Merge pull request #173702 from bdd/go-checkFlags

go-modules/packages: Run unit tests under subdirs

authored by Jörg Thalheim and committed by GitHub 4f8a04f1 54ae4bde

+95 -19
+2 -2
pkgs/applications/networking/cluster/kompose/default.nix
··· 1 - { lib, buildGoModule, fetchFromGitHub, installShellFiles, testers, kompose }: 1 + { lib, buildGoModule, fetchFromGitHub, installShellFiles, testers, kompose, git }: 2 2 3 3 buildGoModule rec { 4 4 pname = "kompose"; ··· 13 13 14 14 vendorSha256 = "sha256-OR5U2PnebO0a+lwU09Dveh0Yxk91cmSRorTxQIO5lHc="; 15 15 16 - nativeBuildInputs = [ installShellFiles ]; 16 + nativeBuildInputs = [ installShellFiles git ]; 17 17 18 18 ldflags = [ "-s" "-w" ]; 19 19
+10 -2
pkgs/applications/version-management/git-and-tools/gitbatch/default.nix
··· 1 - { lib, buildGoModule, fetchFromGitHub }: 1 + { lib, buildGoModule, fetchFromGitHub, git }: 2 2 3 3 buildGoModule rec { 4 4 pname = "gitbatch"; ··· 15 15 16 16 ldflags = [ "-s" "-w" ]; 17 17 18 - checkFlags = [ "-short" ]; 18 + nativeBuildInputs = [ 19 + git # required by unit tests 20 + ]; 21 + 22 + preCheck = '' 23 + HOME=$(mktemp -d) 24 + # Disable tests requiring network access to gitlab.com 25 + buildFlagsArray+=("-run" "[^(Test(Run|Start|(Fetch|Pull)With(Go|)Git))]") 26 + ''; 19 27 20 28 meta = with lib; { 21 29 description = "Running git UI commands";
+15 -5
pkgs/development/go-modules/generic/default.nix
··· 178 178 exclude+='\)' 179 179 180 180 buildGoDir() { 181 - local d; local cmd; 182 - cmd="$1" 183 - d="$2" 181 + local cmd="$1" dir="$2" 182 + 184 183 . $TMPDIR/buildFlagsArray 184 + 185 + declare -a flags 186 + flags+=($buildFlags "''${buildFlagsArray[@]}") 187 + flags+=(''${tags:+-tags=${lib.concatStringsSep "," tags}}) 188 + flags+=(''${ldflags:+-ldflags="$ldflags"}) 189 + flags+=("-v" "-p" "$NIX_BUILD_CORES") 190 + 191 + if [ "$cmd" = "test" ]; then 192 + flags+=($checkFlags) 193 + fi 194 + 185 195 local OUT 186 - if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" ''${tags:+-tags=${lib.concatStringsSep "," tags}} ''${ldflags:+-ldflags="$ldflags"} -v -p $NIX_BUILD_CORES $d 2>&1)"; then 196 + if ! OUT="$(go $cmd "''${flags[@]}" $dir 2>&1)"; then 187 197 if ! echo "$OUT" | grep -qE '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then 188 198 echo "$OUT" >&2 189 199 return 1 ··· 241 251 runHook preCheck 242 252 243 253 for pkg in $(getGoDirs test); do 244 - buildGoDir test $checkFlags "$pkg" 254 + buildGoDir test "$pkg" 245 255 done 246 256 247 257 runHook postCheck
+15 -5
pkgs/development/go-packages/generic/default.nix
··· 160 160 exclude+='\)' 161 161 162 162 buildGoDir() { 163 - local d; local cmd; 164 - cmd="$1" 165 - d="$2" 163 + local cmd="$1" dir="$2" 164 + 166 165 . $TMPDIR/buildFlagsArray 166 + 167 + declare -a flags 168 + flags+=($buildFlags "''${buildFlagsArray[@]}") 169 + flags+=(''${tags:+-tags=${lib.concatStringsSep "," tags}}) 170 + flags+=(''${ldflags:+-ldflags="$ldflags"}) 171 + flags+=("-v" "-p" "$NIX_BUILD_CORES") 172 + 173 + if [ "$cmd" = "test" ]; then 174 + flags+=($checkFlags) 175 + fi 176 + 167 177 local OUT 168 - if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" ''${tags:+-tags=${lib.concatStringsSep "," tags}} ''${ldflags:+-ldflags="$ldflags"} -v -p $NIX_BUILD_CORES $d 2>&1)"; then 178 + if ! OUT="$(go $cmd "''${flags[@]}" $dir 2>&1)"; then 169 179 if ! echo "$OUT" | grep -qE '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then 170 180 echo "$OUT" >&2 171 181 return 1 ··· 225 235 runHook preCheck 226 236 227 237 for pkg in $(getGoDirs test); do 228 - buildGoDir test $checkFlags "$pkg" 238 + buildGoDir test "$pkg" 229 239 done 230 240 231 241 runHook postCheck
+14 -2
pkgs/development/tools/delve/default.nix
··· 1 - { lib, buildGoModule, fetchFromGitHub, makeWrapper }: 1 + { lib, buildGoModule, fetchFromGitHub, makeWrapper, stdenv }: 2 2 3 3 buildGoModule rec { 4 4 pname = "delve"; ··· 17 17 18 18 nativeBuildInputs = [ makeWrapper ]; 19 19 20 - checkFlags = [ "-short" ]; 20 + hardeningDisable = [ "fortify" ]; 21 + 22 + preCheck = '' 23 + XDG_CONFIG_HOME=$(mktemp -d) 24 + ''; 25 + 26 + # Disable tests on Darwin as they require various workarounds. 27 + # 28 + # - Tests requiring local networking fail with or without sandbox, 29 + # even with __darwinAllowLocalNetworking allowed. 30 + # - CGO_FLAGS warnings break tests' expected stdout/stderr outputs. 31 + # - DAP test binaries exit prematurely. 32 + doCheck = !stdenv.isDarwin; 21 33 22 34 postInstall = '' 23 35 # fortify source breaks build since delve compiles with -O0
+5 -1
pkgs/tools/filesystems/go-mtpfs/default.nix
··· 18 18 nativeBuildInputs = [ pkg-config ]; 19 19 buildInputs = [ libusb1 ]; 20 20 21 - checkFlags = [ "-short" ]; 21 + preCheck = '' 22 + # Only run tests under mtp/encoding_test.go 23 + # Other tests require an Android deviced attached over USB. 24 + buildFlagsArray+=("-run" "Test(Encode|Decode|Variant).*") 25 + ''; 22 26 23 27 meta = with lib; { 24 28 description = "A simple FUSE filesystem for mounting Android devices as a MTP device";
+2 -1
pkgs/tools/misc/mmake/default.nix
··· 15 15 16 16 ldflags = [ "-s" "-w" ]; 17 17 18 - checkFlags = [ "-short" ]; 18 + # Almost all tests require non-local networking, trying to resolve githubusercontent.com. 19 + doCheck = false; 19 20 20 21 meta = with lib; { 21 22 homepage = "https://github.com/tj/mmake";
+24 -1
pkgs/tools/system/skeema/default.nix
··· 1 - { lib, buildGoModule, fetchFromGitHub }: 1 + { lib, buildGoModule, fetchFromGitHub, coreutils }: 2 2 3 3 buildGoModule rec { 4 4 pname = "skeema"; ··· 16 16 CGO_ENABLED = 0; 17 17 18 18 ldflags = [ "-s" "-w" ]; 19 + 20 + preCheck = '' 21 + # Disable tests requiring network access to gitlab.com 22 + buildFlagsArray+=("-run" "[^(Test(ParseDir(Symlinks|))|DirRelPath)]") 23 + 24 + # Fix tests expecting /usr/bin/printf and /bin/echo 25 + substituteInPlace skeema_cmd_test.go \ 26 + --replace /usr/bin/printf "${coreutils}/bin/printf" 27 + 28 + substituteInPlace internal/fs/dir_test.go \ 29 + --replace /bin/echo "${coreutils}/bin/echo" \ 30 + --replace /usr/bin/printf "${coreutils}/bin/printf" 31 + 32 + substituteInPlace internal/applier/ddlstatement_test.go \ 33 + --replace /bin/echo "${coreutils}/bin/echo" 34 + 35 + substituteInPlace internal/util/shellout_unix_test.go \ 36 + --replace /bin/echo "${coreutils}/bin/echo" \ 37 + --replace /usr/bin/printf "${coreutils}/bin/printf" 38 + 39 + substituteInPlace internal/util/shellout_unix_test.go \ 40 + --replace /bin/echo "${coreutils}/bin/echo" 41 + ''; 19 42 20 43 checkFlags = [ "-short" ]; 21 44
+8
pkgs/tools/text/gucci/default.nix
··· 21 21 22 22 checkFlags = [ "-short" ]; 23 23 24 + # Integration tests rely on Ginkgo but fail. 25 + # Related: https://github.com/onsi/ginkgo/issues/602 26 + # 27 + # Disable integration tests. 28 + preCheck = '' 29 + buildFlagsArray+=("-run" "[^(TestIntegration)]") 30 + ''; 31 + 24 32 meta = with lib; { 25 33 description = "A simple CLI templating tool written in golang"; 26 34 homepage = "https://github.com/noqcks/gucci";