Commit 63094448 authored by Camil Staps's avatar Camil Staps 🐧

Use source locations in JUnit export when available

parent 082b2b99
Pipeline #27778 failed with stage
in 48 seconds
implementation module Testing.JUnitExport implementation module Testing.JUnitExport
import StdEnv import StdEnv
import StdMaybe
import Data.Func import Data.Func
import Data.Maybe
import System.FilePath import System.FilePath
import Testing.Options import Testing.Options
import Testing.TestEvents import Testing.TestEvents
...@@ -49,8 +49,8 @@ where ...@@ -49,8 +49,8 @@ where
} }
where where
failure msg = failure msg =
{ juf_file = suite_name // TODO { juf_file = fromMaybe "" event.EndEvent.filename
, juf_line = 0 // TODO , juf_line = fromMaybe 0 event.EndEvent.line
, juf_category = "failed unit test" , juf_category = "failed unit test"
, juf_message = msg , juf_message = msg
, juf_severity = "ERROR" , juf_severity = "ERROR"
......
...@@ -253,7 +253,7 @@ list r w ...@@ -253,7 +253,7 @@ list r w
run :: !Options !SubTestRun !*World -> *(!RunResult, !*World) run :: !Options !SubTestRun !*World -> *(!RunResult, !*World)
run opts r w run opts r w
# (io,w) = stdio w # (io,w) = stdio w
# io = emit (StartEvent {StartEvent | name=name}) io # io = emit (StartEvent {StartEvent | name=name, filename=Nothing, line=Nothing}) io
with name = (case r of JustRun r -> r; Only _ r -> r; Without _ r -> r).TestRun.name with name = (case r of JustRun r -> r; Only _ r -> r; Without _ r -> r).TestRun.name
# (extra_opts,r,w) = case r of # (extra_opts,r,w) = case r of
JustRun r -> (Just [], r, w) JustRun r -> (Just [], r, w)
...@@ -263,9 +263,11 @@ run opts r w ...@@ -263,9 +263,11 @@ run opts r w
_ -> Just ["--skip":intersperse "--skip" names], r, w)) $ list r w _ -> Just ["--skip":intersperse "--skip" names], r, w)) $ list r w
| isNothing extra_opts | isNothing extra_opts
# io = emit (EndEvent # io = emit (EndEvent
{ name = r.TestRun.name { name = r.TestRun.name
, event = Passed , filename = Nothing
, message = "No remaining tests" , line = Nothing
, event = Passed
, message = "No remaining tests"
}) io }) io
= return Passed [] r io w = return Passed [] r io w
# extra_opts = fromJust extra_opts # extra_opts = fromJust extra_opts
...@@ -274,9 +276,11 @@ run opts r w ...@@ -274,9 +276,11 @@ run opts r w
# (err,msg) = fromError h # (err,msg) = fromError h
# event = Failed Nothing # event = Failed Nothing
# io = emit (EndEvent # io = emit (EndEvent
{ name = r.TestRun.name { name = r.TestRun.name
, event = event , filename = Nothing
, message = "Failed to execute " <+ r.TestRun.name <+ " (" <+ err <+ "; " <+ msg <+ ")" , line = Nothing
, event = event
, message = "Failed to execute " <+ r.TestRun.name <+ " (" <+ err <+ "; " <+ msg <+ ")"
}) io }) io
= return event [] r io w = return event [] r io w
# (h,pio) = fromOk h # (h,pio) = fromOk h
...@@ -299,9 +303,11 @@ where ...@@ -299,9 +303,11 @@ where
# (err,msg) = fromError t # (err,msg) = fromError t
# event = Failed Nothing # event = Failed Nothing
# io = emit (EndEvent # io = emit (EndEvent
{ name = r.TestRun.name { name = r.TestRun.name
, event = event , filename = Nothing
, message = "Failed to check on child process (" <+ err <+ "; " <+ msg <+ ")" , line = Nothing
, event = event
, message = "Failed to check on child process (" <+ err <+ "; " <+ msg <+ ")"
}) io }) io
= return event [] r io w = return event [] r io w
# rcode = fromOk t # rcode = fromOk t
...@@ -312,9 +318,11 @@ where ...@@ -312,9 +318,11 @@ where
| any isNothing results | any isNothing results
# event = Failed Nothing # event = Failed Nothing
# io = emit (EndEvent # io = emit (EndEvent
{ name = r.TestRun.name { name = r.TestRun.name
, event = event , filename = Nothing
, message = join "\n " , line = Nothing
, event = event
, message = join "\n "
[ "Failed to read child messages:" [ "Failed to read child messages:"
: [printToString (ellipsis 40 outp) \\ outp <- output.lines & Nothing <- results] : [printToString (ellipsis 40 outp) \\ outp <- output.lines & Nothing <- results]
] ]
...@@ -332,12 +340,15 @@ where ...@@ -332,12 +340,15 @@ where
| ee.event=:(Failed (Just (FailedChildren _))) | ee.event=:(Failed (Just (FailedChildren _)))
// We already have a FailedChildren message; no need for another about the exit code // We already have a FailedChildren message; no need for another about the exit code
= return event [ee \\ EndEvent ee <- events] r io w = return event [ee \\ EndEvent ee <- events] r io w
# io = emit ( EndEvent { name = r.TestRun.name # io = emit
, event = event (EndEvent
, message = "Child process exited with " <+ fromJust rcode { name = r.TestRun.name
} , filename = Nothing
) , line = Nothing
io , event = event
, message = "Child process exited with " <+ fromJust rcode
})
io
= return event [ee \\ EndEvent ee <- events] r io w = return event [ee \\ EndEvent ee <- events] r io w
= return ee.event [ee \\ EndEvent ee <- events] r io w = return ee.event [ee \\ EndEvent ee <- events] r io w
# w = snd $ fclose io w # w = snd $ fclose io w
...@@ -345,8 +356,10 @@ where ...@@ -345,8 +356,10 @@ where
where where
collectEvents :: [TestEvent] -> EndEvent collectEvents :: [TestEvent] -> EndEvent
collectEvents tes = collectEvents tes =
{ name = r.TestRun.name { name = r.TestRun.name
, event = if (isEmpty failed && isEmpty lost) Passed , filename = Nothing
, line = Nothing
, event = if (isEmpty failed && isEmpty lost) Passed
(Failed $ Just $ FailedChildren $ (Failed $ Just $ FailedChildren $
[(name, fr) \\ EndEvent {name,event=Failed fr} <- failed] ++ [(name, fr) \\ EndEvent {name,event=Failed fr} <- failed] ++
[(l, Just Crashed) \\ l <- lost]) [(l, Just Crashed) \\ l <- lost])
...@@ -375,9 +388,11 @@ where ...@@ -375,9 +388,11 @@ where
_ -> fromError err _ -> fromError err
# event = Failed Nothing # event = Failed Nothing
# io = emit (EndEvent # io = emit (EndEvent
{ name = r.TestRun.name { name = r.TestRun.name
, event = event , filename = Nothing
, message = "Failed to read child process IO (" <+ err <+ "; " <+ msg <+ ")" , line = Nothing
, event = event
, message = "Failed to read child process IO (" <+ err <+ "; " <+ msg <+ ")"
}) io }) io
= (Error oserr, output, io, w) = (Error oserr, output, io, w)
# out = fromOk out # out = fromOk out
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment