mirror of
https://github.com/NixOS/nix.git
synced 2025-11-16 23:42:43 +01:00
Apply clang-format universally.
* It is tough to contribute to a project that doesn't use a formatter, * It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files * Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose, Let's rip the bandaid off? Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge.
This commit is contained in:
parent
41bf87ec70
commit
e4f62e4608
587 changed files with 23258 additions and 23135 deletions
|
|
@ -12,16 +12,14 @@ using namespace nix;
|
|||
Gen<Hash> Arbitrary<Hash>::arbitrary()
|
||||
{
|
||||
Hash prototype(HashAlgorithm::SHA1);
|
||||
return
|
||||
gen::apply(
|
||||
[](const std::vector<uint8_t> & v) {
|
||||
Hash hash(HashAlgorithm::SHA1);
|
||||
assert(v.size() == hash.hashSize);
|
||||
std::copy(v.begin(), v.end(), hash.hash);
|
||||
return hash;
|
||||
},
|
||||
gen::container<std::vector<uint8_t>>(prototype.hashSize, gen::arbitrary<uint8_t>())
|
||||
);
|
||||
return gen::apply(
|
||||
[](const std::vector<uint8_t> & v) {
|
||||
Hash hash(HashAlgorithm::SHA1);
|
||||
assert(v.size() == hash.hashSize);
|
||||
std::copy(v.begin(), v.end(), hash.hash);
|
||||
return hash;
|
||||
},
|
||||
gen::container<std::vector<uint8_t>>(prototype.hashSize, gen::arbitrary<uint8_t>()));
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace rc
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ namespace nix {
|
|||
* The path to the unit test data directory. See the contributing guide
|
||||
* in the manual for further details.
|
||||
*/
|
||||
static inline std::filesystem::path getUnitTestData() {
|
||||
static inline std::filesystem::path getUnitTestData()
|
||||
{
|
||||
return getEnv("_NIX_TEST_UNIT_DATA").value();
|
||||
}
|
||||
|
||||
|
|
@ -22,7 +23,8 @@ static inline std::filesystem::path getUnitTestData() {
|
|||
* against them. See the contributing guide in the manual for further
|
||||
* details.
|
||||
*/
|
||||
static inline bool testAccept() {
|
||||
static inline bool testAccept()
|
||||
{
|
||||
return getEnv("_NIX_TEST_ACCEPT") == "1";
|
||||
}
|
||||
|
||||
|
|
@ -49,15 +51,9 @@ public:
|
|||
{
|
||||
auto file = goldenMaster(testStem);
|
||||
|
||||
if (testAccept())
|
||||
{
|
||||
GTEST_SKIP()
|
||||
<< "Cannot read golden master "
|
||||
<< file
|
||||
<< "because another test is also updating it";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (testAccept()) {
|
||||
GTEST_SKIP() << "Cannot read golden master " << file << "because another test is also updating it";
|
||||
} else {
|
||||
test(readFile(file));
|
||||
}
|
||||
}
|
||||
|
|
@ -68,23 +64,17 @@ public:
|
|||
* @param test hook that produces contents of the file and does the
|
||||
* actual work
|
||||
*/
|
||||
void writeTest(
|
||||
PathView testStem, auto && test, auto && readFile2, auto && writeFile2)
|
||||
void writeTest(PathView testStem, auto && test, auto && readFile2, auto && writeFile2)
|
||||
{
|
||||
auto file = goldenMaster(testStem);
|
||||
|
||||
auto got = test();
|
||||
|
||||
if (testAccept())
|
||||
{
|
||||
if (testAccept()) {
|
||||
std::filesystem::create_directories(file.parent_path());
|
||||
writeFile2(file, got);
|
||||
GTEST_SKIP()
|
||||
<< "Updating golden master "
|
||||
<< file;
|
||||
}
|
||||
else
|
||||
{
|
||||
GTEST_SKIP() << "Updating golden master " << file;
|
||||
} else {
|
||||
decltype(got) expected = readFile2(file);
|
||||
ASSERT_EQ(got, expected);
|
||||
}
|
||||
|
|
@ -96,14 +86,11 @@ public:
|
|||
void writeTest(PathView testStem, auto && test)
|
||||
{
|
||||
writeTest(
|
||||
testStem, test,
|
||||
[](const std::filesystem::path & f) -> std::string {
|
||||
return readFile(f);
|
||||
},
|
||||
[](const std::filesystem::path & f, const std::string & c) {
|
||||
return writeFile(f, c);
|
||||
});
|
||||
testStem,
|
||||
test,
|
||||
[](const std::filesystem::path & f) -> std::string { return readFile(f); },
|
||||
[](const std::filesystem::path & f, const std::string & c) { return writeFile(f, c); });
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace nix
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ void checkGTestWith(Testable && testable, MakeTestParams makeTestParams)
|
|||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace rc::detail
|
||||
|
||||
#define RC_GTEST_PROP_WITH_PARAMS(TestCase, Name, MakeParams, ArgList) \
|
||||
void rapidCheck_propImpl_##TestCase##_##Name ArgList; \
|
||||
|
|
|
|||
|
|
@ -9,8 +9,9 @@ namespace rc {
|
|||
using namespace nix;
|
||||
|
||||
template<>
|
||||
struct Arbitrary<Hash> {
|
||||
struct Arbitrary<Hash>
|
||||
{
|
||||
static Gen<Hash> arbitrary();
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace rc
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ protected:
|
|||
std::string msg(p, n);
|
||||
throw std::runtime_error(loc(file, line) + ": nix_err_code(ctx) != NIX_OK, message: " + msg);
|
||||
}
|
||||
|
||||
#define assert_ctx_ok() assert_ctx_ok(__FILE__, __LINE__)
|
||||
|
||||
inline void assert_ctx_err(const char * file, int line)
|
||||
|
|
@ -49,7 +50,8 @@ protected:
|
|||
}
|
||||
throw std::runtime_error(loc(file, line) + ": Got NIX_OK, but expected an error!");
|
||||
}
|
||||
|
||||
#define assert_ctx_err() assert_ctx_err(__FILE__, __LINE__)
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace nixC
|
||||
|
|
|
|||
|
|
@ -12,4 +12,4 @@ inline void * observe_string_cb_data(std::string & out)
|
|||
|
||||
#define OBSERVE_STRING(str) nix::testing::observe_string_cb, nix::testing::observe_string_cb_data(str)
|
||||
|
||||
}
|
||||
} // namespace nix::testing
|
||||
|
|
|
|||
|
|
@ -8,4 +8,4 @@ void observe_string_cb(const char * start, unsigned int n, void * user_data)
|
|||
*user_data_casted = std::string(start);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace nix::testing
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue