From e3b71cf0356692bda5f0b3a06aed9d49ad3314a4 Mon Sep 17 00:00:00 2001 From: bspeice Date: Wed, 1 Jan 2025 18:26:43 -0800 Subject: [PATCH] Allow explicit test root (#5980) --- source/core/slang-io.cpp | 4 ++-- tools/slang-test/options.cpp | 15 +++++++++++++++ tools/slang-test/options.h | 3 +++ tools/slang-test/slang-test-main.cpp | 8 +++----- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index 7bfde7bd7a..3c0c9a11ea 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -992,12 +992,12 @@ static SlangResult _calcExectuablePath(char* outPath, size_t* ioSize) { return SLANG_FAIL; } - if (size_t(resSize) >= bufferSize) + if (size_t(resSize + 1) >= bufferSize) { return SLANG_E_BUFFER_TOO_SMALL; } // Zero terminate - outPath[resSize - 1] = 0; + outPath[resSize] = 0; return SLANG_OK; #else String text = Slang::File::readAllText("/proc/self/maps"); diff --git a/tools/slang-test/options.cpp b/tools/slang-test/options.cpp index 10f98f3a28..9dd831afa0 100644 --- a/tools/slang-test/options.cpp +++ b/tools/slang-test/options.cpp @@ -327,6 +327,15 @@ static bool _isSubCommand(const char* arg) optionsOut->expectedFailureList.add(line); } } + else if (strcmp(arg, "-test-dir") == 0) + { + if (argCursor == argEnd) + { + stdError.print("error: expected operand for '%s'\n", arg); + return SLANG_FAIL; + } + optionsOut->testDir = *argCursor++; + } else { stdError.print("unknown option '%s'\n", arg); @@ -365,5 +374,11 @@ static bool _isSubCommand(const char* arg) } } + if (optionsOut->testDir.getLength() == 0) + { + // If the test directory isn't set, use the "tests" directory + optionsOut->testDir = String("tests/"); + } + return SLANG_OK; } diff --git a/tools/slang-test/options.h b/tools/slang-test/options.h index f84240c712..912e284653 100644 --- a/tools/slang-test/options.h +++ b/tools/slang-test/options.h @@ -51,6 +51,9 @@ struct Options // Directory to use when looking for binaries to run. If empty it's not set. Slang::String binDir; + // Root directory to use when looking for test cases + Slang::String testDir; + // only run test cases with names have one of these prefixes. Slang::List testPrefixes; diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index 376d0e0bd2..0987cbf804 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -4427,10 +4427,10 @@ void runTestsInParallel(TestContext* context, int count, const F& f) context->setTestReporter(originalReporter); } -void runTestsInDirectory(TestContext* context, String directoryPath) +void runTestsInDirectory(TestContext* context) { List files; - getFilesInDirectory(directoryPath, files); + getFilesInDirectory(context->options.testDir, files); auto processFile = [&](String file) { if (shouldRunTest(context, file)) @@ -4865,9 +4865,7 @@ SlangResult innerMain(int argc, char** argv) { TestReporter::SuiteScope suiteScope(&reporter, "tests"); // 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/"); + runTestsInDirectory(&context); } // Run the unit tests (these are internal C++ tests - not specified via files in a