-// Copyright (C) 2019 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
throw_error,
};
+ // Create an empty stat result. operator bool() will return false,
+ // error_number() will return -1 and other accessors will return false or 0.
+ Stat();
+
// Run stat(2).
//
// Arguments:
int m_errno;
};
+inline Stat::Stat() : m_stat{}, m_errno(-1)
+{
+}
+
inline Stat
Stat::stat(const std::string& path, OnError on_error)
{
using Catch::Equals;
-TEST_CASE("Constructor")
+TEST_CASE("Default constructor")
+{
+ Stat stat;
+ CHECK(!stat);
+ CHECK(stat.error_number() == -1);
+ CHECK(stat.device() == 0);
+ CHECK(stat.inode() == 0);
+ CHECK(stat.mode() == 0);
+ CHECK(stat.ctime() == 0);
+ CHECK(stat.mtime() == 0);
+ CHECK(stat.size() == 0);
+ CHECK(stat.size_on_disk() == 0);
+ CHECK(!stat.is_directory());
+ CHECK(!stat.is_regular());
+ CHECK(!stat.is_symlink());
+}
+
+TEST_CASE("Named constructors")
{
CHECK(!Stat::stat("does_not_exist"));
CHECK(!Stat::stat("does_not_exist", Stat::OnError::ignore));