Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Building and testing Nix:

* Build Nix using `nix build ./packaging/nix-make#release.nix`. The result is in `./result`.

* Run the functional tests in `tests/functional` using `nix build -L ./packaging/nix-make#release.functional-tests`.
* Run all tests using `nix build -L ./packaging/nix-make#release.nix-all-tests`. This covers the unit tests (e.g. `release.nix-util-tests-run`, which runs `src/libutil-tests`) and the functional tests in `tests/functional` (`release.functional-tests`); each can also be built on its own.

* Individual tests can be executed by doing `nix build ./packaging/nix-make#release.nix && nix run ./packaging/nix-make#test-runner -- --nix-bin-dir ./result/bin $TEST_NAMES`, where `TEST_NAMES` are the file names inside `tests/functional` (without the `.sh` suffix), e.g. `simple` or `flakes/relative-paths`.

Expand Down
22 changes: 21 additions & 1 deletion packaging/nix-make/deps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ in
pkgconfig = [ "libeditline" ];
}
{
prefix = "git2/";
# Matches both <git2.h> and <git2/...>.
prefix = "git2";
pkg = deps.libgit2;
pkgconfig = [ "libgit2" ];
}
Expand All @@ -224,4 +225,23 @@ in
];
libs = [ "-lwasmtime" ];
}
# Unit test frameworks.
{
prefix = "gtest/";
pkg = deps.gtest;
pkgconfig = [ "gtest" ];
}
{
prefix = "gmock/";
pkg = deps.gtest;
pkgconfig = [ "gmock" ];
}
{
# Matches both <rapidcheck.h> and <rapidcheck/...>. rapidcheck.pc has
# an empty `Libs:`, so the library is named explicitly.
prefix = "rapidcheck";
pkg = deps.rapidcheck;
pkgconfig = [ "rapidcheck" ];
libs = [ "-lrapidcheck" ];
}
]
38 changes: 38 additions & 0 deletions packaging/nix-make/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,52 @@
nix-cmd = self.callPackage ../../src/libcmd/make.nix { };
nix = self.callPackage ../../src/nix/make.nix { };

# The unit tests: the test executables and derivations running them.
nix-util-c = self.callPackage ../../src/libutil-c/make.nix { };
nix-util-test-support = self.callPackage ../../src/libutil-test-support/make.nix { };
nix-util-tests = self.callPackage ../../src/libutil-tests/make.nix { };
nix-util-tests-run = self.nix-util-tests.tests.run;
nix-util-tests-run-without-new-syscalls = self.nix-util-tests.tests.run-without-new-syscalls;
nix-store-c = self.callPackage ../../src/libstore-c/make.nix { };
nix-store-test-support = self.callPackage ../../src/libstore-test-support/make.nix { };
nix-store-tests = self.callPackage ../../src/libstore-tests/make.nix { };
nix-store-tests-run = self.nix-store-tests.tests.run;
nix-fetchers-c = self.callPackage ../../src/libfetchers-c/make.nix { };
nix-fetchers-tests = self.callPackage ../../src/libfetchers-tests/make.nix { };
nix-fetchers-tests-run = self.nix-fetchers-tests.tests.run;
nix-expr-c = self.callPackage ../../src/libexpr-c/make.nix { };
nix-expr-test-support = self.callPackage ../../src/libexpr-test-support/make.nix { };
nix-expr-tests = self.callPackage ../../src/libexpr-tests/make.nix { };
nix-expr-tests-run = self.nix-expr-tests.tests.run;
nix-flake-c = self.callPackage ../../src/libflake-c/make.nix { };
nix-flake-tests = self.callPackage ../../src/libflake-tests/make.nix { };
nix-flake-tests-run = self.nix-flake-tests.tests.run;

test-runner = self.callPackage ../../tests/functional/test-runner.nix { };
functional-tests = self.callPackage ../../tests/functional/make.nix { };

# Everything that runs tests; building it runs them all.
nix-all-tests = pkgs.linkFarmFromDrvs "nix-all-tests" [
self.nix-util-tests-run
self.nix-util-tests-run-without-new-syscalls
self.nix-store-tests-run
self.nix-fetchers-tests-run
self.nix-expr-tests-run
self.nix-flake-tests-run
self.functional-tests
];
});
in
rec {
packages.${system} = {
inherit (make.${system}.release) test-runner;
};

# `nix flake check` runs all tests against the release variant.
checks.${system} = {
inherit (make.${system}.release) nix-all-tests;
};

devShells.${system}.default = pkgs.mkShell {
packages = [ make.${system}.release.test-runner ];
};
Expand Down Expand Up @@ -100,6 +137,7 @@
inherit (flake-schemas.schemas)
schemas
packages
checks
devShells
;

Expand Down
21 changes: 21 additions & 0 deletions packaging/nix-make/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,26 @@ let
}
);

# A derivation that runs a test program (e.g. a gtest executable) with
# `env` added to the environment, and succeeds if it does. Its output is
# empty; the program's output is in the build log. `HOME` is a writable
# directory, which the values in `env` may refer to as `$HOME`.
runTest =
{
name,
command,
env ? { },
nativeBuildInputs ? [ ],
}:
mkPythonDerivation {
inherit
name
command
env
nativeBuildInputs
;
} ./run-test.py;

# The stdenv's default hardening flags, except that `_FORTIFY_SOURCE`
# warns on every unit when not optimizing, so it is disabled then (like
# `hardeningDisable = [ "fortify" ]` in `stdenv.mkDerivation`).
Expand Down Expand Up @@ -493,6 +513,7 @@ in
weakVtablesFlags
mkStringHeader
mkComponent
runTest
commonSupportFiles
;
}
26 changes: 26 additions & 0 deletions packaging/nix-make/run-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# The builder for running a test program (see `runTest` in lib.nix). It
# runs `command` with `env` added to the environment; the output of the
# program goes to the build log.

import json
import os
import subprocess


def main():
with open(os.environ["NIX_ATTRS_JSON_FILE"]) as f:
attrs = json.load(f)

# A writable home directory, for tests that keep state (e.g. a store)
# there. The values in `env` may refer to it as `$HOME`.
os.environ["HOME"] = os.path.join(os.environ["TMPDIR"], "home")
os.mkdir(os.environ["HOME"])
env = dict(os.environ)
for name, value in attrs["env"].items():
env[name] = os.path.expandvars(value)

subprocess.run(attrs["command"], env=env, check=True)
os.mkdir(os.environ["out"])


main()
34 changes: 34 additions & 0 deletions src/libexpr-c/make.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# libnixexprc, the C API of libnixexpr, transcribed from meson.build.
{
nixMake,
nix-util,
nix-util-c,
nix-store,
nix-store-c,
nix-expr,
}:

nixMake.mkComponent {
name = "determinate-nix-expr-c";
libName = "nixexprc";

deps = [
nix-util
nix-util-c
nix-store
nix-store-c
nix-expr
];

root = ./.;

includeDirs = [ "" ];
# The headers live in the root, which the default would not export.
publicIncludeDirs = [ "" ];

files = nixMake.commonSupportFiles;

extraCxxFlags = nixMake.weakVtablesFlags;

linkFlags = [ "-Wl,--wrap=__assert_fail" ];
}
33 changes: 33 additions & 0 deletions src/libexpr-test-support/make.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# libnix-expr-test-support, helpers for the unit tests of libnixexpr and
# the components built on it, transcribed from meson.build.
{
nixMake,
nix-util,
nix-util-test-support,
nix-store,
nix-store-test-support,
nix-expr,
nix-expr-c,
}:

nixMake.mkComponent {
name = "determinate-nix-expr-test-support";
libName = "nix-expr-test-support";

deps = [
nix-util
nix-util-test-support
nix-store
nix-store-test-support
nix-expr
nix-expr-c
];

root = ./.;

includeDirs = [ "include" ];

files = nixMake.commonSupportFiles;

linkFlags = [ "-Wl,--wrap=__assert_fail" ];
}
60 changes: 60 additions & 0 deletions src/libexpr-tests/make.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# The unit tests of libnixexpr, transcribed from meson.build and
# package.nix: the `nix-expr-tests` executable, with the derivation that
# runs it as `tests.run`.
{
pkgs,
nixMake,
nix-expr,
nix-expr-c,
nix-expr-test-support,
}:

let
inherit (pkgs) lib;

tests = nixMake.mkComponent {
name = "determinate-nix-expr-tests";
type = "executable";
exeName = "nix-expr-tests";

deps = [
nix-expr
nix-expr-c
nix-expr-test-support
];

root = ./.;

# The benchmarks (Meson option `benchmarks`, off by default).
excludeSources = [
"bench-main.cc"
"dynamic-attrs-bench.cc"
"get-drvs-bench.cc"
"regex-cache-bench.cc"
];

includeDirs = [ "" ];

files = nixMake.commonSupportFiles;

configHeaders = {
"expr-tests-config.hh" = {
PACKAGE_VERSION = lib.fileContents ../../.version;
};
};

linkFlags = [ "-Wl,--wrap=__assert_fail" ];
};
in

tests
// {
tests.run = nixMake.runTest {
name = "${tests.name}-run";
command = [ "${tests}/bin/${tests.exeName}" ];
env = {
_NIX_TEST_UNIT_DATA = ./data;
NIX_STORE = "";
};
};
}
32 changes: 32 additions & 0 deletions src/libfetchers-c/make.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# libnixfetchersc, the C API of libnixfetchers, transcribed from meson.build.
{
nixMake,
nix-util,
nix-util-c,
nix-store,
nix-store-c,
nix-fetchers,
}:

nixMake.mkComponent {
name = "determinate-nix-fetchers-c";
libName = "nixfetchersc";

deps = [
nix-util
nix-util-c
nix-store
nix-store-c
nix-fetchers
];

root = ./.;

includeDirs = [ "" ];
# The headers live in the root, which the default would not export.
publicIncludeDirs = [ "" ];

files = nixMake.commonSupportFiles;

linkFlags = [ "-Wl,--wrap=__assert_fail" ];
}
47 changes: 47 additions & 0 deletions src/libfetchers-tests/make.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# The unit tests of libnixfetchers, transcribed from meson.build and
# package.nix: the `nix-fetchers-tests` executable, with the derivation
# that runs it as `tests.run`.
{
nixMake,
nix-store-test-support,
nix-fetchers,
nix-fetchers-c,
}:

let
tests = nixMake.mkComponent {
name = "determinate-nix-fetchers-tests";
type = "executable";
exeName = "nix-fetchers-tests";

deps = [
nix-store-test-support
nix-fetchers
nix-fetchers-c
];

root = ./.;

includeDirs = [ "" ];

files = nixMake.commonSupportFiles;

# The tests have no main() of their own; it comes from gtest_main
# (see src/libutil-tests/make.nix).
extraLinkLibs = [ "-lgtest_main" ];

linkFlags = [ "-Wl,--wrap=__assert_fail" ];
};
in

tests
// {
tests.run = nixMake.runTest {
name = "${tests.name}-run";
command = [ "${tests}/bin/${tests.exeName}" ];
env = {
_NIX_TEST_UNIT_DATA = ./data;
NIX_STORE = "";
};
};
}
Loading
Loading