diff options
| -rw-r--r-- | source/core/slang-io.cpp | 21 | ||||
| -rw-r--r-- | source/core/slang-io.h | 1 | ||||
| -rw-r--r-- | tools/slang-test/slang-test-main.cpp | 4 |
3 files changed, 25 insertions, 1 deletions
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index e52ea0704..a144c5892 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -31,6 +31,27 @@ namespace Slang { + + /* static */SlangResult File::remove(const String& fileName) + { +#ifdef _WIN32 + // https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-deletefilea + if (DeleteFileA(fileName.getBuffer())) + { + return SLANG_OK; + } + return SLANG_FAIL; +#else + // https://linux.die.net/man/2/unlink + + if (unlink(fileName.getBuffer()) == 0) + { + return SLANG_OK; + } + return SLANG_FAIL; +#endif + } + bool File::exists(const String& fileName) { #ifdef _WIN32 diff --git a/source/core/slang-io.h b/source/core/slang-io.h index 64ec11c5a..4fa921662 100644 --- a/source/core/slang-io.h +++ b/source/core/slang-io.h @@ -15,6 +15,7 @@ namespace Slang static Slang::String readAllText(const Slang::String& fileName); static Slang::List<unsigned char> readAllBytes(const Slang::String& fileName); static void writeAllText(const Slang::String& fileName, const Slang::String& text); + static SlangResult remove(const String& fileName); }; class Path diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index 912d13b78..b93833f89 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -1103,6 +1103,9 @@ static TestResult runExecuteC(TestContext* context, TestInput& input) auto filePath = input.filePath; auto outputStem = input.outputStem; + String actualOutputPath = outputStem + ".actual"; + File::remove(actualOutputPath); + // Make the module name the same as the source file String directory = Path::getParentDirectory(input.outputStem); String moduleName = Path::getFileNameWithoutExt(filePath); @@ -1162,7 +1165,6 @@ static TestResult runExecuteC(TestContext* context, TestInput& input) // Write the output, and compare to expected String actualOutput = getOutput(exeRes); - String actualOutputPath = outputStem + ".actual"; Slang::File::writeAllText(actualOutputPath, actualOutput); // Read the expected |
