diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/core/slang-test-tool-util.cpp | 28 | ||||
| -rw-r--r-- | source/core/slang-test-tool-util.h | 30 | ||||
| -rw-r--r-- | source/slangc/main.cpp | 2 |
3 files changed, 52 insertions, 8 deletions
diff --git a/source/core/slang-test-tool-util.cpp b/source/core/slang-test-tool-util.cpp index 7ecfacefa..20ba2fc47 100644 --- a/source/core/slang-test-tool-util.cpp +++ b/source/core/slang-test-tool-util.cpp @@ -4,18 +4,34 @@ namespace Slang { -/* static */int TestToolUtil::getReturnCode(SlangResult res) +/* static */ToolReturnCode TestToolUtil::getReturnCode(SlangResult res) { - if (SLANG_SUCCEEDED(res)) + switch (res) { - return 0; + case SLANG_OK: return ToolReturnCode::Success; + case SLANG_E_INTERNAL_FAIL: return ToolReturnCode::CompilationFailed; + case SLANG_FAIL: return ToolReturnCode::Failed; + case SLANG_E_NOT_AVAILABLE: return ToolReturnCode::Ignored; + default: + { + return (SLANG_SUCCEEDED(res)) ? ToolReturnCode::Success : ToolReturnCode::Failed; + } } - else if (res == SLANG_E_INTERNAL_FAIL) +} + +/* static */ToolReturnCode TestToolUtil::getReturnCodeFromInt(int code) +{ + if (code >= int(ToolReturnCodeSpan::First) && code <= int(ToolReturnCodeSpan::Last)) { - return -1; + return ToolReturnCode(code); + } + else + { + SLANG_ASSERT(!"Invalid integral code"); + return ToolReturnCode::Failed; } - return 1; } + } diff --git a/source/core/slang-test-tool-util.h b/source/core/slang-test-tool-util.h index 615bbe10d..3ec655cad 100644 --- a/source/core/slang-test-tool-util.h +++ b/source/core/slang-test-tool-util.h @@ -11,13 +11,41 @@ namespace Slang { # define SLANG_TEST_TOOL_API #endif +/* When a tool is run as an executable the return code is the code returned from +the last return of main. On unix this can be up to 8 bits. +By normal command line tool conventions returning 0 means success. */ +enum class ToolReturnCode +{ + CompilationFailed = -1, ///< Compilation failure (-1 to maintain compatibility). This may still produce output and may mean a test was successful. + Success = 0, ///< Tool ran normally + Failed, ///< Tool failed + Ignored, ///< The run was ignored because it couldn't be run (because some optional feature was not present for example) + FailedToRun, ///< Could not even run the test +}; + +enum class ToolReturnCodeSpan +{ + // Span of all valid values + First = int(ToolReturnCode::CompilationFailed), + Last = int(ToolReturnCode::FailedToRun), + // Span of all values that indicate the test is 'done' + FirstIsDone = int(ToolReturnCode::Ignored), + LastIsDone = int(ToolReturnCode::FailedToRun) +}; + /* Utility functions for 'test tools' */ struct TestToolUtil { typedef SlangResult(*InnerMainFunc)(Slang::StdWriters* stdWriters, SlangSession* session, int argc, const char*const* argv); + /// If the test failed to run or was ignored then we are done + static bool isDone(ToolReturnCode code) { return int(code) >= int(ToolReturnCodeSpan::FirstIsDone) && int(code) <= int(ToolReturnCodeSpan::LastIsDone); } + + /// Convert from an int + static ToolReturnCode getReturnCodeFromInt(int code); + /// Given a slang result, returns a return code that can be returned from an executable - static int getReturnCode(SlangResult res); + static ToolReturnCode getReturnCode(SlangResult res); }; } // namespace Slang diff --git a/source/slangc/main.cpp b/source/slangc/main.cpp index bcc40b5ca..80b9cddbd 100644 --- a/source/slangc/main.cpp +++ b/source/slangc/main.cpp @@ -87,7 +87,7 @@ int MAIN(int argc, char** argv) res = innerMain(stdWriters, session, argc, argv); spDestroySession(session); } - return TestToolUtil::getReturnCode(res); + return (int)TestToolUtil::getReturnCode(res); } #ifdef _WIN32 |
