diff options
| -rw-r--r-- | tools/gfx-unit-test/gfx-test-util.h | 4 | ||||
| -rw-r--r-- | tools/slang-test/test-reporter.h | 14 | ||||
| -rw-r--r-- | tools/unit-test/slang-unit-test.cpp | 10 | ||||
| -rw-r--r-- | tools/unit-test/slang-unit-test.h | 40 |
4 files changed, 37 insertions, 31 deletions
diff --git a/tools/gfx-unit-test/gfx-test-util.h b/tools/gfx-unit-test/gfx-test-util.h index 7709512d5..b7e402abc 100644 --- a/tools/gfx-unit-test/gfx-test-util.h +++ b/tools/gfx-unit-test/gfx-test-util.h @@ -35,7 +35,7 @@ namespace gfx_test return compareComputeResult(device, buffer, expectedBuffer.getBuffer(), bufferSize); } -#define GFX_CHECK_CALL(x) {auto callResult = (x); SLANG_CHECK(!SLANG_FAILED(callResult))} -#define GFX_CHECK_CALL_ABORT(x) {auto callResult = (x); SLANG_CHECK_ABORT(!SLANG_FAILED(callResult))} +#define GFX_CHECK_CALL(x) SLANG_CHECK(!SLANG_FAILED(x)) +#define GFX_CHECK_CALL_ABORT(x) SLANG_CHECK_ABORT(!SLANG_FAILED(x)) } diff --git a/tools/slang-test/test-reporter.h b/tools/slang-test/test-reporter.h index ecf6fbab4..94e5de6ed 100644 --- a/tools/slang-test/test-reporter.h +++ b/tools/slang-test/test-reporter.h @@ -68,12 +68,12 @@ class TestReporter : public ITestReporter void startSuite(const Slang::String& name); void endSuite(); - virtual void startTest(const char* testName) override; - virtual void addResult(TestResult result) override; - virtual void addResultWithLocation(TestResult result, const char* testText, const char* file, int line) override; - virtual void addResultWithLocation(bool testSucceeded, const char* testText, const char* file, int line) override; - virtual void addExecutionTime(double time) override; - virtual void endTest() override; + virtual SLANG_NO_THROW void SLANG_MCALL startTest(const char* testName) override; + virtual SLANG_NO_THROW void SLANG_MCALL addResult(TestResult result) override; + virtual SLANG_NO_THROW void SLANG_MCALL addResultWithLocation(TestResult result, const char* testText, const char* file, int line) override; + virtual SLANG_NO_THROW void SLANG_MCALL addResultWithLocation(bool testSucceeded, const char* testText, const char* file, int line) override; + virtual SLANG_NO_THROW void SLANG_MCALL addExecutionTime(double time) override; + virtual SLANG_NO_THROW void SLANG_MCALL endTest() override; /// Runs start/endTest and outputs the result TestResult addTest(const Slang::String& testName, bool isPass); @@ -83,7 +83,7 @@ class TestReporter : public ITestReporter // Called for an error in the test-runner (not for an error involving a test itself). void message(TestMessageType type, const Slang::String& errorText); void messageFormat(TestMessageType type, char const* message, ...); - virtual void message(TestMessageType type, char const* message) override; + virtual SLANG_NO_THROW void SLANG_MCALL message(TestMessageType type, char const* message) override; void dumpOutputDifference(const Slang::String& expectedOutput, const Slang::String& actualOutput); diff --git a/tools/unit-test/slang-unit-test.cpp b/tools/unit-test/slang-unit-test.cpp index 28eba3a1f..8b57b375b 100644 --- a/tools/unit-test/slang-unit-test.cpp +++ b/tools/unit-test/slang-unit-test.cpp @@ -14,26 +14,26 @@ public: Slang::List<SlangUnitTest> tests; ITestReporter* testReporter = nullptr; - virtual SlangInt getTestCount() override + virtual SLANG_NO_THROW SlangInt SLANG_MCALL getTestCount() override { return tests.getCount(); } - virtual const char* getTestName(SlangInt index) override + virtual SLANG_NO_THROW const char* SLANG_MCALL getTestName(SlangInt index) override { return tests[index].name; } - virtual UnitTestFunc getTestFunc(SlangInt index) override + virtual SLANG_NO_THROW UnitTestFunc SLANG_MCALL getTestFunc(SlangInt index) override { return tests[index].func; } - virtual void setTestReporter(ITestReporter* reporter) override + virtual SLANG_NO_THROW void SLANG_MCALL setTestReporter(ITestReporter* reporter) override { testReporter = reporter; } - virtual void destroy() override + virtual SLANG_NO_THROW void SLANG_MCALL destroy() override { tests = decltype(tests)(); } diff --git a/tools/unit-test/slang-unit-test.h b/tools/unit-test/slang-unit-test.h index 033fab395..9e437f072 100644 --- a/tools/unit-test/slang-unit-test.h +++ b/tools/unit-test/slang-unit-test.h @@ -22,13 +22,13 @@ enum class TestMessageType class ITestReporter { public: - virtual void startTest(const char* testName) = 0; - virtual void addResult(TestResult result) = 0; - virtual void addResultWithLocation(TestResult result, const char* testText, const char* file, int line) = 0; - virtual void addResultWithLocation(bool testSucceeded, const char* testText, const char* file, int line) = 0; - virtual void addExecutionTime(double time) = 0; - virtual void message(TestMessageType type, const char* message) = 0; - virtual void endTest() = 0; + 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 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; }; ITestReporter* getTestReporter(); @@ -45,11 +45,11 @@ typedef void (*UnitTestFunc)(UnitTestContext*); class IUnitTestModule { public: - virtual SlangInt getTestCount() = 0; - virtual const char* getTestName(SlangInt index) = 0; - virtual UnitTestFunc getTestFunc(SlangInt index) = 0; - virtual void setTestReporter(ITestReporter* reporter) = 0; - virtual void destroy() = 0; + virtual SLANG_NO_THROW SlangInt SLANG_MCALL getTestCount() = 0; + virtual SLANG_NO_THROW const char* SLANG_MCALL getTestName(SlangInt index) = 0; + virtual SLANG_NO_THROW UnitTestFunc SLANG_MCALL getTestFunc(SlangInt index) = 0; + virtual SLANG_NO_THROW void SLANG_MCALL setTestReporter(ITestReporter* reporter) = 0; + virtual SLANG_NO_THROW void SLANG_MCALL destroy() = 0; }; class UnitTestRegisterHelper @@ -58,18 +58,24 @@ public: UnitTestRegisterHelper(const char* name, UnitTestFunc testFunc); }; +class AbortTestException {}; + typedef IUnitTestModule* (*UnitTestGetModuleFunc)(); #define SLANG_UNIT_TEST(name) \ -void name(UnitTestContext* unitTestContext); \ +void _##name##_impl(UnitTestContext* unitTestContext); \ +void name(UnitTestContext* unitTestContext)\ +{\ + try { _##name##_impl(unitTestContext); } catch (AbortTestException){} \ +}\ UnitTestRegisterHelper _##name##RegisterHelper(#name, name); \ -void name(UnitTestContext* unitTestContext) +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) return; \ + getTestReporter()->addResultWithLocation(_slang_check_result, #x, __FILE__, __LINE__); \ + if (!_slang_check_result) throw AbortTestException(); \ } -#define SLANG_IGNORE_TEST getTestReporter()->addResult(TestResult::Ignored); return; +#define SLANG_IGNORE_TEST getTestReporter()->addResult(TestResult::Ignored); throw AbortTestException(); |
