1

I am trying to parse unit test exception messages and separate them from the stack trace from st-out. The output is formatted like so:

  Message:
    Failed: expected invocation of Session.endDialog(It.isValue("login complete.")) exactly 1 times, invoked 0 times
     Configured setups:
     Session.endDialog(It.isValue("login complete."))

     Performed invocations:
     Session.sendTyping()
     Session.endDialog("Login complete.")

  Stack:
        at Object.<anonymous> (<some path>\<some file>.spec.ts:274:19)
        at fulfilled (<some path>\<some file>.spec.js:4:57)
        at process._tickDomainCallback (internal/process/next_tick.js:228:7)

The important bits are:

  • There is always a Message: preceded by 2 spaces, followed by a newline.
  • What follows Message: is 1 or more lines of text possibly with consecutive newlines.
  • There is always a Stack: preceded by 2 spaces, followed by a newline.
  • What follows Stack: is 1 or more lines of stack trace type text.

The parser is a little complicated in that it is line based but supports loops and a different RegExp is needed to capture the various important parts for the message.

I have working expressions for everything, except for one. Basically I need a RegEx to match anything after the line with Message: until the Stack:, one line at a time.

Eg, it must match:

    Failed: expected invocation of Session.endDialog(It.isValue("login complete.")) exactly 1 times, invoked 0 times`

and

     Configured setups:

and

     Session.endDialog(It.isValue("login complete."))

etc, but not

  Stack:

I have tried using negative look-ahead with no luck, this is what I have so far:

\s+(?!Stack:).+

Sean Sobey
  • 942
  • 7
  • 13
  • You say the parser is line based: how do you expect it to check context on different lines? – Wiktor Stribiżew Oct 05 '17 at 07:59
  • The set of RegExp patterns can be supplied and are used sequentially, so if and when the first pattern matches then then next one in the list is used to match etc. So you will know based on previous supplied regex what has been matched. – Sean Sobey Oct 05 '17 at 08:02
  • Then your description is too long and misleading. What do you need to match? A line that does not start with `Stack:`? `^(?! Stack:$)` / `(?m)^(?! Stack:$)`? – Wiktor Stribiżew Oct 05 '17 at 08:05
  • Well I still need to match the line, but yes I think I did not explain this problem very well :( – Sean Sobey Oct 05 '17 at 08:15
  • It seems `^(?! Stack:$)` and `(?m)^(?! Stack:$)` both just capture an empty string not the message on the line. – Sean Sobey Oct 05 '17 at 08:22
  • Yes, because this pattern can be used to return true or false. If you need the line, adding `.+` or `.*` is not a rocket science. You already have it in your pattern. – Wiktor Stribiżew Oct 05 '17 at 08:23

1 Answers1

1

I found the required pattern eventually: ^(?! Stack:)(.*)$

Sean Sobey
  • 942
  • 7
  • 13