summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbspeice <bspeice@users.noreply.github.com>2025-01-01 18:26:43 -0800
committerGitHub <noreply@github.com>2025-01-01 18:26:43 -0800
commite3b71cf0356692bda5f0b3a06aed9d49ad3314a4 (patch)
tree6bb5dd847275f5f940d974727ef738cd296bf6c3
parenta13ef050996c2792ff3c16b6424d3a6336e56a58 (diff)
Allow explicit test root (#5980)
-rw-r--r--source/core/slang-io.cpp4
-rw-r--r--tools/slang-test/options.cpp15
-rw-r--r--tools/slang-test/options.h3
-rw-r--r--tools/slang-test/slang-test-main.cpp8
4 files changed, 23 insertions, 7 deletions
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp
index 7bfde7bd7..3c0c9a11e 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 10f98f3a2..9dd831afa 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 f84240c71..912e28465 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<Slang::String> testPrefixes;
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp
index 376d0e0bd..0987cbf80 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<String> 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