From 17d2b2492d42e54ea4e0d907b4d84aa17f4a6f33 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 2 Feb 2021 17:45:56 -0500 Subject: 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 --- tools/slang-test/slang-test-main.cpp | 83 ++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) (limited to 'tools/slang-test/slang-test-main.cpp') 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 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 }, -- cgit v1.2.3