summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/slang-test/slang-test-main.cpp118
-rw-r--r--tools/slang-test/unit-test-string.cpp31
2 files changed, 119 insertions, 30 deletions
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp
index 6eae194e6..0543dd067 100644
--- a/tools/slang-test/slang-test-main.cpp
+++ b/tools/slang-test/slang-test-main.cpp
@@ -1086,6 +1086,20 @@ String getExpectedOutput(String const& outputStem)
return expectedOutput;
}
+static String _calcSummary(const CPPCompiler::Output& inOutput)
+{
+ CPPCompiler::Output output(inOutput);
+
+ // We only want to analyse errors for now
+ output.removeByType(CPPCompiler::OutputMessage::Type::Info);
+ output.removeByType(CPPCompiler::OutputMessage::Type::Warning);
+
+ StringBuilder builder;
+
+ output.appendSimplifiedSummary(builder);
+ return builder;
+}
+
static TestResult runCPPCompilerExecute(TestContext* context, TestInput& input)
{
CPPCompilerSet* compilerSet = context->getCPPCompilerSet();
@@ -1131,15 +1145,23 @@ static TestResult runCPPCompilerExecute(TestContext* context, TestInput& input)
options.sourceFiles.add(filePath);
options.modulePath = modulePath;
- ExecuteResult exeRes;
-
- if (SLANG_FAILED(compiler->compile(options, exeRes)))
+ CPPCompiler::Output output;
+ if (SLANG_FAILED(compiler->compile(options, output)))
{
return TestResult::Fail;
}
- // Execute the binary and see what we get
+ String actualOutput;
+
+ // If the actual compilation failed, then the output will be
+ if (SLANG_FAILED(output.result))
+ {
+ actualOutput = _calcSummary(output);
+ }
+ else
{
+ // Execute the binary and see what we get
+
CommandLine cmdLine;
StringBuilder exePath;
@@ -1154,9 +1176,14 @@ static TestResult runCPPCompilerExecute(TestContext* context, TestInput& input)
}
// Write the output, and compare to expected
- String actualOutput = getOutput(exeRes);
- Slang::File::writeAllText(actualOutputPath, actualOutput);
+ actualOutput = getOutput(exeRes);
+ }
+
+ // Write the output
+ Slang::File::writeAllText(actualOutputPath, actualOutput);
+ // Check that they are the same
+ {
// Read the expected
String expectedOutput;
try
@@ -1226,43 +1253,74 @@ static TestResult runCPPCompilerSharedLibrary(TestContext* context, TestInput& i
options.includePaths.add(".");
- ExecuteResult exeRes;
-
- if (SLANG_FAILED(compiler->compile(options, exeRes)))
+ CPPCompiler::Output output;
+ if (SLANG_FAILED(compiler->compile(options, output)))
{
return TestResult::Fail;
}
- SharedLibrary::Handle handle;
- if (SLANG_FAILED(SharedLibrary::loadWithPlatformPath(sharedLibraryPath.getBuffer(), handle)))
+ if (SLANG_FAILED(output.result))
{
- return TestResult::Fail;
- }
-
- const int inValue = 10;
- const char inBuffer[] = "Hello World!";
+ // Compilation failed
+ String actualOutput = _calcSummary(output);
- char buffer[128] = "";
- int value = 0;
+ // Write the output
+ Slang::File::writeAllText(actualOutputPath, actualOutput);
- typedef int (*TestFunc)(int intValue, const char* textValue, char* outTextValue);
+ // Check that they are the same
+ {
+ // Read the expected
+ String expectedOutput;
+ try
+ {
+ String expectedOutputPath = outputStem + ".expected";
+ expectedOutput = Slang::File::readAllText(expectedOutputPath);
+ }
+ catch (Slang::IOException)
+ {
+ }
- // We could capture output if we passed in a ISlangWriter - but for that to work we'd need a
- TestFunc testFunc = (TestFunc)SharedLibrary::findFuncByName(handle, "test");
- if (testFunc)
- {
- value = testFunc(inValue, inBuffer, buffer);
+ // Compare if they are the same
+ if (!StringUtil::areLinesEqual(actualOutput.getUnownedSlice(), expectedOutput.getUnownedSlice()))
+ {
+ context->reporter->dumpOutputDifference(expectedOutput, actualOutput);
+ return TestResult::Fail;
+ }
+ }
}
else
{
- printf("Unable to access 'test' function\n");
- }
+ SharedLibrary::Handle handle;
+ if (SLANG_FAILED(SharedLibrary::loadWithPlatformPath(sharedLibraryPath.getBuffer(), handle)))
+ {
+ return TestResult::Fail;
+ }
- SharedLibrary::unload(handle);
+ const int inValue = 10;
+ const char inBuffer[] = "Hello World!";
- if (!(inValue == value && strcmp(inBuffer, buffer) == 0))
- {
- return TestResult::Fail;
+ char buffer[128] = "";
+ int value = 0;
+
+ typedef int (*TestFunc)(int intValue, const char* textValue, char* outTextValue);
+
+ // We could capture output if we passed in a ISlangWriter - but for that to work we'd need a
+ TestFunc testFunc = (TestFunc)SharedLibrary::findFuncByName(handle, "test");
+ if (testFunc)
+ {
+ value = testFunc(inValue, inBuffer, buffer);
+ }
+ else
+ {
+ printf("Unable to access 'test' function\n");
+ }
+
+ SharedLibrary::unload(handle);
+
+ if (!(inValue == value && strcmp(inBuffer, buffer) == 0))
+ {
+ return TestResult::Fail;
+ }
}
return TestResult::Pass;
diff --git a/tools/slang-test/unit-test-string.cpp b/tools/slang-test/unit-test-string.cpp
index 5811a4a64..d585132c8 100644
--- a/tools/slang-test/unit-test-string.cpp
+++ b/tools/slang-test/unit-test-string.cpp
@@ -72,6 +72,37 @@ static void stringUnitTest()
SLANG_CHECK(_checkLineParser(UnownedStringSlice::fromLiteral("\n")));
SLANG_CHECK(_checkLineParser(UnownedStringSlice::fromLiteral("")));
}
+ {
+ Int value;
+ SLANG_CHECK(SLANG_SUCCEEDED(StringUtil::parseInt(UnownedStringSlice("-10"), value)) && value == -10);
+ SLANG_CHECK(SLANG_SUCCEEDED(StringUtil::parseInt(UnownedStringSlice("0"), value)) && value == 0);
+ SLANG_CHECK(SLANG_SUCCEEDED(StringUtil::parseInt(UnownedStringSlice("-0"), value)) && value == 0);
+
+ SLANG_CHECK(SLANG_SUCCEEDED(StringUtil::parseInt(UnownedStringSlice("13824"), value)) && value == 13824);
+ SLANG_CHECK(SLANG_SUCCEEDED(StringUtil::parseInt(UnownedStringSlice("-13824"), value)) && value == -13824);
+ }
+
+ {
+ UnownedStringSlice values[] = { UnownedStringSlice("hello"), UnownedStringSlice("world"), UnownedStringSlice("!") };
+
+ StringBuilder builder;
+ builder.Clear();
+ StringUtil::join(values, 0, ',', builder);
+ SLANG_CHECK(builder == "");
+
+ builder.Clear();
+ StringUtil::join(values, 1, ',', builder);
+ SLANG_CHECK(builder == "hello");
+
+
+ builder.Clear();
+ StringUtil::join(values, 2, ',', builder);
+ SLANG_CHECK(builder == "hello,world");
+
+ builder.Clear();
+ StringUtil::join(values, 3, UnownedStringSlice("ab"), builder);
+ SLANG_CHECK(builder == "helloabworldab!");
+ }
}
SLANG_UNIT_TEST("String", stringUnitTest);