diff --git a/.bazelrc b/.bazelrc index 0bd27b2..5a043b0 100644 --- a/.bazelrc +++ b/.bazelrc @@ -15,5 +15,6 @@ build --cxxopt=-Wno-unused-macros build --cxxopt=-Wno-documentation-unknown-command build --cxxopt=-Wno-extra-semi-stmt build --cxxopt=-Wno-extra-semi +build --cxxopt=-Wno-global-constructors test --test_output=errors diff --git a/asl/BUILD.bazel b/asl/BUILD.bazel index f0d4c27..f7dddd1 100644 --- a/asl/BUILD.bazel +++ b/asl/BUILD.bazel @@ -24,11 +24,12 @@ cc_library( [cc_test( name = "%s_tests" % name, srcs = [ - "%s_tests.cpp" % name, - "test_types.hpp", + "tests/%s_tests.cpp" % name, + "tests/test_types.hpp", ], deps = [ ":asl", + "//asl/testing", ], ) for name in [ "format", diff --git a/asl/testing/BUILD.bazel b/asl/testing/BUILD.bazel new file mode 100644 index 0000000..2942073 --- /dev/null +++ b/asl/testing/BUILD.bazel @@ -0,0 +1,13 @@ +cc_library( + name = "testing", + hdrs = [ + "testing.hpp", + ], + srcs = [ + "testing.cpp", + ], + deps = [ + "//asl", + ], + visibility = ["//visibility:public"], +) diff --git a/asl/testing/testing.cpp b/asl/testing/testing.cpp new file mode 100644 index 0000000..a2fe152 --- /dev/null +++ b/asl/testing/testing.cpp @@ -0,0 +1,14 @@ +#include "asl/testing/testing.hpp" + +int asl::testing::register_test( + const char* suite_name, + const char* case_name, + TestFunction* fn) +{ + return 0; +} + +int main(int argc, char* argv[]) +{ + return 0; +} diff --git a/asl/testing/testing.hpp b/asl/testing/testing.hpp new file mode 100644 index 0000000..a489d61 --- /dev/null +++ b/asl/testing/testing.hpp @@ -0,0 +1,15 @@ +#pragma once + +namespace asl::testing +{ + +using TestFunction = void(); +int register_test(const char* suite_name, const char* case_name, TestFunction* fn); + +} // namespace asl::testing + +#define ASL_TEST(SUITE, CASE) \ + static void asl_test_fn_##SUITE##_##CASE(); \ + static const int asl_test_##SUITE##_##CASE = ::asl::testing::register_test( \ + #SUITE, #CASE, asl_test_fn_##SUITE##_##CASE); \ + void asl_test_fn_##SUITE##_##CASE() diff --git a/asl/format_tests.cpp b/asl/tests/format_tests.cpp similarity index 95% rename from asl/format_tests.cpp rename to asl/tests/format_tests.cpp index 818773b..6e2430d 100644 --- a/asl/format_tests.cpp +++ b/asl/tests/format_tests.cpp @@ -33,7 +33,7 @@ public: } }; -int main() +int main2() { StringSink sink; diff --git a/asl/integers_tests.cpp b/asl/tests/integers_tests.cpp similarity index 89% rename from asl/integers_tests.cpp rename to asl/tests/integers_tests.cpp index 0393a3c..d15168e 100644 --- a/asl/integers_tests.cpp +++ b/asl/tests/integers_tests.cpp @@ -9,5 +9,3 @@ static_assert(sizeof(uint8_t) == 1); static_assert(sizeof(uint16_t) == 2); static_assert(sizeof(uint32_t) == 4); static_assert(sizeof(uint64_t) == 8); - -int main() { return 0; } diff --git a/asl/maybe_uninit_tests.cpp b/asl/tests/maybe_uninit_tests.cpp similarity index 85% rename from asl/maybe_uninit_tests.cpp rename to asl/tests/maybe_uninit_tests.cpp index 7584eea..3f60558 100644 --- a/asl/maybe_uninit_tests.cpp +++ b/asl/tests/maybe_uninit_tests.cpp @@ -1,5 +1,5 @@ #include "asl/maybe_uninit.hpp" -#include "asl/test_types.hpp" +#include "asl/tests/test_types.hpp" static_assert(asl::layout::of() == asl::layout::of>()); static_assert(asl::size_of == asl::size_of>); @@ -8,7 +8,3 @@ static_assert(asl::align_of == asl::align_of>); static_assert(asl::trivially_destructible>); static_assert(!asl::trivially_destructible>); -int main() -{ - return 0; -} diff --git a/asl/meta_tests.cpp b/asl/tests/meta_tests.cpp similarity index 96% rename from asl/meta_tests.cpp rename to asl/tests/meta_tests.cpp index 2bebb01..5de4f8d 100644 --- a/asl/meta_tests.cpp +++ b/asl/tests/meta_tests.cpp @@ -1,5 +1,5 @@ #include "asl/meta.hpp" -#include "asl/test_types.hpp" +#include "asl/tests/test_types.hpp" struct Struct {}; union Union {}; @@ -168,5 +168,3 @@ static_assert(!asl::trivially_copyable); static_assert(!asl::trivially_copyable); static_assert(asl::trivially_copyable); static_assert(asl::trivially_copyable); - -int main() { return 0; } diff --git a/asl/option_tests.cpp b/asl/tests/option_tests.cpp similarity index 90% rename from asl/option_tests.cpp rename to asl/tests/option_tests.cpp index 38bce2e..7de1f9c 100644 --- a/asl/option_tests.cpp +++ b/asl/tests/option_tests.cpp @@ -1,5 +1,6 @@ #include "asl/option.hpp" -#include "asl/test_types.hpp" +#include "asl/tests/test_types.hpp" +#include static_assert(asl::trivially_destructible>); static_assert(!asl::trivially_destructible>); @@ -23,12 +24,10 @@ static_assert(asl::move_assignable>); static_assert(asl::move_assignable>); static_assert(!asl::move_assignable>); -int main() +ASL_TEST(Option, cheese) { asl::option a; asl::option b; a = ASL_MOVE(b); - - return 0; } diff --git a/asl/test_types.hpp b/asl/tests/test_types.hpp similarity index 100% rename from asl/test_types.hpp rename to asl/tests/test_types.hpp diff --git a/asl/tests/utility_tests.cpp b/asl/tests/utility_tests.cpp new file mode 100644 index 0000000..4acded7 --- /dev/null +++ b/asl/tests/utility_tests.cpp @@ -0,0 +1 @@ +#include "asl/utility.hpp" diff --git a/asl/utility_tests.cpp b/asl/utility_tests.cpp deleted file mode 100644 index 5802cec..0000000 --- a/asl/utility_tests.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "asl/utility.hpp" - -int main() { return 0; }