From 8a150a948c5de57dffa6f8e0a4c1c96acc69ac0a Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 17 Sep 2018 10:28:11 -0400 Subject: Control unit tests being run with -category -exclude and using prefix. (#637) Unit tests appear in unit-test category Unit tests 'appear' in a directory unit-tests Removed the -unitTests option --- test.bat | 1 - tools/slang-test/main.cpp | 52 ++++++++++++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/test.bat b/test.bat index f21dcbbfb..6c6e88580 100644 --- a/test.bat +++ b/test.bat @@ -56,4 +56,3 @@ SET "PATH=%PATH%;%SLANG_TEST_BIN_DIR%" :: TODO: Maybe we should actually invoke `msbuild` to make sure all the code is up to date? "%SLANG_TEST_BIN_DIR%slang-test.exe" -bindir "%SLANG_TEST_BIN_DIR%\" %* -"%SLANG_TEST_BIN_DIR%slang-test.exe" -bindir "%SLANG_TEST_BIN_DIR%\" -unitTests diff --git a/tools/slang-test/main.cpp b/tools/slang-test/main.cpp index a4b903e25..654b18f85 100644 --- a/tools/slang-test/main.cpp +++ b/tools/slang-test/main.cpp @@ -113,9 +113,6 @@ struct Options // By default we potentially synthesize test for all // TODO: Vulkan is disabled by default for now as the majority as vulkan synthesized tests fail RenderApiFlags synthesizedTestApis = RenderApiFlag::AllOf & ~RenderApiFlag::Vulkan; - - // Set this to turn on unit tests - bool unitTests = false; }; // Globals @@ -286,10 +283,6 @@ Result parseOptions(int* argc, char** argv) return res; } } - else if (strcmp(arg, "-unitTests") == 0) - { - g_options.unitTests = true; - } else { fprintf(stderr, "unknown option '%s'\n", arg); @@ -1845,6 +1838,7 @@ static bool endsWithAllowedExtension( ".tesc", ".tese", ".comp", + ".internal", nullptr }; for( auto ii = allowedExtensions; *ii; ++ii ) @@ -1913,6 +1907,7 @@ int main( auto vulkanTestCategory = addTestCategory("vulkan", fullTestCategory); + auto unitTestCatagory = addTestCategory("unit-test", fullTestCategory); // An un-categorized test will always belong to the `full` category g_defaultTestCategory = fullTestCategory; @@ -1944,8 +1939,14 @@ int main( context.m_dumpOutputOnFailure = g_options.dumpOutputOnFailure; context.m_isVerbose = g_options.shouldBeVerbose; - - if (g_options.unitTests) + + // Enumerate test files according to policy + // TODO: add more directories to this list + // TODO: allow for a command-line argument to select a particular directory + runTestsInDirectory(&context, "tests/"); + + // Run the unit tests (these are internal C++ tests - not specified via files in a directory) + // They are registered with SLANG_UNIT_TEST macro { TestContext::set(&context); @@ -1953,26 +1954,35 @@ int main( TestRegister* cur = TestRegister::s_first; while (cur) { - context.startTest(cur->m_name); - - // Run the test function - cur->m_func(); + StringBuilder filePath; + filePath << "unit-tests/" << cur->m_name << ".internal"; - context.endTest(); + TestOptions testOptions; + testOptions.categories.Add(unitTestCatagory); + testOptions.command = filePath; + if (shouldRunTest(&context, testOptions.command)) + { + if (testPassesCategoryMask(&context, testOptions)) + { + context.startTest(testOptions.command); + // Run the test function + cur->m_func(); + context.endTest(); + } + else + { + context.addTest(testOptions.command, TestResult::Ignored); + } + } + // Next cur = cur->m_next; } TestContext::set(nullptr); } - else - { - // Enumerate test files according to policy - // TODO: add more directories to this list - // TODO: allow for a command-line argument to select a particular directory - runTestsInDirectory(&context, "tests/"); - } + context.outputSummary(); -- cgit v1.2.3