diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-06-24 16:08:08 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-24 16:08:08 -0400 |
| commit | f1b41a71be938b8711ee0fff0130185f512d2336 (patch) | |
| tree | 29ad602a61968e1aacdf8424afc0c89defdb4330 /tools/slang-unit-test/unit-test-io.cpp | |
| parent | c12c0ad7fbb0272283f224493dbc28d9d60e7b91 (diff) | |
Handling of temporary files (#2299)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Work around windows issue with temporary file clash.
* Handle the temporary file path actually creates a file.
* Fix typo.
* Fix typo in linux for temporary file.
* Add unit test for io. Tests generateTemporary operation.
Diffstat (limited to 'tools/slang-unit-test/unit-test-io.cpp')
| -rw-r--r-- | tools/slang-unit-test/unit-test-io.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tools/slang-unit-test/unit-test-io.cpp b/tools/slang-unit-test/unit-test-io.cpp new file mode 100644 index 000000000..fbac5af17 --- /dev/null +++ b/tools/slang-unit-test/unit-test-io.cpp @@ -0,0 +1,64 @@ +// unit-test-io.cpp + +#include "../../source/core/slang-io.h" + +#include "tools/unit-test/slang-unit-test.h" + +using namespace Slang; + +static SlangResult _checkGenerateTemporary() +{ + /// Test temporary file functionality + + List<String> paths; + + for (Index i = 0; i < 10; ++i) + { + String path; + SLANG_RETURN_ON_FAIL(File::generateTemporary(toSlice("slang-check"), path)); + + // The path should exist exist + SLANG_CHECK(File::exists(path)); + + if (paths.contains(path)) + { + return SLANG_FAIL; + } + + paths.add(path); + } + + // It should be possible to write to the temporary files + for (auto& path : paths) + { + SLANG_RETURN_ON_FAIL(File::writeAllText(path, path)); + } + // It should be possible to read from the temporary files + + for (auto& path : paths) + { + String contents; + SLANG_RETURN_ON_FAIL(File::readAllText(path, contents)) + + SLANG_CHECK(contents == path); + } + + // Remove all the temporary files + for (auto& path : paths) + { + SLANG_CHECK(File::exists(path)); + + const auto removeResult = File::remove(path); + SLANG_CHECK(SLANG_SUCCEEDED(removeResult)); + + // Check remove worked + SLANG_CHECK(!File::exists(path)); + } + + return SLANG_OK; +} + +SLANG_UNIT_TEST(io) +{ + SLANG_CHECK(SLANG_SUCCEEDED(_checkGenerateTemporary())); +} |
