-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests_obsolete.sh
More file actions
executable file
·58 lines (44 loc) · 1.86 KB
/
run_tests_obsolete.sh
File metadata and controls
executable file
·58 lines (44 loc) · 1.86 KB
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
#!/bin/bash
DEBUG=S
function log() {
if [ "$DEBUG" == "S" ]; then
echo "$1"
fi
}
# Set the classpath to include all dependencies and compiled classes
CLASSPATH=$(find /app/dependency -type f -name "*.jar" | tr '\n' ':')/app/classes:/app/test-classes:/app
RESULT_FILE=/tmp/test_results.txt
log "Copying the student's code..."
# Copy the student's code to the correct directory
PACKAGE=empleados
FILE_PATH=/app/classes/$PACKAGE
cp /tmp/exercise $FILE_PATH/EmpleadoBR.java
log "Compiling the student's code..."
# Compile the student's code, replacing the stubs
COMPILE_ERROR_FILE=/tmp/compile_errors.txt
if ! javac -cp $CLASSPATH $FILE_PATH/EmpleadoBR.java \
-sourcepath /app/classes \
2> $COMPILE_ERROR_FILE; then
# Remove the file path from the error messages
compile_errors=$(sed "s|$FILE_PATH/||g" $COMPILE_ERROR_FILE)
echo "{ \"success\": false, \"error\": \"Compilation failed: $compile_errors\" }"
# Exit with an OK code, since the container succeeded but the correction failed
exit 0
fi
log "Compilation successful!"
log "Running the tests..."
# Run the JUnit Console Launcher to execute the tests
java -jar junit-platform-console-standalone.jar --class-path $CLASSPATH --scan-class-path --details=tree > "$RESULT_FILE"
# This generates the test reports as XML files
# The TEST-junit-jupiter.xml contains the results of the tests, TEST-junit-vintage.xml contains the results of the tests that use JUnit 4
java -jar junit-platform-console-standalone.jar --class-path $CLASSPATH --scan-class-path --details=tree --reports-dir=test-reports
# Check if tests were successful
if grep -q "Test run finished after" "$RESULT_FILE"; then
success=true
else
success=false
fi
# Extract test results
results=$(grep -A 50 "Test run finished after" "$RESULT_FILE")
# Create the JSON output
echo "{ \"success\": $success, \"results\": \"$results\" }"