Skip to content

Commit 6934e33

Browse files
committed
Rewrite file retrieval script to account for classes that don't match their file name.
1 parent 76ba870 commit 6934e33

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

.circleci/collect_results.sh

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This folder will be saved by circleci and available after test runs.
55

66
set -e
7-
#Enable '**' support
7+
# Enable '**' support
88
shopt -s globstar
99

1010
TEST_RESULTS_DIR=results
@@ -23,34 +23,26 @@ echo "Saving test results:"
2323
while IFS= read -r -d '' RESULT_XML_FILE
2424
do
2525
echo -n "- $RESULT_XML_FILE"
26-
27-
28-
# Get source file of XML file
29-
FILE_PATH="${RESULT_XML_FILE%%"build"*}"
30-
FILE_PATH="${FILE_PATH/#workspace\//}"
31-
FILE="${RESULT_XML_FILE##*"TEST-"}"
32-
CLASS="${FILE%%".xml"*}"
33-
if [[ $CLASS == *"#"* ]]; then
34-
# NOTE: if the XML file is of a particular test case, the source file is set to the parent test directory of the file that the test case was run from
35-
SUBDIRS="src/test"
36-
else
37-
CLASS_FILE="${CLASS//./\/}"
38-
SUBDIRS="src/test/groovy/$CLASS_FILE.groovy"
26+
# Get source file for testcases
27+
FILE_PATH="${RESULT_XML_FILE%%"/build"*}"
28+
FILE_PATH="${FILE_PATH/#"$WORKSPACE_DIR"\//}/src"
29+
if ! [[ $RESULT_XML_FILE == *"#"* ]]; then
30+
CLASS="${RESULT_XML_FILE%.xml}"
31+
CLASS="${CLASS##*"."}"
32+
CLASS_PATH=$(grep -rl "class $CLASS" "$FILE_PATH" | tail -n 1)
33+
FILE_PATH="$CLASS_PATH"
3934
fi
40-
FILE_PATH+="$SUBDIRS"
41-
echo -n "$FILE_PATH"
42-
43-
4435
AGGREGATED_FILE_NAME=$(echo "$RESULT_XML_FILE" | rev | cut -d "/" -f 1,2,5 | rev | tr "/" "_")
4536
echo -n " as $AGGREGATED_FILE_NAME"
4637
cp "$RESULT_XML_FILE" "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
47-
48-
4938
# Insert file attribute to testcase XML nodes
50-
# NOTE: this assumes the same source file to each test case of the XML
39+
echo "***"
40+
echo "FILEPATH: $FILE_PATH"
41+
echo "***"
5142
sed -i "/<testcase/ s|\(time=\"[^\"]*\"\)|\1 file=\"$FILE_PATH\"|g" "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
52-
53-
43+
echo "---"
44+
cat "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
45+
echo "---"
5446
# Replace Java Object hashCode by marker in testcase XML nodes to get stable test names
5547
sed -i '/<testcase/ s/@[0-9a-f]\{5,\}/@HASHCODE/g' "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
5648
# Replace random port numbers by marker in testcase XML nodes to get stable test names

0 commit comments

Comments
 (0)