-
Notifications
You must be signed in to change notification settings - Fork 21
/
JUnit.ahk
57 lines (53 loc) · 1.79 KB
/
JUnit.ahk
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;############################
; description: Generate JUnit-XML output for Yunit-Framework (https://github.com/Uberi/Yunit)
;
; author: hoppfrosch
; date: 20170427
;############################
class YunitJUnit{
; implemented according http://stackoverflow.com/questions/4922867/junit-xml-format-specification-that-hudson-supports
__new(instance)
{
this.filename := A_ScriptDir . "\junit.xml"
; the file is deleted if it exists already
if FileExist(this.filename) {
FileDelete % this.filename
}
this.out := {}
this.tests := {}
this.tests.pass := 0
this.tests.fail := 0
this.tests.overall := 0
Return this
}
__Delete() {
file := FileOpen(this.filename, "w")
file.write("<?xml version=""1.0"" encoding=""UTF-8""?>`n")
msg := "<testsuites failures=""" this.tests.fail """ tests=""" this.tests.overall """>"
file.write(msg . "`n")
msg := "`t<testsuite failures=""" this.tests.fail """ tests=""" this.tests.overall """ name=""AHK_YUnit"">"
file.write(msg "`n")
Loop % this.out.Length()
file.write(this.out[A_Index] "`n")
file.write("`t</testsuite>`n")
file.write("</testsuites>`n")
file.close()
}
Update(Category, TestName, Result)
{
this.tests.overall := this.tests.overall + 1
msg := "`t`t<testcase name=""" TestName """ classname=""" Category """"
If IsObject(Result) {
this.out.Push(msg ">")
this.tests.fail := this.tests.fail + 1
msg := "Line #" result.line ": " result.message
this.out.Push("`t`t`t<failure message=""" msg """ type =""failure""></failure>")
this.out.Push("`t`t</testcase>")
}
Else
{
this.out.Push(msg "/>")
this.tests.pass := this.tests.pass + 1
}
}
}