summaryrefslogtreecommitdiff
path: root/pjutest
blob: 8edc4f2ea1f828dbea26a6c526612216a23eb39f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
#
# pjutest - junit xml generator

from junit_xml import TestSuite, TestCase
from pickle import dump, load
from subprocess import Popen, PIPE, STDOUT

import os
import sys

if len (sys.argv) != 2:
	print("%s 'mycmd param1' # to record a test" % sys.argv[0])
	sys.exit(-1)

if os.path.exists('pjutest.dat'):
	with open('pjutest.dat', 'r') as dat:
		tss = load(dat)
else:
	tss = [TestSuite("suite", None)]

p = Popen(sys.argv[1], shell=True, stdout=PIPE, stderr=PIPE)
out,err = p.communicate()

tc = TestCase(sys.argv[1], 'sh', 2, out[:-1], err[:-1])
if p.returncode:
	tc.add_failure_info(err, "return: %d" % p.returncode)

tss[0].test_cases.append(tc)

with open('pjutest.dat', 'w') as dat:
	dump(tss, dat)

with open('pjutest.xml', 'w') as xml:
	TestSuite.to_file(xml, tss, prettyprint=True)