From 97bb82ebcdf8f1391b9d93b5a8d7b1dfc4e88e52 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 4 Oct 2021 14:15:51 -0400 Subject: Removing exceptions from core/compiler-core (#1953) * #include an absolute path didn't work - because paths were taken to always be relative. * Refactor Stream. Working on all tests. * Split out CharEncode. * Make method names lower camel. m_prefix in Writer/Reader * Tidy up around CharEncode interface. * Small improvements around encode/decode. * Better use of types. * Remove readLine from TextReader. * Remove exceptions from Stream/Text handling. * Fix some typos. * Fix tabbing. * Fix missing override. * Remove remaining exception throw/catch via using signal mechanism. * Remove exceptions that are not used anymore. * Document the Stream interface. * Remove index for decoding 'get byte' function. * Fix CharReader -> ByteReader. --- tools/slang-test/slang-test-main.cpp | 118 ++++++++++------------------------- 1 file changed, 33 insertions(+), 85 deletions(-) (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 4f96c3a6a..6fb270c35 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -436,14 +436,8 @@ static SlangResult _gatherTestsForFile( outTestList->tests.clear(); String fileContents; - try - { - fileContents = Slang::File::readAllText(filePath); - } - catch (const Slang::IOException&) - { - return SLANG_FAIL; - } + + SLANG_RETURN_ON_FAIL(Slang::File::readAllText(filePath, fileContents)); // Walk through the lines of the file, looking for test commands char const* cursor = fileContents.begin(); @@ -1168,13 +1162,9 @@ TestResult runDocTest(TestContext* context, TestInput& input) String expectedOutputPath = outputStem + ".expected"; String expectedOutput; - try - { - expectedOutput = Slang::File::readAllText(expectedOutputPath); - } - catch (const Slang::IOException&) - { - } + + // TODO(JS): Might want to check the result code.. + Slang::File::readAllText(expectedOutputPath, expectedOutput); // If no expected output file was found, then we // expect everything to be empty @@ -1258,14 +1248,9 @@ TestResult runSimpleTest(TestContext* context, TestInput& input) String expectedOutputPath = outputStem + ".expected"; String expectedOutput; - try - { - expectedOutput = Slang::File::readAllText(expectedOutputPath); - } - catch (const Slang::IOException&) - { - } - + + Slang::File::readAllText(expectedOutputPath, expectedOutput); + // If no expected output file was found, then we // expect everything to be empty if (expectedOutput.getLength() == 0) @@ -1298,15 +1283,7 @@ TestResult runSimpleTest(TestContext* context, TestInput& input) SlangResult _readText(const UnownedStringSlice& path, String& out) { - try - { - out = Slang::File::readAllText(path); - } - catch (const Slang::IOException&) - { - return SLANG_FAIL; - } - return SLANG_OK; + return Slang::File::readAllText(path, out); } static SlangResult _readExpected(const UnownedStringSlice& stem, String& out) @@ -1540,13 +1517,8 @@ TestResult runReflectionTest(TestContext* context, TestInput& input) String expectedOutputPath = outputStem + ".expected"; String expectedOutput; - try - { - expectedOutput = Slang::File::readAllText(expectedOutputPath); - } - catch (const Slang::IOException&) - { - } + + Slang::File::readAllText(expectedOutputPath, expectedOutput); // If no expected output file was found, then we // expect everything to be empty @@ -1581,14 +1553,9 @@ String getExpectedOutput(String const& outputStem) { String expectedOutputPath = outputStem + ".expected"; String expectedOutput; - try - { - expectedOutput = Slang::File::readAllText(expectedOutputPath); - } - catch (const Slang::IOException&) - { - } - + + Slang::File::readAllText(expectedOutputPath, expectedOutput); + // If no expected output file was found, then we // expect everything to be empty if (expectedOutput.getLength() == 0) @@ -1727,15 +1694,10 @@ static TestResult runCPPCompilerSharedLibrary(TestContext* context, TestInput& i { // Read the expected String expectedOutput; - try - { - String expectedOutputPath = outputStem + ".expected"; - expectedOutput = Slang::File::readAllText(expectedOutputPath); - } - catch (const Slang::IOException&) - { - } - + + String expectedOutputPath = outputStem + ".expected"; + Slang::File::readAllText(expectedOutputPath, expectedOutput); + // Compare if they are the same if (!StringUtil::areLinesEqual(actualOutput.getUnownedSlice(), expectedOutput.getUnownedSlice())) { @@ -1867,15 +1829,10 @@ static TestResult runCPPCompilerExecute(TestContext* context, TestInput& input) { // Read the expected String expectedOutput; - try - { - String expectedOutputPath = outputStem + ".expected"; - expectedOutput = Slang::File::readAllText(expectedOutputPath); - } - catch (const Slang::IOException&) - { - } - + + String expectedOutputPath = outputStem + ".expected"; + Slang::File::readAllText(expectedOutputPath, expectedOutput); + // Compare if they are the same if (!StringUtil::areLinesEqual(actualOutput.getUnownedSlice(), expectedOutput.getUnownedSlice())) { @@ -1960,11 +1917,8 @@ TestResult runCrossCompilerTest(TestContext* context, TestInput& input) { expectedOutput = getOutput(expectedExeRes); String expectedOutputPath = outputStem + ".expected"; - try - { - Slang::File::writeAllText(expectedOutputPath, expectedOutput); - } - catch (const Slang::IOException&) + + if (SLANG_FAILED(Slang::File::writeAllText(expectedOutputPath, expectedOutput))) { return TestResult::Fail; } @@ -2045,14 +1999,12 @@ TestResult generateHLSLBaseline( String expectedOutput = getOutput(exeRes); String expectedOutputPath = outputStem + ".expected"; - try - { - Slang::File::writeAllText(expectedOutputPath, expectedOutput); - } - catch (const Slang::IOException&) + + if (SLANG_FAILED(Slang::File::writeAllText(expectedOutputPath, expectedOutput))) { return TestResult::Fail; } + return TestResult::Pass; } @@ -2126,14 +2078,8 @@ static TestResult _runHLSLComparisonTest( String actualOutput = actualOutputBuilder.ProduceString(); String expectedOutput; - try - { - expectedOutput = Slang::File::readAllText(expectedOutputPath); - } - catch (const Slang::IOException&) - { - } - + Slang::File::readAllText(expectedOutputPath, expectedOutput); + TestResult result = TestResult::Pass; // If no expected output file was found, then we @@ -2543,8 +2489,10 @@ TestResult runComputeComparisonImpl(TestContext* context, TestInput& input, cons printf("referenceOutput %s not found.\n", referenceOutputFile.getBuffer()); return TestResult::Fail; } - auto actualOutputContent = File::readAllText(actualOutputFile); - auto referenceOutputContent = File::readAllText(referenceOutputFile); + String actualOutputContent, referenceOutputContent; + + File::readAllText(actualOutputFile, actualOutputContent); + File::readAllText(referenceOutputFile, referenceOutputContent); if (SLANG_FAILED(_compareWithType(actualOutputContent.getUnownedSlice(), referenceOutputContent.getUnownedSlice()))) { -- cgit v1.2.3