diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-30 09:10:16 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-30 09:10:16 +0100 |
| commit | 36427c0966faa7aecd586b397ed9b845f18172f5 (patch) | |
| tree | 0d86c7ca9ac9e2e768b54d491bf596fb84f5e45a /nihil.posix/open.test.cc | |
| parent | 034cd404a129103a8dd7747e6bd00ffd5550da93 (diff) | |
| download | nihil-36427c0966faa7aecd586b397ed9b845f18172f5.tar.gz nihil-36427c0966faa7aecd586b397ed9b845f18172f5.tar.bz2 | |
more refactoring; add stat()
Diffstat (limited to 'nihil.posix/open.test.cc')
| -rw-r--r-- | nihil.posix/open.test.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/nihil.posix/open.test.cc b/nihil.posix/open.test.cc new file mode 100644 index 0000000..bb8bcc9 --- /dev/null +++ b/nihil.posix/open.test.cc @@ -0,0 +1,38 @@ +// This source code is released into the public domain. + +#include <catch2/catch_test_macros.hpp> + +import nihil.error; +import nihil.posix; + +namespace { + +SCENARIO("nihil::open() can open an existing file") +{ + GIVEN ("A call to open() for /bin/sh") { + auto ret = nihil::open("/bin/sh", nihil::open_read); + + THEN ("The returned file descriptor should be /bin/sh") { + REQUIRE(ret); + + auto sb1 = nihil::stat(*ret).value(); + auto sb2 = nihil::stat("/bin/sh").value(); + REQUIRE(sb1.st_ino == sb2.st_ino); + REQUIRE(sb1.st_dev == sb2.st_dev); + } + } +} + +SCENARIO("nihil::open_in_path returns ENOENT when the file is not found") +{ + GIVEN ("A call to open for a non-existent file") { + auto ret = nihil::open("/nihil_no_such_file", nihil::open_read); + + THEN ("The return value should be std::errc::no_such_file_or_directory") { + REQUIRE(!ret); + REQUIRE(ret.error() == std::errc::no_such_file_or_directory); + } + } +} + +} // anonymous namespace |
