generated from MarcosRigal/plantilla-asignaturas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_and_test.sh
executable file
·76 lines (63 loc) · 2.46 KB
/
build_and_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# List of directories
build_folders=("P1" "P2" "P3" "P4" "P5" "P6" "P7" "P8" "P9" "P10")
test_folders=("P1" "P2" "P3" "P4" "P5")
# Check if a specific folder is passed as an argument
if [ "$1" ]; then
if [[ " ${build_folders[@]} " =~ " $1 " ]]; then
build_folders=($1) # Set folders to only the specified folder
else
echo "Error: Folder $1 is not in the predefined list."
exit 1
fi
fi
# Initialize result files
build_results_file="build_results.log"
test_results_file="test_results.log"
echo "Build Results Summary:" > "$build_results_file"
echo "======================" >> "$build_results_file"
echo "Test Results Summary:" > "$test_results_file"
echo "=====================" >> "$test_results_file"
# Loop through each folder
for folder in "${build_folders[@]}"; do
echo "Processing folder: $folder"
# Navigate to the folder
if cd "$folder"; then
# Create and navigate to the build directory
mkdir -p build && cd build
# Run cmake and make, capturing build errors if any
echo "Building $folder..."
cmake .. >> "../../$build_results_file" 2>&1 && make >> "../../$build_results_file" 2>&1
if [ $? -eq 0 ]; then
echo "[$folder] Build successful." >> "../../$build_results_file"
else
echo "[$folder] Build failed." >> "../../$build_results_file"
cd ../..
continue # Skip to the next folder if build fails
fi
echo "======================" >> "../../$build_results_file"
if [ "$folder" ]; then
if [[ " ${test_folders[@]} " =~ " $folder " ]]; then
# Run the test and capture its output
echo "Running test for $folder..."
./test_common_code >> "../../$test_results_file" 2>&1
if [ $? -eq 0 ]; then
echo "[$folder] Test passed." >> "../../$test_results_file"
else
echo "[$folder] Test failed." >> "../../$test_results_file"
fi
echo "======================" >> "../../$test_results_file"
# Return to the parent folder
fi
fi
cd ..
# Return to the base directory
cd ..
else
echo "[$folder] Failed to navigate to $folder. Skipping." >> "$build_results_file"
fi
done
# Clean up individual logs
for folder in "${build_folders[@]}"; do
rm -f "${folder}_build.log" "${folder}_test.log"
done