-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integration-tests: Allow generating tests results in ant xml format (#…
- Loading branch information
1 parent
2a467b3
commit 4f78bb2
Showing
30 changed files
with
251 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
All integration tests can generate XML reports. | ||
|
||
To generate the report in brig-integration, galley-integration, | ||
cargohold-integration, gundeck-integration, stern-integration and the new | ||
integration suite pass `--xml=<outfile>` to generate the XML file. | ||
|
||
For spar-integration and federator-integration pass `-f junit` and set | ||
`JUNIT_OUTPUT_DIRECTORY` and `JUNIT_SUITE_NAME` environment variables. The XML | ||
report will be generated at `$JUNIT_OUTPUT_DIRECTORY/junit.xml`. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module Testlib.XML where | ||
|
||
import Data.Array qualified as Array | ||
import Data.Fixed | ||
import Data.Time | ||
import Testlib.Types | ||
import Text.Regex.Base qualified as Regex | ||
import Text.Regex.TDFA.String qualified as Regex | ||
import Text.XML.Light | ||
import Prelude | ||
|
||
saveXMLReport :: TestSuiteReport -> FilePath -> IO () | ||
saveXMLReport report output = | ||
writeFile output $ showTopElement $ xmlReport report | ||
|
||
xmlReport :: TestSuiteReport -> Element | ||
xmlReport report = | ||
unode | ||
"testsuites" | ||
( Attr (unqual "name") "wire-server", | ||
testSuiteElements | ||
) | ||
where | ||
testSuiteElements = | ||
unode | ||
"testsuite" | ||
( attrs, | ||
map encodeTestCase report.cases | ||
) | ||
attrs = | ||
[ Attr (unqual "name") "integration", | ||
Attr (unqual "tests") $ show $ length report.cases, | ||
Attr (unqual "failures") $ show $ length $ filter (\testCase -> testCase.result /= TestSuccess) report.cases, | ||
Attr (unqual "time") $ showFixed True $ nominalDiffTimeToSeconds $ sum $ map (.time) report.cases | ||
] | ||
|
||
encodeTestCase :: TestCaseReport -> Element | ||
encodeTestCase TestCaseReport {..} = | ||
unode "testcase" (attrs, content) | ||
where | ||
attrs = | ||
[ Attr (unqual "name") name, | ||
Attr (unqual "time") (showFixed True (nominalDiffTimeToSeconds time)) | ||
] | ||
content = case result of | ||
TestSuccess -> [] | ||
TestFailure msg -> [failure msg] | ||
failure msg = unode "failure" (blank_cdata {cdData = dropConsoleFormatting msg}) | ||
|
||
-- Drops ANSI control characters which might be used to set colors. | ||
-- Including these breaks XML, there is not much point encoding them. | ||
dropConsoleFormatting input = | ||
let regex = Regex.makeRegex "\x1b\\[[0-9;]*[mGKHF]" :: Regex.Regex | ||
matches = Regex.matchAll regex input | ||
dropMatch (offset, len) input' = | ||
let (begining, rest) = splitAt offset input' | ||
(_, end) = splitAt len rest | ||
in begining <> end | ||
matchTuples = map (Array.! 0) matches | ||
in foldr dropMatch input matchTuples |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.