From 89bf795f105ebe2703ee74a021e16786990ca7b2 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 10 Dec 2024 03:49:38 -0800 Subject: Fix a crash when search for files. (#5818) Co-authored-by: Ellie Hermaszewska --- tools/slang-test/slang-test-main.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tools') diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index ae6eb6216..376d0e0bd 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -524,6 +524,17 @@ static SlangResult _extractCommand(const char** ioCursor, UnownedStringSlice& ou } } +static void applyMacroSubstitution(String filePath, TestDetails& details) +{ + for (auto& arg : details.options.args) + { + arg = StringUtil::replaceAll( + arg.getUnownedSlice(), + toSlice("$dirname"), + Path::getParentDirectory(filePath).getUnownedSlice()); + } +} + // Try to read command-line options from the test file itself static SlangResult _gatherTestsForFile( TestCategorySet* categorySet, @@ -597,6 +608,7 @@ static SlangResult _gatherTestsForFile( if (command == "TEST") { SLANG_RETURN_ON_FAIL(_gatherTestOptions(categorySet, &cursor, testDetails.options)); + applyMacroSubstitution(filePath, testDetails); // See if the type of test needs certain APIs available const RenderApiFlags testRequiredApis = @@ -611,6 +623,7 @@ static SlangResult _gatherTestsForFile( else if (command == "DIAGNOSTIC_TEST") { SLANG_RETURN_ON_FAIL(_gatherTestOptions(categorySet, &cursor, testDetails.options)); + applyMacroSubstitution(filePath, testDetails); // Apply the file wide options _combineOptions(categorySet, fileOptions, testDetails.options); -- cgit v1.2.3