summaryrefslogtreecommitdiff
path: root/tools/slang-test/slang-test-main.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-02-02 17:45:56 -0500
committerGitHub <noreply@github.com>2021-02-02 14:45:56 -0800
commit17d2b2492d42e54ea4e0d907b4d84aa17f4a6f33 (patch)
treebdcc4b0aba860139a011ca052e505b9202c6152c /tools/slang-test/slang-test-main.cpp
parent5d755e584ff6c241f42204430e005b26314ed594 (diff)
Downstream compiler line number test (#1682)
* #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
Diffstat (limited to 'tools/slang-test/slang-test-main.cpp')
-rw-r--r--tools/slang-test/slang-test-main.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp
index 3a15c6e61..fcb609c34 100644
--- a/tools/slang-test/slang-test-main.cpp
+++ b/tools/slang-test/slang-test-main.cpp
@@ -10,6 +10,7 @@
#include "../../source/core/slang-string-util.h"
#include "../../source/core/slang-byte-encode-util.h"
+#include "../../source/core/slang-char-util.h"
using namespace Slang;
@@ -19,6 +20,7 @@ using namespace Slang;
#include "test-reporter.h"
#include "options.h"
#include "slangc-tool.h"
+#include "parse-diagnostic-util.h"
#include "../../source/core/slang-downstream-compiler.h"
@@ -1244,6 +1246,86 @@ TestResult runSimpleTest(TestContext* context, TestInput& input)
return result;
}
+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
+ auto outputStem = input.outputStem;
+
+ CommandLine cmdLine;
+ _initSlangCompiler(context, cmdLine);
+
+ cmdLine.addArg(input.filePath);
+
+ for (auto arg : input.testOptions->args)
+ {
+ cmdLine.addArg(arg);
+ }
+
+ ExecuteResult exeRes;
+ TEST_RETURN_ON_DONE(spawnAndWait(context, outputStem, input.spawnType, cmdLine, exeRes));
+
+ if (context->isCollectingRequirements())
+ {
+ return TestResult::Pass;
+ }
+
+ // Parse all the diagnostics so we can extract line numbers
+ List<DownstreamDiagnostic> diagnostics;
+ if (SLANG_FAILED(ParseDiagnosticUtil::parseDiagnostics(exeRes.standardError.getUnownedSlice(), diagnostics)) || diagnostics.getCount() <= 0)
+ {
+ // Write out the diagnostics which couldn't be parsed.
+
+ String actualOutputPath = outputStem + ".actual";
+ Slang::File::writeAllText(actualOutputPath, exeRes.standardError);
+
+ return TestResult::Fail;
+ }
+
+ StringBuilder actualOutput;
+
+ if (diagnostics.getCount() > 0)
+ {
+ actualOutput << diagnostics[0].fileLine << "\n";
+ }
+ else
+ {
+ actualOutput << "No output diagnostics\n";
+ }
+
+
+ String expectedOutputPath = outputStem + ".expected";
+ String expectedOutput;
+ try
+ {
+ expectedOutput = Slang::File::readAllText(expectedOutputPath);
+ }
+ catch (const Slang::IOException&)
+ {
+ }
+
+ TestResult result = TestResult::Pass;
+
+ // Otherwise we compare to the expected output
+ if (!_areResultsEqual(input.testOptions->type, expectedOutput, actualOutput))
+ {
+ context->reporter->dumpOutputDifference(expectedOutput, actualOutput);
+ result = TestResult::Fail;
+ }
+
+ // If the test failed, then we write the actual output to a file
+ // so that we can easily diff it from the command line and
+ // diagnose the problem.
+ if (result == TestResult::Fail)
+ {
+ String actualOutputPath = outputStem + ".actual";
+ Slang::File::writeAllText(actualOutputPath, actualOutput);
+
+ context->reporter->dumpOutputDifference(expectedOutput, actualOutput);
+ }
+
+ return result;
+}
+
TestResult runCompile(TestContext* context, TestInput& input)
{
auto outputStem = input.outputStem;
@@ -2688,6 +2770,7 @@ static const TestCommandInfo s_testCommandInfos[] =
{
{ "SIMPLE", &runSimpleTest, 0 },
{ "SIMPLE_EX", &runSimpleTest, 0 },
+ { "SIMPLE_LINE", &runSimpleLineTest, 0 },
{ "REFLECTION", &runReflectionTest, 0 },
{ "CPU_REFLECTION", &runReflectionTest, 0 },
{ "COMMAND_LINE_SIMPLE", &runSimpleCompareCommandLineTest, 0 },