// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "../src/Args.hpp"
+#include "TestUtil.hpp"
#include "third_party/catch.hpp"
+using TestUtil::TestContext;
+
TEST_CASE("Args default constructor")
{
Args args;
TEST_CASE("Args::from_gcc_atfile")
{
+ TestContext testContext;
+
Args args;
SECTION("Non-existing file")
#include "../src/AtomicFile.hpp"
#include "../src/Util.hpp"
+#include "TestUtil.hpp"
#include "third_party/catch.hpp"
using Catch::Equals;
+using TestUtil::TestContext;
TEST_CASE("Base case")
{
- unlink("test");
+ TestContext test_context;
+
AtomicFile atomic_file("test", AtomicFile::Mode::text);
atomic_file.write("h");
atomic_file.write(std::vector<uint8_t>{0x65, 0x6c});
TEST_CASE("Not committing")
{
- unlink("test");
+ TestContext test_context;
+
{
AtomicFile atomic_file("test", AtomicFile::Mode::text);
atomic_file.write("hello");
#include "../src/Util.hpp"
#include "../src/ccache.hpp"
#include "../src/exceptions.hpp"
+#include "TestUtil.hpp"
#include "third_party/catch.hpp"
#include "third_party/fmt/core.h"
#include <vector>
using Catch::Equals;
+using TestUtil::TestContext;
TEST_CASE("Config: default values")
{
TEST_CASE("Config::update_from_file")
{
+ TestContext test_context;
+
const char user[] = "rabbit";
x_setenv("USER", user);
TEST_CASE("Config::update_from_file, error handling")
{
+ TestContext test_context;
+
Config config;
- unlink("ccache.conf"); // Make sure it doesn't exist.
SECTION("missing equal sign")
{
TEST_CASE("Config::set_value_in_file")
{
+ TestContext test_context;
+
SECTION("set new value")
{
Util::write_file("ccache.conf", "path = vanilla\n");
TEST_CASE("Config::visit_items")
{
+ TestContext test_context;
+
Util::write_file(
"test.conf",
#ifndef _WIN32
#include "../src/Lockfile.hpp"
#include "../src/Stat.hpp"
+#include "TestUtil.hpp"
#include "third_party/catch.hpp"
+using TestUtil::TestContext;
+
TEST_CASE("Lockfile acquire and release")
{
+ TestContext test_context;
+
{
Lockfile lock("test", 1000);
CHECK(lock.acquired());
#ifndef _WIN32
TEST_CASE("Lockfile breaking")
{
+ TestContext test_context;
+
CHECK(symlink("foo", "test.lock") == 0);
Lockfile lock("test", 1000);
#include "../src/Compressor.hpp"
#include "../src/Decompressor.hpp"
#include "../src/File.hpp"
+#include "TestUtil.hpp"
#include "third_party/catch.hpp"
using Catch::Equals;
+using TestUtil::TestContext;
TEST_CASE("Compression::Type::none roundtrip")
{
+ TestContext test_context;
+
File f("data.uncompressed", "w");
auto compressor =
Compressor::create_from_type(Compression::Type::none, f.get(), 1);
#include "../src/Stat.hpp"
#include "../src/Util.hpp"
+#include "TestUtil.hpp"
#include "third_party/catch.hpp"
#include <unistd.h>
using Catch::Equals;
+using TestUtil::TestContext;
TEST_CASE("Default constructor")
{
TEST_CASE("Same i-node as")
{
+ TestContext test_context;
+
Util::write_file("a", "");
Util::write_file("b", "");
auto a_stat = Stat::stat("a");
TEST_CASE("Return values when file exists")
{
+ TestContext test_context;
+
Util::write_file("file", "1234567");
auto stat = Stat::stat("file");
TEST_CASE("Directory")
{
- rmdir("directory");
+ TestContext test_context;
+
REQUIRE(mkdir("directory", 0456) == 0);
auto stat = Stat::stat("directory");
#ifndef _WIN32
TEST_CASE("Symlinks")
{
+ TestContext test_context;
+
Util::write_file("file", "1234567");
SECTION("file lstat")
SECTION("symlink lstat")
{
- unlink("symlink");
REQUIRE(symlink("file", "symlink") == 0);
auto stat = Stat::lstat("symlink", Stat::OnError::ignore);
CHECK(stat);
SECTION("symlink stat")
{
- unlink("symlink");
REQUIRE(symlink("file", "symlink") == 0);
auto stat = Stat::stat("symlink", Stat::OnError::ignore);
CHECK(stat);
#include "../src/Config.hpp"
#include "../src/Util.hpp"
+#include "TestUtil.hpp"
#include "third_party/catch.hpp"
using Catch::EndsWith;
using Catch::Equals;
+using TestUtil::TestContext;
TEST_CASE("Util::base_name")
{
TEST_CASE("Util::create_dir")
{
+ TestContext test_context;
+
CHECK(Util::create_dir("/"));
CHECK(Util::create_dir("create/dir"));
TEST_CASE("Util::get_level_1_files")
{
+ TestContext test_context;
+
Util::create_dir("e/m/p/t/y");
Util::create_dir("0/1");
TEST_CASE("Util::read_file and Util::write_file")
{
+ TestContext test_context;
+
Util::write_file("test", "foo\nbar\n");
std::string data = Util::read_file("test");
CHECK(data == "foo\nbar\n");
TEST_CASE("Util::traverse")
{
- REQUIRE(Util::create_dir("traverse/dir-with-subdir-and-file/subdir"));
- Util::write_file("traverse/dir-with-subdir-and-file/subdir/f", "");
- REQUIRE(Util::create_dir("traverse/dir-with-files"));
- Util::write_file("traverse/dir-with-files/f1", "");
- Util::write_file("traverse/dir-with-files/f2", "");
- REQUIRE(Util::create_dir("traverse/empty-dir"));
+ TestContext test_context;
+
+ REQUIRE(Util::create_dir("dir-with-subdir-and-file/subdir"));
+ Util::write_file("dir-with-subdir-and-file/subdir/f", "");
+ REQUIRE(Util::create_dir("dir-with-files"));
+ Util::write_file("dir-with-files/f1", "");
+ Util::write_file("dir-with-files/f2", "");
+ REQUIRE(Util::create_dir("empty-dir"));
std::vector<std::string> visited;
auto visitor = [&visited](const std::string& path, bool is_dir) {
SECTION("traverse file")
{
- CHECK_NOTHROW(
- Util::traverse("traverse/dir-with-subdir-and-file/subdir/f", visitor));
+ CHECK_NOTHROW(Util::traverse("dir-with-subdir-and-file/subdir/f", visitor));
REQUIRE(visited.size() == 1);
- CHECK(visited[0] == "[f] traverse/dir-with-subdir-and-file/subdir/f");
+ CHECK(visited[0] == "[f] dir-with-subdir-and-file/subdir/f");
}
SECTION("traverse empty directory")
{
- CHECK_NOTHROW(Util::traverse("traverse/empty-dir", visitor));
+ CHECK_NOTHROW(Util::traverse("empty-dir", visitor));
REQUIRE(visited.size() == 1);
- CHECK(visited[0] == "[d] traverse/empty-dir");
+ CHECK(visited[0] == "[d] empty-dir");
}
SECTION("traverse directory with files")
{
- CHECK_NOTHROW(Util::traverse("traverse/dir-with-files", visitor));
+ CHECK_NOTHROW(Util::traverse("dir-with-files", visitor));
REQUIRE(visited.size() == 3);
- std::string f1 = "[f] traverse/dir-with-files/f1";
- std::string f2 = "[f] traverse/dir-with-files/f2";
+ std::string f1 = "[f] dir-with-files/f1";
+ std::string f2 = "[f] dir-with-files/f2";
CHECK(((visited[0] == f1 && visited[1] == f2)
|| (visited[0] == f2 && visited[1] == f1)));
- CHECK(visited[2] == "[d] traverse/dir-with-files");
+ CHECK(visited[2] == "[d] dir-with-files");
}
SECTION("traverse directory hierarchy")
{
- CHECK_NOTHROW(Util::traverse("traverse/dir-with-subdir-and-file", visitor));
+ CHECK_NOTHROW(Util::traverse("dir-with-subdir-and-file", visitor));
REQUIRE(visited.size() == 3);
- CHECK(visited[0] == "[f] traverse/dir-with-subdir-and-file/subdir/f");
- CHECK(visited[1] == "[d] traverse/dir-with-subdir-and-file/subdir");
- CHECK(visited[2] == "[d] traverse/dir-with-subdir-and-file");
+ CHECK(visited[0] == "[f] dir-with-subdir-and-file/subdir/f");
+ CHECK(visited[1] == "[d] dir-with-subdir-and-file/subdir");
+ CHECK(visited[2] == "[d] dir-with-subdir-and-file");
}
}
TEST_CASE("Util::wipe_path")
{
+ TestContext test_context;
+
SECTION("Wipe non-existing path")
{
CHECK_NOTHROW(Util::wipe_path("a"));
#include "../src/Compressor.hpp"
#include "../src/Decompressor.hpp"
#include "../src/File.hpp"
+#include "TestUtil.hpp"
#include "third_party/catch.hpp"
using Catch::Equals;
+using TestUtil::TestContext;
TEST_CASE("Small Compression::Type::zstd roundtrip")
{
+ TestContext test_context;
+
File f("data.zstd", "wb");
auto compressor =
Compressor::create_from_type(Compression::Type::zstd, f.get(), 1);
TEST_CASE("Large compressible Compression::Type::zstd roundtrip")
{
+ TestContext test_context;
+
char data[] = "The quick brown fox jumps over the lazy dog";
File f("data.zstd", "wb");
TEST_CASE("Large uncompressible Compression::Type::zstd roundtrip")
{
+ TestContext test_context;
+
char data[100000];
for (char& c : data) {
c = rand() % 256;
#include "../src/Util.hpp"
#include "../src/ccache.hpp"
#include "../src/stats.hpp"
+#include "TestUtil.hpp"
#include "argprocessing.hpp"
#include "util.hpp"
#include "third_party/catch.hpp"
+using TestUtil::TestContext;
+
namespace {
std::string
TEST_CASE("dash_E_should_result_in_called_for_preprocessing")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args = Args::from_string("cc -c foo.c -E");
TEST_CASE("dash_M_should_be_unsupported")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args = Args::from_string("cc -c foo.c -M");
TEST_CASE("dependency_args_to_preprocessor_if_run_second_cpp_is_false")
{
+ TestContext test_context;
+
Context ctx;
#define DEP_ARGS \
TEST_CASE("dependency_args_to_compiler_if_run_second_cpp_is_true")
{
+ TestContext test_context;
+
Context ctx;
#define DEP_ARGS \
TEST_CASE("cpp_only_args_to_preprocessor_if_run_second_cpp_is_false")
{
+ TestContext test_context;
+
Context ctx;
#define CPP_ARGS \
TEST_CASE(
"cpp_only_args_to_preprocessor_and_compiler_if_run_second_cpp_is_true")
{
+ TestContext test_context;
+
Context ctx;
#define CPP_ARGS \
TEST_CASE(
"dependency_args_that_take_an_argument_should_not_require_space_delimiter")
{
+ TestContext test_context;
+
Context ctx;
#define DEP_ARGS "-MMD -MFfoo.d -MT mt -MTmt -MQmq"
TEST_CASE("MQ_flag_should_not_be_added_if_run_second_cpp_is_true")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args = Args::from_string("cc -c -MD foo.c -MF foo.d -o foo.o");
TEST_CASE("MQ_flag_should_be_added_if_run_second_cpp_is_false")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args = Args::from_string("cc -c -MD foo.c -MF foo.d -o foo.o");
TEST_CASE("MF_should_be_added_if_run_second_cpp_is_false")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args = Args::from_string("cc -c -MD foo.c -o foo.o");
TEST_CASE("MF_should_not_be_added_if_run_second_cpp_is_true")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args = Args::from_string("cc -c -MD foo.c -o foo.o");
TEST_CASE("equal_sign_after_MF_should_be_removed")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args = Args::from_string("cc -c -MF=path foo.c -o foo.o");
TEST_CASE("sysroot_should_be_rewritten_if_basedir_is_used")
{
+ TestContext test_context;
+
Context ctx;
char* arg_string;
TEST_CASE(
"sysroot_with_separate_argument_should_be_rewritten_if_basedir_is_used")
{
+ TestContext test_context;
+
Context ctx;
char* arg_string;
TEST_CASE("MF_flag_with_immediate_argument_should_work_as_last_argument")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args =
TEST_CASE("MT_flag_with_immediate_argument_should_work_as_last_argument")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args =
TEST_CASE("MQ_flag_with_immediate_argument_should_work_as_last_argument")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args =
TEST_CASE("MQ_flag_without_immediate_argument_should_not_add_MQobj")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args = Args::from_string("gcc -c -MD -MP -MFfoo.d -MQ foo.d foo.c");
TEST_CASE("MT_flag_without_immediate_argument_should_not_add_MTobj")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args = Args::from_string("gcc -c -MD -MP -MFfoo.d -MT foo.d foo.c");
TEST_CASE("MQ_flag_with_immediate_argument_should_not_add_MQobj")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args = Args::from_string("gcc -c -MD -MP -MFfoo.d -MQfoo.d foo.c");
TEST_CASE("MT_flag_with_immediate_argument_should_not_add_MQobj")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args = Args::from_string("gcc -c -MD -MP -MFfoo.d -MTfoo.d foo.c");
TEST_CASE(
"isystem_flag_with_separate_arg_should_be_rewritten_if_basedir_is_used")
{
+ TestContext test_context;
+
Context ctx;
char* arg_string;
TEST_CASE("isystem_flag_with_concat_arg_should_be_rewritten_if_basedir_is_used")
{
+ TestContext test_context;
+
Context ctx;
char* cwd;
TEST_CASE("I_flag_with_concat_arg_should_be_rewritten_if_basedir_is_used")
{
+ TestContext test_context;
+
Context ctx;
char* cwd;
TEST_CASE("debug_flag_order_with_known_option_first")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args = Args::from_string("cc -g1 -gsplit-dwarf foo.c -c");
TEST_CASE("debug_flag_order_with_known_option_last")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args = Args::from_string("cc -gsplit-dwarf -g1 foo.c -c");
TEST_CASE("options_not_to_be_passed_to_the_preprocesor")
{
+ TestContext test_context;
+
Context ctx;
ctx.orig_args = Args::from_string(
TEST_CASE("cuda_option_file")
{
+ TestContext test_context;
+
Context ctx;
ctx.guessed_compiler = GuessedCompiler::nvcc;
#include "../src/Context.hpp"
#include "../src/hashutil.hpp"
+#include "TestUtil.hpp"
#include "util.hpp"
#include "third_party/catch.hpp"
+using TestUtil::TestContext;
+
TEST_CASE("hash_command_output_simple")
{
char d1[DIGEST_STRING_BUFFER_SIZE];
TEST_CASE("hash_command_output_stdout_versus_stderr")
{
+ TestContext test_context;
+
Context ctx;
char d1[DIGEST_STRING_BUFFER_SIZE];