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/stat.test.cc | |
| parent | 034cd404a129103a8dd7747e6bd00ffd5550da93 (diff) | |
| download | nihil-36427c0966faa7aecd586b397ed9b845f18172f5.tar.gz nihil-36427c0966faa7aecd586b397ed9b845f18172f5.tar.bz2 | |
more refactoring; add stat()
Diffstat (limited to 'nihil.posix/stat.test.cc')
| -rw-r--r-- | nihil.posix/stat.test.cc | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/nihil.posix/stat.test.cc b/nihil.posix/stat.test.cc new file mode 100644 index 0000000..cf1e29c --- /dev/null +++ b/nihil.posix/stat.test.cc @@ -0,0 +1,59 @@ +// This source code is released into the public domain. + +import nihil.error; +import nihil.posix; + +#include <sys/stat.h> + +#include <catch2/catch_test_macros.hpp> + +namespace { + +SCENARIO("nihil::stat() on an existing file") +{ + GIVEN("A call to stat() on /etc/passwd") + { + auto sb = nihil::stat("/etc/passwd"); + + THEN("The returned struct is correct") + { + REQUIRE(sb); + REQUIRE(S_ISREG(sb->st_mode)); + } + } +} + +SCENARIO("nihil::stat() on a non-existent file") +{ + GIVEN("A call to stat() on /nonesuchfile") + { + auto sb = nihil::stat("/nonesuchfile"); + + THEN("std::errc::no_such_file_or_directory is returned") + { + REQUIRE(!sb); + REQUIRE(sb.error() == std::errc::no_such_file_or_directory); + } + } +} + +SCENARIO("nihil::stat() on an open file descriptor") +{ + GIVEN("An fd referring to /etc/password") + { + auto fd = nihil::open("/etc/passwd", nihil::open_read).value(); + + WHEN("nihil::stat() is called on the fd") + { + auto sb = nihil::stat(fd); + + THEN("The returned struct is correct") + { + REQUIRE(sb); + REQUIRE(S_ISREG(sb->st_mode)); + } + } + } +} + +} // anonymous namespace |
