3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #173702 from bdd/go-checkFlags

go-modules/packages: Run unit tests under subdirs
This commit is contained in:
Jörg Thalheim 2022-06-28 08:30:43 +02:00 committed by GitHub
commit 4f8a04f180
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 95 additions and 19 deletions

View file

@ -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" ];

View file

@ -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";

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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";

View file

@ -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";

View file

@ -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; {

View file

@ -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";