diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2024-10-29 14:49:26 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-29 14:49:26 +0800 |
| commit | f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch) | |
| tree | ea1d61342cd29368e19135000ec2948813096205 /tools/unit-test | |
| parent | a729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff) | |
format
* format
* Minor test fixes
* enable checking cpp format in ci
Diffstat (limited to 'tools/unit-test')
| -rw-r--r-- | tools/unit-test/slang-unit-test.cpp | 22 | ||||
| -rw-r--r-- | tools/unit-test/slang-unit-test.h | 58 |
2 files changed, 44 insertions, 36 deletions
diff --git a/tools/unit-test/slang-unit-test.cpp b/tools/unit-test/slang-unit-test.cpp index 8b57b375b..61f778c9a 100644 --- a/tools/unit-test/slang-unit-test.cpp +++ b/tools/unit-test/slang-unit-test.cpp @@ -1,4 +1,5 @@ #include "slang-unit-test.h" + #include "slang.h" #include "source/core/slang-basic.h" @@ -14,10 +15,7 @@ public: Slang::List<SlangUnitTest> tests; ITestReporter* testReporter = nullptr; - virtual SLANG_NO_THROW SlangInt SLANG_MCALL getTestCount() override - { - return tests.getCount(); - } + virtual SLANG_NO_THROW SlangInt SLANG_MCALL getTestCount() override { return tests.getCount(); } virtual SLANG_NO_THROW const char* SLANG_MCALL getTestName(SlangInt index) override { return tests[index].name; @@ -33,11 +31,7 @@ public: testReporter = reporter; } - virtual SLANG_NO_THROW void SLANG_MCALL destroy() override - { - tests = decltype(tests)(); - } - + virtual SLANG_NO_THROW void SLANG_MCALL destroy() override { tests = decltype(tests)(); } }; SlangUnitTestModule* _getTestModule() @@ -53,13 +47,13 @@ ITestReporter* getTestReporter() extern "C" { -SLANG_DLL_EXPORT IUnitTestModule* slangUnitTestGetModule() -{ - return _getTestModule(); -} + SLANG_DLL_EXPORT IUnitTestModule* slangUnitTestGetModule() + { + return _getTestModule(); + } } UnitTestRegisterHelper::UnitTestRegisterHelper(const char* name, UnitTestFunc testFunc) { - _getTestModule()->tests.add(SlangUnitTest{ name, testFunc }); + _getTestModule()->tests.add(SlangUnitTest{name, testFunc}); } diff --git a/tools/unit-test/slang-unit-test.h b/tools/unit-test/slang-unit-test.h index 8f96f6805..c63fb8a10 100644 --- a/tools/unit-test/slang-unit-test.h +++ b/tools/unit-test/slang-unit-test.h @@ -5,8 +5,9 @@ enum class TestResult { - // NOTE! Must keep in order such that combine is meaningful. That is larger values are higher precident - and a series of tests that has lots of passes - // and a fail, is still a fail overall. + // NOTE! Must keep in order such that combine is meaningful. That is larger values are higher + // precident - and a series of tests that has lots of passes and a fail, is still a fail + // overall. Ignored, Pass, ExpectedFail, @@ -15,9 +16,9 @@ enum class TestResult enum class TestMessageType { - Info, ///< General info (may not be shown depending on verbosity setting) - TestFailure, ///< Describes how a test failure took place - RunError, ///< Describes an error that caused a test not to actually correctly run + Info, ///< General info (may not be shown depending on verbosity setting) + TestFailure, ///< Describes how a test failure took place + RunError, ///< Describes an error that caused a test not to actually correctly run }; class ITestReporter @@ -25,8 +26,10 @@ class ITestReporter public: virtual SLANG_NO_THROW void SLANG_MCALL startTest(const char* testName) = 0; virtual SLANG_NO_THROW void SLANG_MCALL addResult(TestResult result) = 0; - virtual SLANG_NO_THROW void SLANG_MCALL addResultWithLocation(TestResult result, const char* testText, const char* file, int line) = 0; - virtual SLANG_NO_THROW void SLANG_MCALL addResultWithLocation(bool testSucceeded, const char* testText, const char* file, int line) = 0; + virtual SLANG_NO_THROW void SLANG_MCALL + addResultWithLocation(TestResult result, const char* testText, const char* file, int line) = 0; + virtual SLANG_NO_THROW void SLANG_MCALL + addResultWithLocation(bool testSucceeded, const char* testText, const char* file, int line) = 0; virtual SLANG_NO_THROW void SLANG_MCALL addExecutionTime(double time) = 0; virtual SLANG_NO_THROW void SLANG_MCALL message(TestMessageType type, const char* message) = 0; virtual SLANG_NO_THROW void SLANG_MCALL endTest() = 0; @@ -60,24 +63,35 @@ public: UnitTestRegisterHelper(const char* name, UnitTestFunc testFunc); }; -class AbortTestException {}; +class AbortTestException +{ +}; typedef IUnitTestModule* (*UnitTestGetModuleFunc)(); -#define SLANG_UNIT_TEST(name) \ -void _##name##_impl(UnitTestContext* unitTestContext); \ -void name(UnitTestContext* unitTestContext)\ -{\ - try { _##name##_impl(unitTestContext); } catch (AbortTestException&){} \ -}\ -UnitTestRegisterHelper _##name##RegisterHelper(#name, name); \ -void _##name##_impl(UnitTestContext* unitTestContext) +#define SLANG_UNIT_TEST(name) \ + void _##name##_impl(UnitTestContext* unitTestContext); \ + void name(UnitTestContext* unitTestContext) \ + { \ + try \ + { \ + _##name##_impl(unitTestContext); \ + } \ + catch (AbortTestException&) \ + { \ + } \ + } \ + UnitTestRegisterHelper _##name##RegisterHelper(#name, name); \ + void _##name##_impl(UnitTestContext* unitTestContext) #define SLANG_CHECK(x) getTestReporter()->addResultWithLocation((x), #x, __FILE__, __LINE__); -#define SLANG_CHECK_ABORT(x) \ - { \ - bool _slang_check_result = (x); \ - getTestReporter()->addResultWithLocation(_slang_check_result, #x, __FILE__, __LINE__); \ - if (!_slang_check_result) throw AbortTestException(); \ +#define SLANG_CHECK_ABORT(x) \ + { \ + bool _slang_check_result = (x); \ + getTestReporter()->addResultWithLocation(_slang_check_result, #x, __FILE__, __LINE__); \ + if (!_slang_check_result) \ + throw AbortTestException(); \ } -#define SLANG_IGNORE_TEST getTestReporter()->addResult(TestResult::Ignored); throw AbortTestException(); +#define SLANG_IGNORE_TEST \ + getTestReporter()->addResult(TestResult::Ignored); \ + throw AbortTestException(); |
