Skip to content

Commit 3355d77

Browse files
author
thk123
committed
Add basic unit test
Full tests are provided in the submodule - this checks that it compiles and links correctly.
1 parent c2afb08 commit 3355d77

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
113113
endif()
114114
endif()
115115

116+
add_subdirectory(lib/variant)
117+
116118
add_subdirectory(src)
117119
add_subdirectory(regression)
118120
add_subdirectory(unit)

src/util/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ add_dependencies(util generate_version_cpp)
4747

4848
generic_includes(util)
4949

50-
target_link_libraries(util big-int langapi)
50+
target_link_libraries(util big-int langapi mpark_variant)

src/util/module_dependencies.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
big-int
22
mach # system
33
malloc # system
4+
mpark
45
nonstd
56
sys # system
67
util
8+

src/util/variant.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*******************************************************************\
2+
3+
Module: typedef for optional class template. To be replaced with
4+
std::optional once C++17 support is enabled
5+
6+
Author: Diffblue Ltd.
7+
8+
\*******************************************************************/
9+
10+
#ifndef CPROVER_UTIL_VARIANT_H
11+
#define CPROVER_UTIL_VARIANT_H
12+
13+
#include <mpark/variant.hpp>
14+
15+
template <typename ... Ts>
16+
using variantt = mpark::variant<Ts...>;
17+
18+
#endif // CPROVER_UTIL_VARIANT_H

unit/util/variant.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2016-2019 Diffblue Limited. All Rights Reserved.
2+
3+
#include <testing-utils/use_catch.h>
4+
#include <util/variant.h>
5+
6+
TEST_CASE("Ensure variant has been included", "[core][util][variant]")
7+
{
8+
variantt<int, float> some_type = 1;
9+
REQUIRE(some_type.index() == 0);
10+
some_type = 1.0f;
11+
REQUIRE(some_type.index() == 1);
12+
}

0 commit comments

Comments
 (0)