Skip to content
Merged
25 changes: 24 additions & 1 deletion .circleci/collect_results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This folder will be saved by circleci and available after test runs.

set -e
#Enable '**' support
# Enable '**' support
shopt -s globstar

TEST_RESULTS_DIR=results
Expand All @@ -19,13 +19,36 @@ if [[ ${#TEST_RESULT_DIRS[@]} -eq 0 ]]; then
exit 0
fi

function get_source_file () {
file_path="${RESULT_XML_FILE%%"/build"*}"
file_path="${file_path/#"$WORKSPACE_DIR"\//}/src"
if ! [[ $RESULT_XML_FILE == *"#"* ]]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the XML file has "#" in the path, then the file name corresponds to the testcase name. In this case I left the source file as the src parent directory of the file that the test case was run from.

class="${RESULT_XML_FILE%.xml}"
class="${class##*"TEST-"}"
class="${class##*"."}"
common_root=$(grep -rl "class $class" "$file_path" | head -n 1)
while IFS= read -r line; do
while [[ $line != "$common_root"* ]]; do
common_root=$(dirname "$common_root")
if [[ "$common_root" == "$common_root/.." ]]; then
break
fi
done
done < <(grep -rl "class $class" "$file_path")
file_path="$common_root"
fi
}

echo "Saving test results:"
while IFS= read -r -d '' RESULT_XML_FILE
do
echo -n "- $RESULT_XML_FILE"
AGGREGATED_FILE_NAME=$(echo "$RESULT_XML_FILE" | rev | cut -d "/" -f 1,2,5 | rev | tr "/" "_")
echo -n " as $AGGREGATED_FILE_NAME"
cp "$RESULT_XML_FILE" "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
# Insert file attribute to testcase XML nodes
get_source_file
sed -i "/<testcase/ s|\(time=\"[^\"]*\"\)|\1 file=\"$file_path\"|g" "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes that all testcases in the same XML result come from the same source file.

# Replace Java Object hashCode by marker in testcase XML nodes to get stable test names
sed -i '/<testcase/ s/@[0-9a-f]\{5,\}/@HASHCODE/g' "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
# Replace random port numbers by marker in testcase XML nodes to get stable test names
Expand Down
Loading