#!/bin/bash
# Generate test output files for the testing module examples
# Run this script to regenerate all output files after making changes to tests

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

echo "Generating test outputs in ${SCRIPT_DIR}..."

cd "${SCRIPT_DIR}"

# Context tests
echo "  -> context_test.go outputs..."
go test -v -run Test_WithContext ./context_test.go 2>&1 > "${SCRIPT_DIR}/context_test.output"
go test -v -run Test_ContextCancellation ./context_test.go 2>&1 > "${SCRIPT_DIR}/context_cancel.output"

# Chdir tests
echo "  -> chdir_test.go outputs..."
go test -v -run Test_Chdir ./chdir_test.go 2>&1 > "${SCRIPT_DIR}/chdir_test.output"
go test -v -run Test_ConfigFile ./chdir_test.go 2>&1 > "${SCRIPT_DIR}/chdir_config.output"

# Benchmark tests
echo "  -> benchmark_test.go outputs..."
go test -bench=BenchmarkStringConcat -benchmem ./benchmark_test.go 2>&1 > "${SCRIPT_DIR}/benchmark_basic.output"
go test -bench=BenchmarkStringBuilder_Loop -benchmem ./benchmark_test.go 2>&1 > "${SCRIPT_DIR}/benchmark_loop.output"
go test -bench=. -benchmem ./benchmark_test.go 2>&1 > "${SCRIPT_DIR}/benchmark_all.output"

# Synctest tests
echo "  -> synctest_test.go outputs..."
go test -v -run Test_Synctest_Basic ./synctest_test.go 2>&1 > "${SCRIPT_DIR}/synctest_basic.output"
go test -v -run Test_Synctest_Wait ./synctest_test.go 2>&1 > "${SCRIPT_DIR}/synctest_wait.output"
go test -v -run Test_Synctest_Ticker ./synctest_test.go 2>&1 > "${SCRIPT_DIR}/synctest_ticker.output"

# Attr tests
echo "  -> attr_test.go outputs..."
go test -v -run Test_Attributes ./attr_test.go 2>&1 > "${SCRIPT_DIR}/attr_test.output"
go test -v -run Test_Output ./attr_test.go 2>&1 > "${SCRIPT_DIR}/attr_output.output"
go test -v -run Test_SubtestAttributes ./attr_test.go 2>&1 > "${SCRIPT_DIR}/attr_subtest.output"

# Parallel subtest
echo "  -> sub_test_parallel_test.go outputs..."
go test -v -run Test_Print ./sub_test_parallel_test.go 2>&1 > "${SCRIPT_DIR}/sub_test_parallel.output"

echo ""
echo "Done! Generated output files:"
ls -la "${SCRIPT_DIR}"/*.output
