Commit Graph

52 Commits

Author SHA1 Message Date
Robert Hensing
43908e0d12 testers.modularServiceCompliance: init
Portable test suite for modular services, designed to be usable with
other service managers and use cases, inside Nixpkgs and externally.

Like modular services itself, it's still quite bare-bones. New
features can crystallize around this kind of infrastructure.

Assisted-By: Claude Opus 4.7/4.8 era Claude models
2026-06-26 14:25:32 +02:00
Yueh-Shun Li
1548251cfa testers.invalidateFetcherByDrvHash: take fixed-point arguments args 2025-12-19 22:44:22 +08:00
Yueh-Shun Li
7ba63c64a6 testers.invalidateFetcherByDrvHash: use overrideAttrs if fetcher ignore name arguments 2025-12-19 22:44:21 +08:00
Yueh-Shun Li
cb39a53e9f testers.invalidateFetcherByDrvHash: salt pname if presented 2025-12-19 22:44:21 +08:00
Matt Sturgeon
237b3cb5ce testers.testEqualContents: add checkMetadata option
Allows ignoring file metadata differences (permissions, ownership)
when comparing files.

This is especially useful on darwin, where we often run into subtle
issues like:

    -Device: 1,23 Access: (0444/-r--r--r--) Uid: ( 0/ root) Gid: ( 0/ wheel)
    +Device: 1,23 Access: (0444/-r--r--r--) Uid: ( 0/ root) Gid: ( 350/ nixbld)
2025-10-17 16:18:56 +01:00
NAHO
c8d4dabc43 pkgs: remove optional builtins prefixes from prelude functions
Remove optional builtins prefixes from prelude functions by running:

    builtins=(
      abort
      baseNameOf
      break
      derivation
      derivationStrict
      dirOf
      false
      fetchGit
      fetchMercurial
      fetchTarball
      fetchTree
      fromTOML
      import
      isNull
      map
      null
      placeholder
      removeAttrs
      scopedImport
      throw
      toString
      true
    )

    fd \
      --type file \
      . \
      pkgs \
      --exec-batch sed --in-place --regexp-extended "
        s/\<builtins\.($(
          printf '%s\n' "${builtins[@]}" |
            paste --delimiter '|' --serial -
        ))\>/\1/g
      "

    nix fmt
2025-10-04 19:02:37 +02:00
Robert Hensing
8d128a4138 testers.testEqualContents: add postFailureMessage parameter
Add an optional postFailureMessage parameter to testEqualContents that allows
users to provide additional context when tests fail. This is particularly useful
for providing instructions on how to update expected results when they change
intentionally.

The message is displayed after the standard failure output, helping maintainers
understand what to do next when a test fails.
2025-08-24 20:09:54 +02:00
Wolfgang Walther
5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
qbisi
11291afcb3 testers.hasCmakeConfigModules: init 2025-05-31 04:24:52 +08:00
Silvan Mosberger
374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
Philip Taron
cb26667f94 testers.shfmt: init (#385939) 2025-03-07 15:45:30 -08:00
Connor Baker
6f52f21ad2 testers.shfmt: init 2025-03-05 12:40:58 -08:00
Connor Baker
12ffaa4e85 testers.testEqualArrayOrMap: switch to callPackage 2025-03-03 16:30:15 +00:00
Connor Baker
4e6be8f313 testers.testEqualArrayOrMap: use default.nix and move recurseIntoAttrs into tests.nix 2025-03-03 16:30:15 +00:00
Connor Baker
731b74db8b testers.testEqualArrayOrMap: use buildCommandPath and change checkSetupScript argument to script 2025-03-03 16:29:40 +00:00
Connor Baker
261693fe5d testers.testEqualArrayOrMap: init 2025-03-03 16:29:11 +00:00
Connor Baker
d2a0e52d09 testers.testBuildFailure': replace import with callPackage 2025-02-27 17:55:13 +00:00
Connor Baker
25833baaa4 testers.testBuildFailure': use default.nix and move recurseIntoAttrs into tests.nix 2025-02-27 15:56:46 +00:00
Connor Baker
95c8770fa2 testers.testBuildFailure': move to separate directory and use buildCommandPath 2025-02-27 15:56:46 +00:00
Connor Baker
2ac21a1375 testers.testBuildFailure': use more strict bash for checks 2025-02-27 15:56:46 +00:00
Connor Baker
38745b132d testers.testBuildFailure': init 2025-02-27 15:56:45 +00:00
Wolfgang Walther
4c5458df2c testers.testBuildFailure: fix
Introduced by cf127c9dc3, which changed
default-builder.sh, but forgot to tell testBuildFailure about it.
2025-01-21 17:36:42 +01:00
Matt Sturgeon
40a6c466fc testers.testBuildFailure: fix structuredAttrs support
Fixes `testers.testBuildFailure` compatibility with `__structuredAttrs`.

The two main issues are, when `structuredAttrs` is enabled:
- `$__structuredAttrs` is not set
- `$outputs` is not set

`$__structuredAttrs` not being set is fixed by checking for
`$NIX_ATTRS_SH_FILE`, as per pkgs/stdenv/generic/setup.sh

`$outputs` not being set is fixed by sourcing `$NIX_ATTRS_SH_FILE`,
as-per pkgs/stdenv/generic/default-builder.sh
2025-01-08 19:19:52 +00:00
Wolfgang Walther
4423b0746c various: replace substituteAll with replaceVars
This deals with some special cases, i.e. where "null" is used to avoid
replacing some values or where the syntax is not too easy to grep for
for automated replacement.
2024-12-01 14:56:12 +01:00
Philip Taron
bc0fb46cd2 Merge pull request #334995 from pbsds/fix-test-version-1723771306 2024-08-17 07:53:03 -07:00
Peder Bergebakken Sundt
ecb342fd4e testers.testVersion: ignore echoed store paths
Fixes the error mode where the test always passes if the store path of the binary is echoed by the test command.
2024-08-16 20:16:44 +02:00
nicoo
18dd486bb9 emptyFile: use SRI hash 2024-08-08 20:06:21 +00:00
nicoo
d0a96c6eda testers.runCommand: add, document, and test 2024-08-08 15:29:14 +00:00
nicoo
906598c914 testers: format inputs per RFC166 2024-08-08 13:26:37 +00:00
Robert Hensing
4ca52fdf5f Merge pull request #323613 from CyberShadow/fix-nix-path-without-channels-v2
nix-channel: do not set empty nix-path when disabling channels
2024-07-28 13:31:10 +02:00
Ivan Trubach
fc5c829532 testers.testEqualContents: use diffoscope instead of diffing find output
Before this change, testers.testEqualContents implementation had several
bugs (e.g. executables at different paths were not considered equal). So
we switch to diffoscope that that is designed to handle exactly these
kinds of comparisons and gives more insights into the differences in the
output.
2024-07-18 19:33:44 +03:00
Ivan Trubach
c2e1be3be0 doc: fixup doc/build-helpers references 2024-07-18 14:15:53 +03:00
Robert Hensing
3fb14db08a testers.shellcheck: init
Needed for testing upcoming commit.
2024-07-16 20:10:02 +02:00
Robert Hensing
e0c43a96d2 testers.lycheeLinkCheck: init (#298665)
* testers.lycheeLinkCheck: init

Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2024-05-27 01:14:19 +02:00
Gabriella Gonzalez
b8698cd8d6 macOS support for NixOS tests (#282401)
Closes #193336
Closes #261694
Related to #108984

The goal here was to get the following flake to build and run on
`aarch64-darwin`:

```nix
{ inputs.nixpkgs.url = <this branch>;

  outputs = { nixpkgs, ... }: {
    checks.aarch64-darwin.default =
      nixpkgs.legacyPackages.aarch64-darwin.nixosTest {
        name = "test";

        nodes.machine = { };

        testScript = "";
      };
  };
}
```

… and after this change it does.  There's no longer a need for the
user to set `nodes.*.nixpkgs.pkgs` or
`nodes.*.virtualisation.host.pkgs` as the correct values are inferred
from the host system.
2024-03-02 06:33:14 +01:00
Johann Wagner
da073295d0 testers.testVersion: Fix usage of hyphens within the version argument 2023-09-12 21:54:10 +02:00
sternenseemann
af60e68744 testers.hasPkgConfigModules: allow checking multiple pkg-config mods
This is very useful in conjunction with meta.pkgConfigModules, as the
new tester can use the list provided by this meta attribute as a default
value for moduleNames, making its usage in passthru.tests very
convenient.

For backwards compatibility, a shim under the old name is maintained
with a warning.
2023-08-08 19:16:48 +02:00
Arthur Gautier
562f879cd1 runNixOSTest: adds support for lib.extend
When lib overrides were used, before this commit, they would not be made
available in the configuration evaluation of nixosTest's nodes.

Sample code:
``` nix
let
  pkgs = import ./. {
    overlays = [
      (new: old: {
        lib = old.lib.extend (self: super: {
          sorry_dave = builtins.trace "There are no pod bay doors" "sorry dave";
        });
      })
    ];
  };
in
pkgs.testers.runNixOSTest {
  name = "demo lib overlay";

  nodes = {
    machine = { lib, ... }: {
      environment.etc."got-lib-overlay".text = lib.sorry_dave;
    };
  };

  testScript = { nodes }:
    ''
      start_all()
      machine.succeed('grep dave /etc/got-lib-overlay')
    '';
}
```
2023-06-29 09:13:44 -07:00
Robert Hensing
ac1134f321 testers.runNixOSTest: init
An up to date alternative to pkgs.nixosTest
2023-05-11 19:12:07 +02:00
John Ericson
6e4a1b18d9 meta.pkgConfigModules: Init convention
See docs.

Follow-up work:

- Existing packages should be converted

- `defaultPkgConfigPackages` should assert on `meta.pkgConfigModules`
  and let `tests.pkg-config` alone test the build results.

CC @sternenseemann

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-02-03 09:37:31 -05:00
Robert Hensing
b6bec17eb9 testers.hasPkgConfigModule: Extract and add tests, docs 2023-01-30 00:35:34 +01:00
Robert Hensing
3cf3fef372 testers: Add missing doc link comments 2022-10-27 14:06:39 +02:00
Robert Hensing
e20a362908 testers.testEqualContents: init 2022-10-27 14:06:38 +02:00
Robert Hensing
44d0f37833 testers.testBuildFailure: init 2022-10-27 14:06:38 +02:00
Robert Hensing
aed1deab05 nixos/testing: Fix release.nix tests evaluation
Fixes the problem introduced by 12b3066aae
which caused nixos/release.nix to return the wrong attributes, while
intending to only affect nixos/lib's runTest.
This also removes callTest from the test options, because callTest is
only ever invoked by all-tests.nix.
2022-09-29 10:49:09 +02:00
Artturin
a23fbeb6e8 testers.testVersion: if grep failed then print the output of the command 2022-05-16 16:16:35 +03:00
Robert Hensing
7edb414660 testers.nixosTest: Move from top-level and improve docs 2022-05-05 12:48:47 +02:00
Robert Hensing
c071530ca5 testers.invalidateFetcherByDrvHash: Move from top-level 2022-05-05 12:08:50 +02:00
Artturin
41808d42d2 doc: move testers to their own chapter 2022-04-22 16:24:29 +03:00
Artturin
3cc2e86bab testers: convert to a format that is kind of compatible with nixdoc
Examples: support has to be added to https://github.com/nix-community/nixdoc

'nixdoc --category testers --description "nixpkgs testers" --file ./pkgs/build-support/testers/default.nix'
2022-04-22 16:24:29 +03:00