--- /dev/null
+dne
\ No newline at end of file
--- /dev/null
+dir3
\ No newline at end of file
--- /dev/null
+dir1
\ No newline at end of file
--- /dev/null
+empty_file
\ No newline at end of file
TEST_CASE(path_ctor_dne) {
using namespace fs;
- static_test_env static_env;
-
{
std::error_code ec = GetTestEC();
directory_entry ent(StaticEnv::DNE, ec);
TEST_CASE(error_reporting) {
using namespace fs;
- static_test_env static_env;
scoped_test_env env;
const path dir = env.create_dir("dir");
TEST_CASE(error_reporting) {
using namespace fs;
- static_test_env static_env;
scoped_test_env env;
const path dir = env.create_dir("dir");
TEST_CASE(error_reporting) {
using namespace fs;
- static_test_env static_env;
scoped_test_env env;
const path dir = env.create_dir("dir");
TEST_CASE(test_construction_from_bad_path)
{
- static_test_env static_env;
std::error_code ec;
directory_options opts = directory_options::none;
const directory_iterator endIt;
TEST_CASE(test_open_on_directory_succeeds)
{
- static_test_env static_env;
const path testDir = StaticEnv::Dir;
std::set<path> dir_contents(std::begin(StaticEnv::DirIterationList),
std::end( StaticEnv::DirIterationList));
TEST_CASE(test_open_on_file_fails)
{
- static_test_env static_env;
const path testFile = StaticEnv::File;
const directory_iterator endIt{};
{
TEST_CASE(test_open_on_symlink)
{
- static_test_env static_env;
const path symlinkToDir = StaticEnv::SymlinkToDir;
std::set<path> dir_contents;
for (path const& p : StaticEnv::DirIterationList) {
TEST_CASE(test_prefix_increment)
{
- static_test_env static_env;
const path testDir = StaticEnv::Dir;
const std::set<path> dir_contents(std::begin(StaticEnv::RecDirIterationList),
std::end( StaticEnv::RecDirIterationList));
TEST_CASE(test_postfix_increment)
{
- static_test_env static_env;
const path testDir = StaticEnv::Dir;
const std::set<path> dir_contents(std::begin(StaticEnv::RecDirIterationList),
std::end( StaticEnv::RecDirIterationList));
TEST_CASE(test_increment_method)
{
- static_test_env static_env;
const path testDir = StaticEnv::Dir;
const std::set<path> dir_contents(std::begin(StaticEnv::RecDirIterationList),
std::end( StaticEnv::RecDirIterationList));
TEST_CASE(test_follow_symlinks)
{
- static_test_env static_env;
const path testDir = StaticEnv::Dir;
auto const& IterList = StaticEnv::RecDirFollowSymlinksIterationList;
TEST_CASE(test_ranged_for_loop)
{
- static_test_env static_env;
const path testDir = StaticEnv::Dir;
std::set<path> dir_contents(std::begin(StaticEnv::RecDirIterationList),
std::end( StaticEnv::RecDirIterationList));
// Each scope tests one of the cases.
TEST_CASE(test_canonical)
{
- static_test_env static_env;
CWDGuard guard;
// has_root_name() && has_root_directory()
const path Root = StaticEnv::Root;
}
TEST_CASE(equivalent_test) {
- static_test_env static_env;
struct TestCase {
path lhs;
path rhs;
TEST_CASE(symlink_test_case)
{
- static_test_env static_env;
const path p = StaticEnv::File;
const path p2 = StaticEnv::SymlinkToFile;
TEST_CHECK(file_size(p) == file_size(p2));
TEST_CASE(file_size_error_cases)
{
- static_test_env static_env;
struct {
path p;
std::errc expected_err;
TEST_CASE(static_env_test)
{
- static_test_env static_env;
TEST_CHECK(is_directory(StaticEnv::Dir));
TEST_CHECK(is_directory(StaticEnv::SymlinkToDir));
TEST_CHECK(!is_directory(StaticEnv::File));
TEST_CASE(test_is_empty_directory)
{
- static_test_env static_env;
TEST_CHECK(!is_empty(StaticEnv::Dir));
TEST_CHECK(!is_empty(StaticEnv::SymlinkToDir));
}
TEST_CASE(static_env_test)
{
- static_test_env static_env;
struct TestCase {
path p;
bool expect;
TEST_CASE(read_last_write_time_static_env_test)
{
- static_test_env static_env;
using C = file_time_type::clock;
file_time_type min = file_time_type::min();
{
}
TEST_CASE(test_signature_4) {
- static_test_env static_env;
fs::path p(StaticEnv::SymlinkToDir);
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir));
}
TEST_CASE(test_signature_5) {
- static_test_env static_env;
fs::path p(StaticEnv::SymlinkToDir / "dir2/.");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir / "dir2"));
}
TEST_CASE(test_signature_6) {
- static_test_env static_env;
// FIXME? If the trailing separator occurs in a part of the path that exists,
// it is omitted. Otherwise it is added to the end of the result.
fs::path p(StaticEnv::SymlinkToDir / "dir2/./");
}
TEST_CASE(test_signature_7) {
- static_test_env static_env;
fs::path p(StaticEnv::SymlinkToDir / "dir2/DNE/./");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir / "dir2/DNE/"));
}
TEST_CASE(test_signature_8) {
- static_test_env static_env;
fs::path p(StaticEnv::SymlinkToDir / "dir2");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir2));
}
TEST_CASE(test_signature_9) {
- static_test_env static_env;
fs::path p(StaticEnv::SymlinkToDir / "dir2/../dir2/DNE/..");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir2 / ""));
}
TEST_CASE(test_signature_10) {
- static_test_env static_env;
fs::path p(StaticEnv::SymlinkToDir / "dir2/dir3/../DNE/DNE2");
const fs::path output = fs::weakly_canonical(p);
TEST_CHECK(output == std::string(StaticEnv::Dir2 / "DNE/DNE2"));
TEST_CASE(basic_space_test)
{
- static_test_env static_env;
-
// All the test cases should reside on the same filesystem and therefore
// should have the same expected result. Compute this expected result
// one and check that it looks semi-sane.
TEST_CASE(status_file_types_test)
{
- static_test_env static_env;
scoped_test_env env;
struct TestCase {
path p;
TEST_CASE(symlink_status_file_types_test)
{
- static_test_env static_env;
scoped_test_env env;
struct TestCase {
path p;
int main(int, char**) {
-
- static_test_env static_env;
-
// clang-format off
struct {
std::string input;
#include "filesystem_include.h"
-#include <unistd.h> // for ftruncate, symlink, unlink
+#include <unistd.h> // for ftruncate
#include <cassert>
#include <cstdio> // for printf
makePath("dir1/dir2/symlink_to_dir3/file5"),
};
-static const std::pair<fs::path, fs::path> SymlinkList[] = {
- {"dne", makePath("bad_symlink")},
- {"dir1", makePath("symlink_to_dir")},
- {"empty_file", makePath("symlink_to_empty_file")},
- {"dir3", makePath("dir1/dir2/symlink_to_dir3")}
-};
-
} // namespace StaticEnv
namespace random_utils {
} // namespace random_utils
-/// A RAII object that prepares the 'static_test_env' directory for usage in
-/// tests.
-///
-/// Namely, it creates some symlinks that tests expect to be present.
-/// We do it here instead of storing them in the repo to be
-/// cross-toolchain-friendly. The primary use case for this are Windows-hosted
-/// cross-toolchains.
-/// Windows doesn't really have a concept of symlinks. So, when the monorepo
-/// is cloned, those symlinks turn to ordinary text files.
-/// If we cross-compiled libc++ for some symlink-friendly system
-/// (e. g. Linux) and ran tests on the target system, some tests would fail.
-/// Instead, we create symlinks here, when a test is already being executed.
-class static_test_env {
-public:
- static_test_env() {
- for (const auto *link = std::begin(StaticEnv::SymlinkList);
- link != std::end(StaticEnv::SymlinkList);
- ++link) {
- int ret = ::symlink(link->first.c_str(), link->second.c_str());
- assert(ret == 0);
- }
- }
-
- ~static_test_env() {
- for (const auto *link = std::begin(StaticEnv::SymlinkList);
- link != std::end(StaticEnv::SymlinkList);
- ++link) {
- int ret = ::unlink(link->second.c_str());
- assert(ret == 0);
- }
- }
-};
-
struct scoped_test_env
{
scoped_test_env() : test_root(random_path()) {