From 8a22d640a736036dc7eb9b7c8b62885d2c82cdb2 Mon Sep 17 00:00:00 2001 From: Piotr Tabor Date: Mon, 18 Apr 2022 20:05:17 +0200 Subject: [PATCH] add OUTPUT_FILE='foo.log' env variable support to test.sh script. Side consequence of this is that `make test-smoke` can become interactive again. --- Makefile | 8 ++++---- scripts/test.sh | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 798bf3e52..850a59c16 100644 --- a/Makefile +++ b/Makefile @@ -96,16 +96,16 @@ pull-docker-test: test: $(info TEST_OPTS: $(TEST_OPTS)) $(info log-file: test-$(TEST_SUFFIX).log) - $(TEST_OPTS) ./scripts/test.sh > test-$(TEST_SUFFIX).log 2>&1 || (cat test-$(TEST_SUFFIX).log && exit 1) + $(TEST_OPTS) OUTPUT_FILE="test-$(TEST_SUFFIX).log" ./scripts/test.sh ! egrep "(--- FAIL:|FAIL:|DATA RACE|panic: test timed out|appears to have leaked)" -B50 -A10 test-$(TEST_SUFFIX).log test-smoke: $(info log-file: test-$(TEST_SUFFIX).log) - PASSES="fmt build unit" ./scripts/test.sh > test-$(TEST_SUFFIX).log 2>&1 || (cat test-$(TEST_SUFFIX).log && exit 1) + PASSES="fmt build unit" OUTPUT_FILE="test-$(TEST_SUFFIX).log" ./scripts/test.sh test-full: $(info log-file: test-$(TEST_SUFFIX).log) - PASSES="fmt build release unit integration functional e2e grpcproxy" ./scripts/test.sh > test-$(TEST_SUFFIX).log 2>&1 || (cat test-$(TEST_SUFFIX).log && exit 1) + PASSES="fmt build release unit integration functional e2e grpcproxy" OUTPUT_FILE="test-$(TEST_SUFFIX).log" ./scripts/test.sh ensure-docker-test-image-exists: make pull-docker-test || ( echo "WARNING: Container Image not found in registry, building locally"; make build-docker-test ) @@ -122,7 +122,7 @@ docker-test: ensure-docker-test-image-exists $(TMP_DIR_MOUNT_FLAG) \ --mount type=bind,source=`pwd`,destination=/go/src/go.etcd.io/etcd \ gcr.io/etcd-development/etcd-test:go$(GO_VERSION) \ - /bin/bash -c "$(TEST_OPTS) ./scripts/test.sh 2>&1" > test-$(TEST_SUFFIX).log 2>&1 || (cat test-$(TEST_SUFFIX).log && exit 1) + /bin/bash -c "$(TEST_OPTS) OUTPUT_FILE='test-$(TEST_SUFFIX).log' ./scripts/test.sh" ! egrep "(--- FAIL:|FAIL:|DATA RACE|panic: test timed out|appears to have leaked)" -B50 -A10 test-$(TEST_SUFFIX).log docker-test-coverage: diff --git a/scripts/test.sh b/scripts/test.sh index 04b2ab530..bb70192f9 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -46,6 +46,11 @@ export ETCD_VERIFY=all source ./scripts/test_lib.sh source ./scripts/build.sh +if [ -n "${OUTPUT_FILE}" ]; then + log_callout "Dumping output to: ${OUTPUT_FILE}" + exec > >(tee -a "${OUTPUT_FILE}") 2>&1 +fi + PASSES=${PASSES:-"fmt bom dep build unit"} PKG=${PKG:-}