diff --git a/pkgs/applications/networking/cluster/kompose/default.nix b/pkgs/applications/networking/cluster/kompose/default.nix index 2b80dfc6815a..a4081408871a 100644 --- a/pkgs/applications/networking/cluster/kompose/default.nix +++ b/pkgs/applications/networking/cluster/kompose/default.nix @@ -1,4 +1,4 @@ -{ lib, buildGoModule, fetchFromGitHub, installShellFiles, testers, kompose }: +{ lib, buildGoModule, fetchFromGitHub, installShellFiles, testers, kompose, git }: buildGoModule rec { pname = "kompose"; @@ -13,7 +13,7 @@ buildGoModule rec { vendorSha256 = "sha256-OR5U2PnebO0a+lwU09Dveh0Yxk91cmSRorTxQIO5lHc="; - nativeBuildInputs = [ installShellFiles ]; + nativeBuildInputs = [ installShellFiles git ]; ldflags = [ "-s" "-w" ]; diff --git a/pkgs/applications/version-management/git-and-tools/gitbatch/default.nix b/pkgs/applications/version-management/git-and-tools/gitbatch/default.nix index 75fea7bf871f..0eb20db1462a 100644 --- a/pkgs/applications/version-management/git-and-tools/gitbatch/default.nix +++ b/pkgs/applications/version-management/git-and-tools/gitbatch/default.nix @@ -1,4 +1,4 @@ -{ lib, buildGoModule, fetchFromGitHub }: +{ lib, buildGoModule, fetchFromGitHub, git }: buildGoModule rec { pname = "gitbatch"; @@ -15,7 +15,15 @@ buildGoModule rec { ldflags = [ "-s" "-w" ]; - checkFlags = [ "-short" ]; + nativeBuildInputs = [ + git # required by unit tests + ]; + + preCheck = '' + HOME=$(mktemp -d) + # Disable tests requiring network access to gitlab.com + buildFlagsArray+=("-run" "[^(Test(Run|Start|(Fetch|Pull)With(Go|)Git))]") + ''; meta = with lib; { description = "Running git UI commands"; diff --git a/pkgs/development/go-modules/generic/default.nix b/pkgs/development/go-modules/generic/default.nix index b0c587ea4712..7e9a76dbde6d 100644 --- a/pkgs/development/go-modules/generic/default.nix +++ b/pkgs/development/go-modules/generic/default.nix @@ -178,12 +178,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 @@ -241,7 +251,7 @@ let runHook preCheck for pkg in $(getGoDirs test); do - buildGoDir test $checkFlags "$pkg" + buildGoDir test "$pkg" done runHook postCheck diff --git a/pkgs/development/go-packages/generic/default.nix b/pkgs/development/go-packages/generic/default.nix index 0559f7f07a7c..643c1955d2b0 100644 --- a/pkgs/development/go-packages/generic/default.nix +++ b/pkgs/development/go-packages/generic/default.nix @@ -160,12 +160,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 @@ -225,7 +235,7 @@ let runHook preCheck for pkg in $(getGoDirs test); do - buildGoDir test $checkFlags "$pkg" + buildGoDir test "$pkg" done runHook postCheck diff --git a/pkgs/development/tools/delve/default.nix b/pkgs/development/tools/delve/default.nix index 101449cb8038..27100fe15cc0 100644 --- a/pkgs/development/tools/delve/default.nix +++ b/pkgs/development/tools/delve/default.nix @@ -1,4 +1,4 @@ -{ lib, buildGoModule, fetchFromGitHub, makeWrapper }: +{ lib, buildGoModule, fetchFromGitHub, makeWrapper, stdenv }: buildGoModule rec { pname = "delve"; @@ -17,7 +17,19 @@ buildGoModule rec { nativeBuildInputs = [ makeWrapper ]; - checkFlags = [ "-short" ]; + hardeningDisable = [ "fortify" ]; + + preCheck = '' + XDG_CONFIG_HOME=$(mktemp -d) + ''; + + # Disable tests on Darwin as they require various workarounds. + # + # - Tests requiring local networking fail with or without sandbox, + # even with __darwinAllowLocalNetworking allowed. + # - CGO_FLAGS warnings break tests' expected stdout/stderr outputs. + # - DAP test binaries exit prematurely. + doCheck = !stdenv.isDarwin; postInstall = '' # fortify source breaks build since delve compiles with -O0 diff --git a/pkgs/tools/filesystems/go-mtpfs/default.nix b/pkgs/tools/filesystems/go-mtpfs/default.nix index 4bb2a3c24d5f..260e6891f956 100644 --- a/pkgs/tools/filesystems/go-mtpfs/default.nix +++ b/pkgs/tools/filesystems/go-mtpfs/default.nix @@ -18,7 +18,11 @@ buildGoModule rec { nativeBuildInputs = [ pkg-config ]; buildInputs = [ libusb1 ]; - checkFlags = [ "-short" ]; + preCheck = '' + # Only run tests under mtp/encoding_test.go + # Other tests require an Android deviced attached over USB. + buildFlagsArray+=("-run" "Test(Encode|Decode|Variant).*") + ''; meta = with lib; { description = "A simple FUSE filesystem for mounting Android devices as a MTP device"; diff --git a/pkgs/tools/misc/mmake/default.nix b/pkgs/tools/misc/mmake/default.nix index 2172b8b958c6..b95033bea24b 100644 --- a/pkgs/tools/misc/mmake/default.nix +++ b/pkgs/tools/misc/mmake/default.nix @@ -15,7 +15,8 @@ buildGoModule rec { ldflags = [ "-s" "-w" ]; - checkFlags = [ "-short" ]; + # Almost all tests require non-local networking, trying to resolve githubusercontent.com. + doCheck = false; meta = with lib; { homepage = "https://github.com/tj/mmake"; diff --git a/pkgs/tools/system/skeema/default.nix b/pkgs/tools/system/skeema/default.nix index 56ee0e69aa19..be18340de70b 100644 --- a/pkgs/tools/system/skeema/default.nix +++ b/pkgs/tools/system/skeema/default.nix @@ -1,4 +1,4 @@ -{ lib, buildGoModule, fetchFromGitHub }: +{ lib, buildGoModule, fetchFromGitHub, coreutils }: buildGoModule rec { pname = "skeema"; @@ -17,6 +17,29 @@ buildGoModule rec { ldflags = [ "-s" "-w" ]; + preCheck = '' + # Disable tests requiring network access to gitlab.com + buildFlagsArray+=("-run" "[^(Test(ParseDir(Symlinks|))|DirRelPath)]") + + # Fix tests expecting /usr/bin/printf and /bin/echo + substituteInPlace skeema_cmd_test.go \ + --replace /usr/bin/printf "${coreutils}/bin/printf" + + substituteInPlace internal/fs/dir_test.go \ + --replace /bin/echo "${coreutils}/bin/echo" \ + --replace /usr/bin/printf "${coreutils}/bin/printf" + + substituteInPlace internal/applier/ddlstatement_test.go \ + --replace /bin/echo "${coreutils}/bin/echo" + + substituteInPlace internal/util/shellout_unix_test.go \ + --replace /bin/echo "${coreutils}/bin/echo" \ + --replace /usr/bin/printf "${coreutils}/bin/printf" + + substituteInPlace internal/util/shellout_unix_test.go \ + --replace /bin/echo "${coreutils}/bin/echo" + ''; + checkFlags = [ "-short" ]; meta = with lib; { diff --git a/pkgs/tools/text/gucci/default.nix b/pkgs/tools/text/gucci/default.nix index 3e87b7cb79c1..8d9bd5279af0 100644 --- a/pkgs/tools/text/gucci/default.nix +++ b/pkgs/tools/text/gucci/default.nix @@ -21,6 +21,14 @@ buildGoModule rec { checkFlags = [ "-short" ]; + # Integration tests rely on Ginkgo but fail. + # Related: https://github.com/onsi/ginkgo/issues/602 + # + # Disable integration tests. + preCheck = '' + buildFlagsArray+=("-run" "[^(TestIntegration)]") + ''; + meta = with lib; { description = "A simple CLI templating tool written in golang"; homepage = "https://github.com/noqcks/gucci";