Files

35 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Records what Instancio prints when a test fails, and how to reproduce it with @Seed.
# FailingSeedDemoTest fails on purpose, so every mvn call here is allowed to exit non-zero.
set -uo pipefail
cd "$(dirname "$0")/.."
clean() { grep -v -E '^(Picked up JAVA_TOOL_OPTIONS|WARNING:)' | grep -v -E '^\[INFO\] (Total time|Finished at)'; }
# 1. default classpath: no SLF4J provider, so the seed summary (logged via SLF4J) is dropped
RAW=$(mvn -B -T1 test -Dtest=FailingSeedDemoTest -Dlab.demo=fail 2>&1 | clean)
{
echo '$ mvn test -Dtest=FailingSeedDemoTest -Dlab.demo=fail'
echo "$RAW" | sed -n '/Running lab.instancio.FailingSeedDemoTest/,/Tests run: 40, Failures: [0-9]*, Errors: 0, Skipped: 0$/p' \
| grep -v -E '^\[INFO\] (BUILD|---|$)' | grep -v '^\s*at '
echo "lines containing '@Seed' in the whole Maven output: $(echo "$RAW" | grep -c '@Seed')"
} > output/16-failing-test-without-slf4j.txt
# 2. with an SLF4J provider (profile seed-log adds slf4j-simple) the summary appears
{
echo '$ mvn test -Pseed-log -Dtest=FailingSeedDemoTest -Dlab.demo=fail'
mvn -B -T1 test -Pseed-log -Dtest=FailingSeedDemoTest -Dlab.demo=fail 2>&1 | clean \
| sed -n '/Running lab.instancio.FailingSeedDemoTest/,/Tests run: 40, Failures: [0-9]*, Errors: 0, Skipped: 0$/p' \
| grep -v -E '^\[INFO\] (BUILD|---|$)' | grep -v '^\s*at '
} > output/17-failing-test-seed-summary.txt
# 3. the same assertion, pinned with a seed copied from a summary like the one above
{
echo '$ mvn test -Pseed-log -Dtest=ReproduceFailureDemoTest -Dlab.demo=reproduce (run 1)'
mvn -B -T1 test -Pseed-log -Dtest=ReproduceFailureDemoTest -Dlab.demo=reproduce 2>&1 | clean \
| grep -E 'Tests run:.*in lab|AssertionFailedError|@Seed' | head -4
echo '$ same command again (run 2)'
mvn -B -T1 test -Pseed-log -Dtest=ReproduceFailureDemoTest -Dlab.demo=reproduce 2>&1 | clean \
| grep -E 'Tests run:.*in lab|AssertionFailedError|@Seed' | head -4
} > output/18-reproduced-with-seed.txt
echo "captured: $(ls output | wc -l) files"