AutoModality / action-xunit-viewer

XUnit / JUnit HTML Test Reports
MIT License
8 stars 11 forks source link

Errors incorrectly detected when failures="0" #12

Closed steve-taylor closed 2 years ago

steve-taylor commented 2 years ago

Consider the following xunit output:

<testsuite name="Testem Tests" tests="18" skipped="0" failures="0" timestamp="Mon Nov 08 2021 10:21:17 GMT+1100 (Australian Eastern Daylight Time)" time="8.652">
    <!-- Redacted -->
</testsuite>

This is being reported as an error, which I've traced to detection.sh line 19.

I noticed there's inconsistent usage of the -L option of grep. This is important because the -L option not only suppresses output (replacing it with the name of the file), but also inverts the match.

Interestingly, when I ran this locally on macOS to reproduce the issue, I couldn't reproduce it. However, I was able to reproduce it in Linux. It seems that grep -L always returns 0 on macOS, whereas it returns 1 on Linux when a match is found (i.e. opposite of what grep -l would do).

The pseudocode of this snippet:

if echo "$suite_line" | grep "failures=\"0\"";then
    if echo "$suite_line" | grep -L "errors=\"[1-9]\d*\"";then
        echo "Error found in $file: $suite_line"
        return 1
    else
        return 0
    fi
elif echo "$suite_line" | grep -L "errors=\"0\"";then
    if echo "$suite_line" | grep -L "failures=\"[1-9]\d*\"";then
        echo "Error found in $file: $suite_line"
        return 1
    else
        return 0
    fi
else
    echo "Failure found in $file: $suite_line"
    return 1
fi

appears to be the following:

More concisely, failure occurs if one of the following is true:

This is what I think is needed:

In which case, find_fail should become:

find_fail() {
    target=$1
    file=$2
    suite_line=$(cat "$file" | grep "$target")

    if echo "$suite_line" | grep -q -E "failures=\"[1-9]\\d*\""; then
      echo "Failure(s) found in $file: $suite_line"
      return 1
    elif echo "$suite_line" | grep -q -E "errors=\"[1-9]\\d*\""; then
      echo "Error(s) found in $file: $suite_line"
      return 1
    elif echo "$suite_line" | grep -qv -E "failures=\"0\""; then
      echo "Test report may be malformed: No errors were detected, but the failures attribute is missing from the testsuite element."
      return 1
    fi
}

As a bonus, it also works on macOS.

trittgers-principal commented 2 years ago

I am also experiencing this issue since yesterday and would appreciate a fix.

aroller commented 2 years ago

Notice the action from a clean branch of master shows tests failing. image

Then merging branch #13 fixes the tests in this action. It would seem something stopped working correctly without any code introduced.

image

github-actions[bot] commented 2 years ago

:tada: This issue has been resolved in version 1.2.3 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

aroller commented 2 years ago

@trittgers-principal @steve-taylor please see if v1 tag works now for your actions. Close the issue if so or let me know what we need to do next.

v1 now points to the latest release that includes #13 image

Thanks for your contribution.

trittgers-principal commented 2 years ago

This works for me. Thanks!