Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow explicit test root #5980

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/core/slang-io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
15 changes: 15 additions & 0 deletions tools/slang-test/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions tools/slang-test/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 3 additions & 5 deletions tools/slang-test/slang-test-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
Loading