diff options
author | Arnout Engelen <arnout@bzzt.net> | 2021-04-17 19:02:16 +0200 |
---|---|---|
committer | Arnout Engelen <arnout@bzzt.net> | 2021-08-14 09:47:21 +0200 |
commit | d09e0be1c4876fe99340b03e56ebb941f93842c2 (patch) | |
tree | 60e3a3823e6af4a979dc9ca865cdb3e8f8848231 /doc/contributing | |
parent | 28135ad08a5d3b40df1d68a686e8f65a106def3e (diff) |
nixpkgs-docs: when to prefer passthru.tests over installCheckPhase
And mention you can have either lightweight 'package' or more heavyweight 'NixOS' (module) tests. This was suggested at https://github.com/ryantm/nixpkgs-update/issues/260#issuecomment-821287971 and discussed further at https://github.com/NixOS/nixpkgs/pull/119731
Diffstat (limited to 'doc/contributing')
-rw-r--r-- | doc/contributing/coding-conventions.chapter.md | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/doc/contributing/coding-conventions.chapter.md b/doc/contributing/coding-conventions.chapter.md index 7199fc63c8d03..85c8626bd99c4 100644 --- a/doc/contributing/coding-conventions.chapter.md +++ b/doc/contributing/coding-conventions.chapter.md @@ -545,7 +545,26 @@ The following types of tests exists: Here in the nixpkgs manual we describe mostly _package tests_; for _module tests_ head over to the corresponding [section in the NixOS manual](https://nixos.org/manual/nixos/stable/#sec-nixos-tests). -### Writing package tests {#ssec-package-tests-writing} +### Writing inline package tests {#ssec-inline-package-tests-writing} + +For very simple tests, they can be written inline: + +```nix +{ …, yq-go }: + +buildGoModule rec { + … + + passthru.tests = { + simple = runCommand "${pname}-test" {} '' + echo "test: 1" | ${yq-go}/bin/yq eval -j > $out + [ "$(cat $out | tr -d $'\n ')" = '{"test":1}' ] + ''; + }; +} +``` + +### Writing larger package tests {#ssec-package-tests-writing} This is an example using the `phoronix-test-suite` package with the current best practices. |