Last active
February 26, 2025 00:01
-
-
Save itsjoeoui/c18f3a5f0c71324207e98b7edda6e57f to your computer and use it in GitHub Desktop.
COMP 310 Test Runner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Arguments: | |
| # $1 - Assignment number (A1 or A2) | |
| ASSIGNMENT=$1 | |
| # Colors | |
| GREEN='\033[0;32m' | |
| RED='\033[0;31m' | |
| NC='\033[0m' | |
| # Get test files (excluding result files) | |
| TEST_FILES=$(find "${ASSIGNMENT}/test-cases" -name "*.txt" ! -name "*_result*.txt") | |
| echo -e "\nRunning ${ASSIGNMENT} tests..." | |
| PASSED=0 | |
| TOTAL=0 | |
| FAILED_TESTS="" | |
| for test in $TEST_FILES; do | |
| TOTAL=$((TOTAL + 1)) | |
| if ./verify_single_test.sh "$test"; then | |
| PASSED=$((PASSED + 1)) | |
| else | |
| FAILED_TESTS="${FAILED_TESTS}\n${test}" | |
| fi | |
| done | |
| echo -e "\n${ASSIGNMENT} Test Summary: ${PASSED}/${TOTAL} tests passed" | |
| if [ $PASSED -eq $TOTAL ]; then | |
| echo -e "${GREEN}All ${ASSIGNMENT} tests passed!${NC}" | |
| exit 0 | |
| else | |
| echo -e "${RED}$((TOTAL - PASSED)) test(s) failed${NC}" | |
| echo -e "Failed tests: ${FAILED_TESTS}" | |
| exit 1 | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Main directories | |
| PROJECT_DIR = project/src | |
| TEST_DIRS = A1/test-cases A2/test-cases | |
| EXECUTABLE = mysh | |
| # Clean directories | |
| A1_CLEAN_DIRS = toto bad_name testdir test | |
| A2_CLEAN_DIRS = | |
| .PHONY: all clean test test-a1 test-a2 build setup-tests clean-a1 clean-a2 | |
| # Default target | |
| all: clean build test | |
| # Build the project | |
| build: | |
| @echo "Building project..." | |
| @$(MAKE) -C $(PROJECT_DIR) | |
| # Create symbolic links to executable in test directories | |
| setup-tests: build | |
| @echo "Setting up test environments..." | |
| @for dir in $(TEST_DIRS); do \ | |
| ln -sf ../../$(PROJECT_DIR)/$(EXECUTABLE) $$dir/$(EXECUTABLE); \ | |
| done | |
| test-single: setup-tests | |
| @$(MAKE) clean-a2 | |
| @$(MAKE) clean-a1 | |
| @./verify_single_test.sh $(TEST) | |
| @$(MAKE) clean-a2 | |
| @$(MAKE) clean-a1 | |
| # Run all tests | |
| test: test-a1 test-a2 | |
| # Run A1 tests | |
| test-a1: setup-tests | |
| @$(MAKE) clean-a1 | |
| @./execute_test_suite.sh A1 | |
| @$(MAKE) clean-a1 | |
| # Clean A1 test directories | |
| clean-a1: | |
| @echo "Cleaning A1 test directories..." | |
| @for dir in $(A1_CLEAN_DIRS); do \ | |
| rm -rf ./A1/test-cases/$$dir; \ | |
| done | |
| # Run A2 tests | |
| test-a2: setup-tests | |
| @$(MAKE) clean-a2 | |
| @./execute_test_suite.sh A2 | |
| @$(MAKE) clean-a2 | |
| # Clean A2 test directories | |
| clean-a2: | |
| @echo "Cleaning A2 test directories..." | |
| @for dir in $(A2_CLEAN_DIRS); do \ | |
| rm -rf ./A2/test-cases/$$dir; \ | |
| done | |
| # Clean up everything | |
| clean: clean-a1 clean-a2 | |
| @echo "Cleaning up project..." | |
| @$(MAKE) -C $(PROJECT_DIR) clean | |
| setup: | |
| git remote set-url --add --push origin git@gitlab.cs.mcgill.ca:xyu62/operating-systems-w25.git | |
| git remote set-url --add --push origin git@github.com:itsjoeoui/os310.git |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Colors for output | |
| GREEN='\033[0;32m' | |
| RED='\033[0;31m' | |
| YELLOW='\033[0;33m' | |
| NC='\033[0m' # No Color | |
| # Arguments: | |
| # $1 - test file path | |
| echo -e "\nTesting $1:" | |
| # Derive test directory and test file name from $1 | |
| test_directory=$(dirname "$1") | |
| test_file_name=$(basename "$1") | |
| # Get the base name (without extension) | |
| base_name=$(basename "$test_file_name" .txt) | |
| result_files=("$test_directory/${base_name}_result.txt" "$test_directory/${base_name}_result2.txt") | |
| # Run test and capture output | |
| output=$(cd "$test_directory" && ./mysh <"$test_file_name" | grep -v '^$') | |
| # Check against multiple expected result files | |
| for result_file in "${result_files[@]}"; do | |
| if [ -f "$result_file" ]; then | |
| expected=$(grep -v '^$' "$result_file") | |
| if [ "$output" = "$expected" ]; then | |
| echo -e "${GREEN}PASS${NC}: $1 with $result_file" | |
| exit 0 | |
| fi | |
| fi | |
| done | |
| echo -e "${RED}FAIL${NC}: $1" | |
| cat "$1" | |
| printf "\n" | |
| echo -e "${YELLOW}Expected${NC}:" | |
| for result_file in "${result_files[@]}"; do | |
| if [ -f "$result_file" ]; then | |
| echo "---------- $result_file ----------" | |
| grep -v '^$' "$result_file" | |
| fi | |
| done | |
| echo -e "${YELLOW}Got${NC}:" | |
| echo "$output" | |
| exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment