Add JUnit XML reports; refactor test reporting

* Add Junit output file support
* Differentiate between an expected failure test and an error in the
test, as described in JUnit.
* In case of an error/exception during test, record and attach it to the
Test object and continue running the tests, and show it at the end
during the trial report.

Change-Id: Iedf6d912b3cce3333a187a4ac6d5c6b70fe9d5c5
diff --git a/selftest/suite_test.py b/selftest/suite_test.py
index 315c683..16342c5 100755
--- a/selftest/suite_test.py
+++ b/selftest/suite_test.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 import os
 import _prep
-from osmo_gsm_tester import log, suite, config
+from osmo_gsm_tester import log, suite, config, report
 
 config.ENV_CONF = './suite_test'
 
@@ -22,13 +22,33 @@
 print('- run hello world test')
 s = suite.SuiteRun(None, 'test_suite', s_def)
 results = s.run_tests('hello_world.py')
-print(str(results))
+print(report.suite_to_text(s))
 
 log.style_change(src=True)
 #log.style_change(trace=True)
 print('\n- a test with an error')
 results = s.run_tests('test_error.py')
-print(str(results))
+output = report.suite_to_text(s)
+assert 'FAIL: [test_suite] 1 failed ' in output
+assert 'FAIL: [test_error.py]' in output
+assert "type:'AssertionError' message: AssertionError()" in output
+assert 'assert False' in output
+
+print('\n- a test with a failure')
+results = s.run_tests('test_fail.py')
+output = report.suite_to_text(s)
+assert 'FAIL: [test_suite] 1 failed ' in output
+assert 'FAIL: [test_fail.py]' in output
+assert "type:'EpicFail' message: This failure is expected" in output
+assert "test.set_fail('EpicFail', 'This failure is expected')" in output
+
+print('\n- a test with a raised failure')
+results = s.run_tests('test_fail_raise.py')
+output = report.suite_to_text(s)
+assert 'FAIL: [test_suite] 1 failed ' in output
+assert 'FAIL: [test_fail_raise.py]' in output
+assert "type:'EpicFail' message: This failure is expected" in output
+assert "raise Failure('EpicFail', 'This failure is expected')" in output
 
 print('\n- graceful exit.')
 # vim: expandtab tabstop=4 shiftwidth=4