Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Parsing strategy  RSS feed

 
Carl Pettersson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all!
I'm writing a parser to generate JUnit-like files from a custom test format used in one of our products. The product is not writted in Java, so we cannot rewrite the tests to JUnit, but our build statistics tool only reads JUnit-format.
What I'd like some help with is evaluating if I'm doing this in a smart way, or if you can suggest a better one. Below is my current idea.
The files generated by our test tool look like this (part of acual output):

So each line is date, time, log severity, test facility and status message.
The approach I'm currently using reads the input into an arraylist of hashmaps, and removes header/footer and other "uninteresting" lines.
Then I iterate over the ArrayList, and depending on what is in the status field, I do different things.
However, I'm finding this increasingly difficult. The test is started with a line with a status "Test: <TESTNAME>...", then any output during the test, and then "Test: <TESTNAME> [ <TEST OUTCOME> ] ( <FAILED/TOTAL> )".
So I'd have to save a temporary var with the current test name, collect any lines in another temporary var, until I find the test name again.
Is this really a good strategy?
Also, is the JUnit-XML format specified somewhere? I've googled but haven't found anything. Since there are multiple Script-sections, I thought I'd create a separate <testsuite>, and thus file, for each. However, there are sometimes nested Scripts, how would you handle this?

Best regards
Carl Pettersson
[ July 03, 2008: Message edited by: Carl Pettersson ]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this were my problem I'd use a lexer such as JFlex, which makes it much easier to associate Java code to particular text inputs.
 
Carl Pettersson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've had a look at it (read the manual), and it seems rather more complicated than I'd hoped. I'll try it though, but any ideas on my approach are still very welcome!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!