Skip to content

Commit

Permalink
Move tests to tmp namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
bugdea1er committed Apr 30, 2024
1 parent e5221eb commit fea54c5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 36 deletions.
34 changes: 17 additions & 17 deletions tests/directory_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

#include <gtest/gtest.h>

namespace fs = tmp::fs;
namespace tmp {

TEST(DirectoryTest, CreateDirectory) {
{
const auto tmpdir = tmp::directory(PREFIX);
const auto tmpdir = directory(PREFIX);
const auto parent = tmpdir->parent_path();

ASSERT_TRUE(fs::exists(tmpdir));
ASSERT_TRUE(fs::equivalent(parent, fs::temp_directory_path() / PREFIX));
}
{
const auto tmpdir = tmp::directory();
const auto tmpdir = directory();
const auto parent = tmpdir->parent_path();

ASSERT_TRUE(fs::exists(tmpdir));
Expand All @@ -25,7 +25,7 @@ TEST(DirectoryTest, CreateDirectory) {
TEST(DirectoryTest, RemoveDirectory) {
auto path = fs::path();
{
const auto tmpdir = tmp::directory(PREFIX);
const auto tmpdir = directory(PREFIX);
path = tmpdir;
ASSERT_TRUE(fs::exists(path));
}
Expand All @@ -34,17 +34,17 @@ TEST(DirectoryTest, RemoveDirectory) {
}

TEST(DirectoryTest, CreateMultiple) {
const auto fst = tmp::directory(PREFIX);
const auto fst = directory(PREFIX);
ASSERT_TRUE(fs::exists(fst));

const auto snd = tmp::directory(PREFIX);
const auto snd = directory(PREFIX);
ASSERT_TRUE(fs::exists(snd));

EXPECT_NE(fs::path(fst), fs::path(snd));
}

TEST(DirectoryTest, SubpathTest) {
const auto tmpdir = tmp::directory(PREFIX);
const auto tmpdir = directory(PREFIX);
const auto child = tmpdir / "child";

ASSERT_EQ(fs::path(tmpdir), child.parent_path());
Expand All @@ -53,7 +53,7 @@ TEST(DirectoryTest, SubpathTest) {
TEST(DirectoryTest, Release) {
auto path = fs::path();
{
auto tmpdir = tmp::directory(PREFIX);
auto tmpdir = directory(PREFIX);
auto expected = fs::path(tmpdir);
path = tmpdir.release();
ASSERT_EQ(path, expected);
Expand All @@ -68,7 +68,7 @@ TEST(DirectoryTest, MoveDirectory) {
auto path = fs::path();
auto to = fs::temp_directory_path() / PREFIX / "moved";
{
auto tmpdir = tmp::directory(PREFIX);
auto tmpdir = directory(PREFIX);
path = tmpdir;

tmpdir.move(to);
Expand All @@ -80,16 +80,16 @@ TEST(DirectoryTest, MoveDirectory) {
}

TEST(DirectoryTest, MoveConstruction) {
auto fst = tmp::directory(PREFIX);
auto fst = directory(PREFIX);
const auto snd = std::move(fst);

ASSERT_TRUE(fst->empty());
ASSERT_TRUE(fs::exists(snd));
}

TEST(DirectoryTest, MoveAssignment) {
auto fst = tmp::directory(PREFIX);
auto snd = tmp::directory(PREFIX);
auto fst = directory(PREFIX);
auto snd = directory(PREFIX);

const auto path1 = fs::path(fst);
const auto path2 = fs::path(snd);
Expand All @@ -105,13 +105,13 @@ TEST(DirectoryTest, MoveAssignment) {

TEST(DirectoryTest, Copy) {
{
const auto tmpdir = tmp::directory(PREFIX);
const auto tmpdir = directory(PREFIX);

auto file = std::ofstream(tmpdir / "file");
file << "Hello, world!";
file.close();

const auto tmpcopy = tmp::directory::copy(tmpdir, PREFIX);
const auto tmpcopy = directory::copy(tmpdir, PREFIX);

auto stream = std::ifstream(tmpcopy / "file");
auto content = std::string(std::istreambuf_iterator<char>(stream), {});
Expand All @@ -120,8 +120,8 @@ TEST(DirectoryTest, Copy) {
EXPECT_NE(fs::path(tmpdir), fs::path(tmpcopy));
}
{
const auto tmpfile = tmp::file(PREFIX);
ASSERT_THROW(tmp::directory::copy(tmpfile, PREFIX),
fs::filesystem_error);
const auto tmpfile = file(PREFIX);
ASSERT_THROW(directory::copy(tmpfile, PREFIX), fs::filesystem_error);
}
}
} // namespace tmp
39 changes: 20 additions & 19 deletions tests/file_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

#include <gtest/gtest.h>

namespace fs = tmp::fs;
namespace tmp {

TEST(FileTest, CreateFile) {
{
const auto tmpfile = tmp::file(PREFIX);
const auto tmpfile = file(PREFIX);
const auto parent = tmpfile->parent_path();

ASSERT_TRUE(fs::exists(tmpfile));
ASSERT_TRUE(fs::equivalent(parent, fs::temp_directory_path() / PREFIX));
}
{
const auto tmpfile = tmp::file();
const auto tmpfile = file();
const auto parent = tmpfile->parent_path();

ASSERT_TRUE(fs::exists(tmpfile));
Expand All @@ -25,7 +25,7 @@ TEST(FileTest, CreateFile) {
TEST(FileTest, RemoveFile) {
auto path = fs::path();
{
const auto tmpfile = tmp::file(PREFIX);
const auto tmpfile = file(PREFIX);
path = tmpfile;
ASSERT_TRUE(fs::exists(path));
}
Expand All @@ -34,10 +34,10 @@ TEST(FileTest, RemoveFile) {
}

TEST(FileTest, CreateMultiple) {
const auto fst = tmp::file(PREFIX);
const auto fst = file(PREFIX);
ASSERT_TRUE(fs::exists(fst));

const auto snd = tmp::file(PREFIX);
const auto snd = file(PREFIX);
ASSERT_TRUE(fs::exists(snd));

EXPECT_NE(fs::path(fst), fs::path(snd));
Expand All @@ -46,7 +46,7 @@ TEST(FileTest, CreateMultiple) {
TEST(FileTest, Release) {
auto path = fs::path();
{
auto tmpfile = tmp::file(PREFIX);
auto tmpfile = file(PREFIX);
auto expected = fs::path(tmpfile);
path = tmpfile.release();
ASSERT_EQ(path, expected);
Expand All @@ -61,7 +61,7 @@ TEST(FileTest, MoveFile) {
auto path = fs::path();
auto to = fs::temp_directory_path() / PREFIX / "non-existing" / "parent";
{
auto tmpfile = tmp::file(PREFIX);
auto tmpfile = file(PREFIX);
path = tmpfile;

tmpfile.move(to);
Expand All @@ -73,16 +73,16 @@ TEST(FileTest, MoveFile) {
}

TEST(FileTest, MoveConstruction) {
auto fst = tmp::file(PREFIX);
auto fst = file(PREFIX);
const auto snd = std::move(fst);

ASSERT_TRUE(fst->empty());
ASSERT_TRUE(fs::exists(snd));
}

TEST(FileTest, MoveAssignment) {
auto fst = tmp::file(PREFIX);
auto snd = tmp::file(PREFIX);
auto fst = file(PREFIX);
auto snd = file(PREFIX);

const auto path1 = fs::path(fst);
const auto path2 = fs::path(snd);
Expand All @@ -97,7 +97,7 @@ TEST(FileTest, MoveAssignment) {
}

TEST(FileTest, Read) {
const auto tmpfile = tmp::file(PREFIX);
const auto tmpfile = file(PREFIX);
tmpfile.write("Hello");
tmpfile.append(", world!");

Expand All @@ -108,7 +108,7 @@ TEST(FileTest, Read) {
}

TEST(FileTest, Slurp) {
const auto tmpfile = tmp::file(PREFIX);
const auto tmpfile = file(PREFIX);
tmpfile.write("Hello");
tmpfile.append(", world!");

Expand All @@ -117,7 +117,7 @@ TEST(FileTest, Slurp) {
}

TEST(FileTest, Write) {
const auto tmpfile = tmp::file(PREFIX);
const auto tmpfile = file(PREFIX);
tmpfile.write("Hello");

auto stream = std::ifstream(fs::path(tmpfile));
Expand All @@ -126,7 +126,7 @@ TEST(FileTest, Write) {
}

TEST(FileTest, Append) {
const auto tmpfile = tmp::file(PREFIX);
const auto tmpfile = file(PREFIX);

tmpfile.write("Hello");
tmpfile.append(", world!");
Expand All @@ -138,15 +138,16 @@ TEST(FileTest, Append) {

TEST(FileTest, Copy) {
{
const auto tmpfile = tmp::file(PREFIX);
const auto tmpfile = file(PREFIX);
tmpfile.write("Hello, world!");

const auto tmpcopy = tmp::file::copy(tmpfile, PREFIX);
const auto tmpcopy = file::copy(tmpfile, PREFIX);
ASSERT_EQ(tmpcopy.slurp(), "Hello, world!");
EXPECT_NE(fs::path(tmpfile), fs::path(tmpcopy));
}
{
const auto tmpdir = tmp::directory(PREFIX);
ASSERT_THROW(tmp::file::copy(tmpdir, PREFIX), fs::filesystem_error);
const auto tmpdir = directory(PREFIX);
ASSERT_THROW(file::copy(tmpdir, PREFIX), fs::filesystem_error);
}
}
} // namespace tmp

0 comments on commit fea54c5

Please sign in to comment.