Skip to content

Instantly share code, notes, and snippets.

@benasher44
Last active February 28, 2023 15:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benasher44/b3cdf4060d4eac24eff85ef08816ffc0 to your computer and use it in GitHub Desktop.
Save benasher44/b3cdf4060d4eac24eff85ef08816ffc0 to your computer and use it in GitHub Desktop.
K/N GTest Output to JUnit XML using sed
# Escape XML characters
s/&/\&/g
s/"/\"/g
s/'/\'/g
s/</\&lt;/g
s/>/\&gt;/g
s/\[==========\] Running ([0-9]+) tests from [0-9]+ test cases./<testsuites><testsuite tests="\1">/g
s/\[ RUN \] ([[:alnum:]_-]+)\.(.+)/<testcase classname="\1" name="\2">/g
s/\[----------\].+//g
s/YOU HAVE [0-9]+ DISABLED TEST\(S\)//g
# lines that start with a letter are usually an exception being thrown; start a failure node
s/^([[:alpha:]].+)/<failure>\1/
s#\[ FAILED \].+ ms\)#</failure></testcase>#g
s#\[ OK \].+ ms\)#</testcase>#g
s#\[==========\] ([0-9]+) tests from ([0-9]+) test cases ran.+#</testsuite></testsuites>#g
s/\[ PASSED \] [0-9]+ tests\.//g
s/\[ FAILED \] [0-9]+ tests,.+//g
s/\[ FAILED \] .+//g
s/[0-9]+ FAILED TESTS//g
@benasher44
Copy link
Author

Usage:

./test.kexe --ktest_logger=GTEST | sed -E -f kn_gtest_to_junit.sed

@benasher44
Copy link
Author

Would need to use a real programming language to capture test times testcase nodes

@benasher44
Copy link
Author

Updated to support ignored tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment