-
Notifications
You must be signed in to change notification settings - Fork 323
Add testcase source file attribute to JUnit XML reports #8218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
be158e5
Add script to insert source file attributes to XML file testcases.
sarahchen6 ec8e82b
Change sed deliminator and add file quotes.
sarahchen6 271dc82
Remove 'workspace/' from path.
sarahchen6 02776f6
Rewrite file retrieval script to account for classes that don't match…
sarahchen6 779f69e
Clean script.
sarahchen6 fcea1c6
Add missing formatting for class name.
sarahchen6 42780e0
Get common root of classes that are in multiple file paths.
sarahchen6 d44139d
Lower case new variables.
sarahchen6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 | ||
| 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" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.