From bc2eca7eac8d0aaf630ed128c7b7e436f3898ff3 Mon Sep 17 00:00:00 2001 From: htom Date: Fri, 7 Nov 2025 12:54:11 +0100 Subject: [PATCH] added new test.sh script The test.sh script will run the cargo test and save a formatted output from each project and then append them to a final log file which will be the data to be uploaded to the spreadsheet --- .github/workflows/engine_test.yml | 4 +--- .github/workflows/server_test.yml | 4 +--- .github/workflows/test.sh | 37 +++++++++++++++++++++++++++++++ .github/workflows/ui_test.yml | 4 +--- 4 files changed, 40 insertions(+), 9 deletions(-) create mode 100755 .github/workflows/test.sh diff --git a/.github/workflows/engine_test.yml b/.github/workflows/engine_test.yml index 8abc162..4590631 100644 --- a/.github/workflows/engine_test.yml +++ b/.github/workflows/engine_test.yml @@ -14,6 +14,4 @@ jobs: - name: Run Engine tests run: | - cd engine - pwd - cargo test --verbose + bash .github/workflows/test.sh engine/ diff --git a/.github/workflows/server_test.yml b/.github/workflows/server_test.yml index 3c5f8ab..f39eae5 100644 --- a/.github/workflows/server_test.yml +++ b/.github/workflows/server_test.yml @@ -14,6 +14,4 @@ jobs: - name: Run Server tests run: | - cd server - pwd - cargo test --verbose + bash .github/workflows/test.sh server/ diff --git a/.github/workflows/test.sh b/.github/workflows/test.sh new file mode 100755 index 0000000..1191005 --- /dev/null +++ b/.github/workflows/test.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +set -e + +# --- ARGUMENT CHECK --- +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +# --- SETUP VARIABLES --- +PROJECT_PATH="$1" +PROJECT_NAME=$(basename "$PROJECT_PATH") +ROOT_DIR=$(git rev-parse --show-toplevel) + +LOG_FILE="${PROJECT_NAME}_test.log" +FINAL_LOG="${ROOT_DIR}/test_data.log" + +# --- MOVE TO PROJECT DIRECTORY --- +echo ">>> Running tests for project: $PROJECT_NAME" +cd "$PROJECT_PATH" || { echo "Error: Could not cd into $PROJECT_PATH"; exit 1; } + +# --- RUN TESTS --- +cargo test --verbose | tee full_test_output.log + +# --- EXTRACT TEST SECTION --- +# Create the log file with the project name as the first line +echo "$PROJECT_NAME" > "$LOG_FILE" + +# Then append only the lines between "running X test(s)" and the first empty line +awk '/^running [0-9]+ test[s]?$/,/^$/' full_test_output.log >> "$LOG_FILE" + +# --- APPEND TO GLOBAL LOG (in repo root) --- +cat "$LOG_FILE" >> "$FINAL_LOG" + +# --- SUMMARY --- +echo ">>> Test output extracted to $PROJECT_PATH/$LOG_FILE" +echo ">>> Appended to $FINAL_LOG" diff --git a/.github/workflows/ui_test.yml b/.github/workflows/ui_test.yml index 37ada00..114283a 100644 --- a/.github/workflows/ui_test.yml +++ b/.github/workflows/ui_test.yml @@ -14,6 +14,4 @@ jobs: - name: Run UI tests run: | - cd ui - pwd - cargo test --verbose + bash .github/workflows/test.sh ui/