-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
define
ctest
to specify tests must run at compile-time (#28)
Change-Id: I02db2963c778bec9423f2653ba066960e70ad7d5
- Loading branch information
Showing
11 changed files
with
208 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include "src/detail/remove_cvref.hpp" | ||
|
||
#include <type_traits> | ||
|
||
namespace skytest::detail { | ||
|
||
template <const auto& f, class F = remove_cvref_t<decltype(f)>> | ||
struct static_closure : F | ||
{ | ||
constexpr static_closure() : F{f} {} | ||
}; | ||
|
||
template <class T> | ||
struct is_static_closure : std::false_type | ||
{}; | ||
template <const auto& f, class F> | ||
struct is_static_closure<static_closure<f, F>> : std::true_type | ||
{}; | ||
|
||
template <class T> | ||
constexpr auto is_static_closure_v = is_static_closure<T>::value; | ||
|
||
template <class T> | ||
constexpr auto is_static_closure_constructible_v = | ||
std::is_empty_v<T> and std::is_copy_constructible_v<T>; | ||
|
||
} // namespace skytest::detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
|
||
#include "src/detail/priority.hpp" | ||
#include "src/detail/static_closure.hpp" | ||
|
||
#include <optional> | ||
#include <type_traits> | ||
|
||
namespace skytest::detail { | ||
|
||
struct test_style | ||
{ | ||
struct runtime_only | ||
{ | ||
template <class> | ||
static constexpr auto value = std::optional<bool>{}; | ||
}; | ||
|
||
struct compile_time_if_possible | ||
{ | ||
private: | ||
template < | ||
class F, | ||
std::enable_if_t<is_static_closure_v<F>, bool> result = bool{F{}()}> | ||
static constexpr auto try_eval(priority<1>) | ||
{ | ||
return std::optional<bool>{result}; | ||
} | ||
template <class F> | ||
static constexpr auto try_eval(priority<0>) | ||
{ | ||
return std::optional<bool>{}; | ||
} | ||
|
||
public: | ||
template <class F> | ||
static constexpr auto value = try_eval<F>(priority<1>{}); | ||
}; | ||
|
||
struct compile_time | ||
{ | ||
template <class F> | ||
static constexpr auto value = std::optional<bool>{bool{F{}()}}; | ||
}; | ||
}; | ||
|
||
} // namespace skytest::detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
source test/prelude.sh | ||
prelude "${BASH_SOURCE[0]}" | ||
|
||
cat >>BUILD.bazel <<EOF | ||
cc_binary( | ||
name = "ctest_build_failure", | ||
srcs = ["ctest_build_failure.cpp"], | ||
copts = [ | ||
"-std=c++$CC_BINARY_CXXSTD", | ||
"-Werror", | ||
"-Wall", | ||
"-Wextra", | ||
], | ||
malloc = "$CC_BINARY_MALLOC", | ||
deps = [":external_skytest"], | ||
) | ||
EOF | ||
|
||
cat >ctest_build_failure.cpp <<EOF | ||
#include "skytest/skytest.hpp" | ||
auto x = false; | ||
auto main() -> int | ||
{ | ||
using namespace ::skytest::literals; | ||
using ::skytest::expect; | ||
using ::skytest::types; | ||
"test1"_ctest = [] { | ||
return expect(x); | ||
}; | ||
"test2"_ctest * types<int> = [](auto) { | ||
return expect(x); | ||
}; | ||
} | ||
EOF | ||
|
||
bazel build -s //:ctest_build_failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "skytest/skytest.hpp" | ||
|
||
auto main() -> int | ||
{ | ||
using namespace ::skytest::literals; | ||
using ::skytest::eq; | ||
using ::skytest::expect; | ||
using ::skytest::types; | ||
|
||
"test1"_ctest = [] { return expect(eq(1, 1)); }; | ||
|
||
"test2"_ctest * types<int> = [](auto param) { | ||
using T = typename decltype(param)::type; | ||
return expect(eq(0, T{})); | ||
}; | ||
} |