diff options
author | Berk D. Demir <bdd@mindcast.org> | 2022-05-01 23:15:08 +0000 |
---|---|---|
committer | Berk D. Demir <bdd@mindcast.org> | 2022-06-01 00:52:20 +0000 |
commit | 89864413b28a787ee61e46a7ff510587eb041e32 (patch) | |
tree | 31d691cb94707fb9c7c5e23f63276bd4fbcb0c38 /pkgs/development/go-modules | |
parent | 1af612e8559393f4564784d567f9743fdef15797 (diff) | |
download | nixpkgs-89864413b28a787ee61e46a7ff510587eb041e32.tar nixpkgs-89864413b28a787ee61e46a7ff510587eb041e32.tar.gz nixpkgs-89864413b28a787ee61e46a7ff510587eb041e32.tar.bz2 nixpkgs-89864413b28a787ee61e46a7ff510587eb041e32.tar.lz nixpkgs-89864413b28a787ee61e46a7ff510587eb041e32.tar.xz nixpkgs-89864413b28a787ee61e46a7ff510587eb041e32.tar.zst nixpkgs-89864413b28a787ee61e46a7ff510587eb041e32.zip |
go-modules/packages: Run unit tests under subdirs
Bug: Due to the way `buildGoDir` function was repurposed to also run `go test`, if `checkFlags` was defined, `go test` was ran only at the top level directory. Only the first element of `checkFlags` array would get passed to the `go test` command as arguments. Fix: Now the first parameter to `buildGoDir` is handled as the command. If the command is "test" `checkFlags` get passed as arguments along with other build flags like ldflags, tags, etc. Readability: - Iteratively build a flag array in `buildGoDir` instead of single long variable expansion command line. - Bash style: Single line local assignment of positional parameters.
Diffstat (limited to 'pkgs/development/go-modules')
-rw-r--r-- | pkgs/development/go-modules/generic/default.nix | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/pkgs/development/go-modules/generic/default.nix b/pkgs/development/go-modules/generic/default.nix index 4dff2d82848..d0dc55376fa 100644 --- a/pkgs/development/go-modules/generic/default.nix +++ b/pkgs/development/go-modules/generic/default.nix @@ -180,12 +180,22 @@ let exclude+='\)' buildGoDir() { - local d; local cmd; - cmd="$1" - d="$2" + local cmd="$1" dir="$2" + . $TMPDIR/buildFlagsArray + + declare -a flags + flags+=($buildFlags "''${buildFlagsArray[@]}") + flags+=(''${tags:+-tags=${lib.concatStringsSep "," tags}}) + flags+=(''${ldflags:+-ldflags="$ldflags"}) + flags+=("-v" "-p" "$NIX_BUILD_CORES") + + if [ "$cmd" = "test" ]; then + flags+=($checkFlags) + fi + local OUT - if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" ''${tags:+-tags=${lib.concatStringsSep "," tags}} ''${ldflags:+-ldflags="$ldflags"} -v -p $NIX_BUILD_CORES $d 2>&1)"; then + if ! OUT="$(go $cmd "''${flags[@]}" $dir 2>&1)"; then if ! echo "$OUT" | grep -qE '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then echo "$OUT" >&2 return 1 @@ -243,7 +253,7 @@ let runHook preCheck for pkg in $(getGoDirs test); do - buildGoDir test $checkFlags "$pkg" + buildGoDir test "$pkg" done runHook postCheck |