diff options
| -rw-r--r-- | tests/reflection/global-type-params.slang.expected | 4 | ||||
| -rw-r--r-- | tools/slang-reflection-test/slang-reflection-test-main.cpp | 2 | ||||
| -rw-r--r-- | tools/slang-test/parse-diagnostic-util.cpp | 18 | ||||
| -rw-r--r-- | tools/slang-test/slang-test-main.cpp | 53 |
4 files changed, 72 insertions, 5 deletions
diff --git a/tests/reflection/global-type-params.slang.expected b/tests/reflection/global-type-params.slang.expected index 4fb7d0279..a168ce03f 100644 --- a/tests/reflection/global-type-params.slang.expected +++ b/tests/reflection/global-type-params.slang.expected @@ -200,7 +200,7 @@ standard output = { [ { "name": "TParam", - constraints: + "constraints": [ { "kind": "Interface", @@ -210,7 +210,7 @@ standard output = { }, { "name": "TParam2", - constraints: + "constraints": [ { "kind": "Interface", diff --git a/tools/slang-reflection-test/slang-reflection-test-main.cpp b/tools/slang-reflection-test/slang-reflection-test-main.cpp index 9dd69a6d1..94062cf2b 100644 --- a/tools/slang-reflection-test/slang-reflection-test-main.cpp +++ b/tools/slang-reflection-test/slang-reflection-test-main.cpp @@ -1123,7 +1123,7 @@ static void emitReflectionTypeParamJSON( writer.indent(); emitReflectionNameInfoJSON(writer, typeParam->getName()); writer << ",\n"; - writer << "constraints: \n"; + writer << "\"constraints\": \n"; writer << "[\n"; writer.indent(); auto constraintCount = typeParam->getConstraintCount(); diff --git a/tools/slang-test/parse-diagnostic-util.cpp b/tools/slang-test/parse-diagnostic-util.cpp index 49cc2555b..1141f81c4 100644 --- a/tools/slang-test/parse-diagnostic-util.cpp +++ b/tools/slang-test/parse-diagnostic-util.cpp @@ -341,6 +341,20 @@ static UnownedStringSlice _getEquals(const UnownedStringSlice& in) return in.tail(equalsIndex + 1).trim(); } +static bool _isAtEnd(const UnownedStringSlice& text, const UnownedStringSlice& line) +{ + if (line != "}") + { + return false; + } + // We need to get the *next* line. If it is "}" then this isn't the final closing + UnownedStringSlice remaining(text); + UnownedStringSlice nextLine; + StringUtil::extractLine(remaining, nextLine); + + return (nextLine != toSlice("}")); +} + /* static */SlangResult ParseDiagnosticUtil::parseOutputInfo(const UnownedStringSlice& inText, OutputInfo& out) { enum State @@ -405,9 +419,9 @@ static UnownedStringSlice _getEquals(const UnownedStringSlice& in) case State::InStdError: case State::InStdOut: { - if (line == "}") + if (_isAtEnd(text, line)) { - String& dst = state == State::InStdError ? out.stdError : out.stdOut; + String& dst = (state == State::InStdError) ? out.stdError : out.stdOut; if (lines.getCount() > 0) { dst = UnownedStringSlice(lines[0].begin(), lines.getLast().end()); diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index 8595cac12..99593bb90 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -2161,6 +2161,25 @@ TestResult runSimpleCompareCommandLineTest(TestContext* context, TestInput& inpu return runSimpleTest(context, workInput); } +static SlangResult _parseJSON(const UnownedStringSlice& slice, DiagnosticSink* sink, JSONContainer* container, JSONValue& outValue) +{ + SourceManager* sourceManager = sink->getSourceManager(); + + SourceFile* sourceFile = sourceManager->createSourceFileWithString(PathInfo::makeUnknown(), slice); + SourceView* sourceView = sourceManager->createSourceView(sourceFile, nullptr, SourceLoc()); + + JSONLexer lexer; + lexer.init(sourceView, sink); + + JSONBuilder builder(container); + + JSONParser parser; + SLANG_RETURN_ON_FAIL(parser.parse(&lexer, sourceView, &builder, sink)); + + outValue = builder.getRootValue(); + return SLANG_OK; +} + TestResult runReflectionTest(TestContext* context, TestInput& input) { const auto& options = context->options; @@ -2198,6 +2217,40 @@ TestResult runReflectionTest(TestContext* context, TestInput& input) #endif } + // Extrac the stand + ParseDiagnosticUtil::OutputInfo outputInfo; + if (SLANG_SUCCEEDED(ParseDiagnosticUtil::parseOutputInfo(actualOutput.getUnownedSlice(), outputInfo))) + { + const auto toolReturnCode = ToolReturnCode(outputInfo.resultCode); + + // The output should be JSON. + // Parse it to check that it is valid json + if (toolReturnCode == ToolReturnCode::Success) + { + SourceManager sourceManager; + sourceManager.initialize(nullptr, nullptr); + + JSONContainer container(&sourceManager); + + DiagnosticSink sink; + sink.init(&sourceManager, nullptr); + + JSONValue value; + if (SLANG_FAILED(_parseJSON(outputInfo.stdOut.getUnownedSlice(), &sink, &container, value))) + { + // Unable to parse as JSON + + context->getTestReporter()->messageFormat(TestMessageType::RunError, + "Unable to parse reflection JSON '%s'\n", + input.outputStem.getBuffer()); + + String actualOutputPath = input.outputStem + ".actual"; + Slang::File::writeAllText(actualOutputPath, actualOutput); + return TestResult::Fail; + } + } + } + return _validateOutput(context, input, actualOutput); } |
