Merge "Don't run libstore unit tests in project root" into main

This commit is contained in:
Rebecca Turner 2024-04-08 22:08:34 +00:00 committed by Gerrit Code Review
commit 5ec256625e
5 changed files with 29 additions and 4 deletions

View file

@ -0,0 +1,25 @@
#pragma once
#include "util.hh"
#include "types.hh"
namespace nix {
// TODO: These helpers should be available in all unit tests.
/**
* The path to the unit test data directory. See the contributing guide
* in the manual for further details.
*/
static Path getUnitTestData() {
return getEnv("_NIX_TEST_UNIT_DATA").value();
}
/**
* Resolve a path under the unit test data directory to an absolute path.
*/
static Path getUnitTestDataPath(std::string_view path) {
return absPath(getUnitTestData() + "/" + path);
}
}

View file

@ -1,5 +1,6 @@
#include "machines.hh" #include "machines.hh"
#include "globals.hh" #include "globals.hh"
#include "tests/test-data.hh"
#include <gmock/gmock-matchers.h> #include <gmock/gmock-matchers.h>
@ -17,7 +18,6 @@ using nix::getMachines;
using nix::Machine; using nix::Machine;
using nix::Machines; using nix::Machines;
using nix::pathExists; using nix::pathExists;
using nix::Settings;
using nix::settings; using nix::settings;
class Environment : public ::testing::Environment { class Environment : public ::testing::Environment {
@ -138,7 +138,7 @@ TEST(machines, getMachinesWithIncorrectFormat) {
} }
TEST(machines, getMachinesWithCorrectFileReference) { TEST(machines, getMachinesWithCorrectFileReference) {
auto path = absPath("tests/unit/libstore/test-data/machines.valid"); auto path = nix::getUnitTestDataPath("machines.valid");
ASSERT_TRUE(pathExists(path)); ASSERT_TRUE(pathExists(path));
settings.builders = std::string("@") + path; settings.builders = std::string("@") + path;
@ -165,6 +165,6 @@ TEST(machines, getMachinesWithIncorrectFileReference) {
} }
TEST(machines, getMachinesWithCorrectFileReferenceToIncorrectFile) { TEST(machines, getMachinesWithCorrectFileReferenceToIncorrectFile) {
settings.builders = std::string("@") + absPath("tests/unit/libstore/test-data/machines.bad_format"); settings.builders = std::string("@") + nix::getUnitTestDataPath("machines.bad_format");
EXPECT_THROW(getMachines(), FormatError); EXPECT_THROW(getMachines(), FormatError);
} }

View file

@ -85,6 +85,7 @@ libstore_test_support_sources = files(
'libstore-support/tests/derived-path.cc', 'libstore-support/tests/derived-path.cc',
'libstore-support/tests/outputs-spec.cc', 'libstore-support/tests/outputs-spec.cc',
'libstore-support/tests/path.cc', 'libstore-support/tests/path.cc',
'libstore-support/tests/test-data.hh',
) )
libstore_test_support = library( libstore_test_support = library(
@ -142,7 +143,6 @@ test(
'_NIX_TEST_UNIT_DATA': meson.project_source_root() / 'tests/unit/libstore/data', '_NIX_TEST_UNIT_DATA': meson.project_source_root() / 'tests/unit/libstore/data',
}, },
suite : 'check', suite : 'check',
workdir : meson.project_source_root(),
protocol : 'gtest', protocol : 'gtest',
verbose : true, verbose : true,
) )