summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-02-04 18:45:50 -0500
committerGitHub <noreply@github.com>2021-02-04 15:45:50 -0800
commitfb053433ef64bbae50a8a10ea4381a5695019fac (patch)
tree87298897bf88ec79b40343a868a283d1885357b9 /tools
parentc40f10b704b8bd5a744cc9b3964344585436b1ac (diff)
Fix line offset problem (#1690)
* #include an absolute path didn't work - because paths were taken to always be relative. * WIP diagnostics for line number output. * Small param naming change * Use x macro for pass through compile human name lookup/getting. * WIP on parsing downstream compiler output. * Split out parsing into ParseDiagnosticUtil. Added test result of single line. * Dump out the std output on fail to parse diagnostics. * Change test type for syntax-error-intrinsic.slang be TEST not TEST_DIAGNOSTIC * Use Index for StringUtil. * WIP: First pass support for parsing Slang diagnostics. * WIP Testing comparing with ParseDiagnosticUtil with previous ad-hoc mechanism. * Use the new parsing mechanism for diagnostic comparisons. * Fix layout on GLSL, doesn't have CR so runs into main. * Split out switch on outputting intrinsic 'specials'. Output code around intrinsic as emit - so that we get the appropriate indenting (and potentially other benefits). * Improvements to diagnostics parsing. Better error handling, and fallback handling. Added ability to parse downstream compilers without a prefix. Added ability to parse Slang with a prefix. * DownstreamDiagnostic::Type -> Severity and related fixes. * Small fixes around moving from DownstreamDiagnostic::Type -> Severity * Fix handling of 'special intrinsic' expansion * Split out the handling of intrinsic expansion into it's own type and files. * Fixes to reading expected output - for SimpleLine test. * Test using += to check #line output. * A test around += and return. * Small comment fixes. Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/slang-test/slang-test-main.cpp72
1 files changed, 57 insertions, 15 deletions
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp
index 861e42971..d57ea50e4 100644
--- a/tools/slang-test/slang-test-main.cpp
+++ b/tools/slang-test/slang-test-main.cpp
@@ -1155,6 +1155,47 @@ TestResult runSimpleTest(TestContext* context, TestInput& input)
return result;
}
+SlangResult _readText(const UnownedStringSlice& path, String& out)
+{
+ try
+ {
+ out = Slang::File::readAllText(path);
+ }
+ catch (const Slang::IOException&)
+ {
+ return SLANG_FAIL;
+ }
+ return SLANG_OK;
+}
+
+static SlangResult _readExpected(const UnownedStringSlice& stem, String& out)
+{
+ StringBuilder buf;
+
+ // See if we have a trailing . index, and try *without* that first
+ const Index dotIndex = stem.lastIndexOf('.');
+ if (dotIndex >= 0)
+ {
+ const UnownedStringSlice postfix = stem.tail(dotIndex + 1);
+
+ Int value;
+ if (SLANG_SUCCEEDED(StringUtil::parseInt(postfix, value)))
+ {
+ UnownedStringSlice head = stem.head(dotIndex);
+
+ buf << head << ".expected";
+
+ if (SLANG_SUCCEEDED(_readText(buf.getUnownedSlice(), out)))
+ {
+ return SLANG_OK;
+ }
+ }
+ }
+
+ buf << stem << ".expected";
+ return _readText(buf.getUnownedSlice(), out);
+}
+
TestResult runSimpleLineTest(TestContext* context, TestInput& input)
{
// need to execute the stand-alone Slang compiler on the file, and compare its output to what we expect
@@ -1201,24 +1242,26 @@ TestResult runSimpleLineTest(TestContext* context, TestInput& input)
actualOutput << "No output diagnostics\n";
}
+ TestResult result = TestResult::Fail;
- String expectedOutputPath = outputStem + ".expected";
String expectedOutput;
- try
- {
- expectedOutput = Slang::File::readAllText(expectedOutputPath);
- }
- catch (const Slang::IOException&)
+
+ if (SLANG_SUCCEEDED(_readExpected(outputStem.getUnownedSlice(), expectedOutput)))
{
+ if (StringUtil::areLinesEqual(expectedOutput.getUnownedSlice(), actualOutput.getUnownedSlice()))
+ {
+ result = TestResult::Pass;
+ }
+ else
+ {
+ context->reporter->dumpOutputDifference(expectedOutput, actualOutput);
+ }
}
-
- TestResult result = TestResult::Pass;
-
- // Otherwise we compare to the expected output
- if (!_areResultsEqual(input.testOptions->type, expectedOutput, actualOutput))
+ else
{
- context->reporter->dumpOutputDifference(expectedOutput, actualOutput);
- result = TestResult::Fail;
+ StringBuilder buf;
+ buf << "Unable to find expected output for '" << outputStem << "'";
+ context->reporter->message(TestMessageType::TestFailure, buf);
}
// If the test failed, then we write the actual output to a file
@@ -1228,8 +1271,6 @@ TestResult runSimpleLineTest(TestContext* context, TestInput& input)
{
String actualOutputPath = outputStem + ".actual";
Slang::File::writeAllText(actualOutputPath, actualOutput);
-
- context->reporter->dumpOutputDifference(expectedOutput, actualOutput);
}
return result;
@@ -3397,3 +3438,4 @@ int main(int argc, char** argv)
#endif
return SLANG_SUCCEEDED(res) ? 0 : 1;
}
+