Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
characterization.hh
Go to the documentation of this file.
1
#pragma once
3
4
#include <gtest/gtest.h>
5
6
#include "
nix/util/types.hh
"
7
#include "
nix/util/file-system.hh
"
8
#include "
nix/util/tests/test-data.hh
"
9
10
namespace
nix {
11
17
static
inline
bool
testAccept()
18
{
19
return
getEnv(
"_NIX_TEST_ACCEPT"
) ==
"1"
;
20
}
21
25
struct
CharacterizationTest
:
virtual
::testing::Test
26
{
31
virtual
std::filesystem::path
goldenMaster
(std::string_view testStem)
const
= 0;
32
39
void
readTest
(std::string_view testStem,
auto
&& test)
40
{
41
auto
file =
goldenMaster
(testStem);
42
43
if
(testAccept()) {
44
GTEST_SKIP() <<
"Cannot read golden master "
<< file <<
"because another test is also updating it"
;
45
}
else
{
46
test(readFile(file));
47
}
48
}
49
56
void
writeTest
(std::string_view testStem,
auto
&& test,
auto
&& readFile2,
auto
&& writeFile2)
57
{
58
auto
file =
goldenMaster
(testStem);
59
60
auto
got = test();
61
62
if
(testAccept()) {
63
createDirs(file.parent_path());
64
writeFile2(file, got);
65
GTEST_SKIP() <<
"Updating golden master "
<< file;
66
}
else
{
67
decltype
(got) expected = readFile2(file);
68
ASSERT_EQ(got, expected);
69
}
70
}
71
75
void
writeTest
(std::string_view testStem,
auto
&& test)
76
{
77
writeTest
(
78
testStem,
79
test,
80
[](
const
std::filesystem::path & f) -> std::string {
return
readFile(f); },
81
[](
const
std::filesystem::path & f,
const
std::string & c) {
return
writeFile(f, c); });
82
}
83
};
84
85
}
// namespace nix
file-system.hh
Utilities for working with the file system and file paths.
nix::CharacterizationTest
Definition
characterization.hh:26
nix::CharacterizationTest::readTest
void readTest(std::string_view testStem, auto &&test)
Definition
characterization.hh:39
nix::CharacterizationTest::writeTest
void writeTest(std::string_view testStem, auto &&test)
Definition
characterization.hh:75
nix::CharacterizationTest::writeTest
void writeTest(std::string_view testStem, auto &&test, auto &&readFile2, auto &&writeFile2)
Definition
characterization.hh:56
nix::CharacterizationTest::goldenMaster
virtual std::filesystem::path goldenMaster(std::string_view testStem) const =0
test-data.hh
types.hh
libutil-test-support
include
nix
util
tests
characterization.hh
Generated by
1.18.0