1
1
open System
2
- open NUnit.Engine
3
2
open System.Reflection
4
3
open System.Xml
5
4
open System.Globalization
6
5
6
+ open NUnit.Engine
7
+
8
+ type TestResult = Unknown | Passed | Failed
9
+
7
10
[<EntryPoint>]
8
11
let main argv =
9
-
10
12
let GetAttribute ( node : XmlNode ) ( name : string ): string option =
11
13
match node with
12
14
| null -> None
13
- | elem -> match node .Attributes.[ name] with
15
+ | elem -> match elem .Attributes.[ name] with
14
16
| null -> None
15
17
| a -> Some( a.Value)
16
18
@@ -27,7 +29,15 @@ let main argv =
27
29
28
30
let escapeLF ( s : string ): string = s.Replace( Environment.NewLine, " <:LF:>" )
29
31
30
- let OnTestCase ( testCase : XmlNode ) =
32
+ let GetSuiteResult ( testResults : TestResult seq ) =
33
+ let GetResultScore ( result : TestResult ): int =
34
+ match result with
35
+ | Passed -> 0
36
+ | Unknown -> 1
37
+ | Failed -> 2
38
+ if Seq.isEmpty testResults then Unknown else Seq.maxBy GetResultScore testResults
39
+
40
+ let OnTestCase ( testCase : XmlNode ): TestResult =
31
41
32
42
GetDescription testCase
33
43
|> Option.orElse ( GetAttribute testCase " name" )
@@ -38,77 +48,94 @@ let main argv =
38
48
|> Option.ofObj
39
49
|> Option.iter ( fun node -> printfn " %s " node.InnerText)
40
50
41
- match GetAttribute testCase " result" with
42
- | Some( " Passed" ) -> printfn " \n <PASSED::>Test Passed"
43
- | Some( " Failed" ) ->
44
- let label = GetAttribute testCase " label"
45
- let message = Option.ofObj <| testCase.SelectSingleNode " failure/message"
46
- match label with
47
- | Some( " Error" ) ->
48
- message
49
- |> Option.map ( fun m -> escapeLF( m.InnerText))
50
- |> Option.defaultValue " Unknown Error"
51
- |> printfn " \n <ERROR::>%s "
52
-
53
- testCase.SelectSingleNode " failure/stack-trace"
54
- |> Option.ofObj
55
- |> Option.iter ( fun node -> printfn " \n <LOG::-Stack Trace>%s " node.InnerText)
56
- | _ ->
57
- message
58
- |> Option.map ( fun msg -> " <:LF:>" + escapeLF msg.InnerText)
59
- |> Option.defaultValue " "
60
- |> printfn " \n <FAILED::>Test Failed%s "
61
- | _ -> ()
51
+ let testCaseResult =
52
+ match GetAttribute testCase " result" with
53
+ | Some( " Passed" ) ->
54
+ printfn " \n <PASSED::>Test Passed"
55
+ Passed
56
+ | Some( " Failed" ) ->
57
+ let label = GetAttribute testCase " label"
58
+ let message = Option.ofObj <| testCase.SelectSingleNode " failure/message"
59
+ match label with
60
+ | Some( " Error" ) ->
61
+ message
62
+ |> Option.map ( fun m -> escapeLF( m.InnerText))
63
+ |> Option.defaultValue " Unknown Error"
64
+ |> printfn " \n <ERROR::>%s "
65
+
66
+ testCase.SelectSingleNode " failure/stack-trace"
67
+ |> Option.ofObj
68
+ |> Option.iter ( fun node -> printfn " \n <LOG::-Stack Trace>%s " node.InnerText)
69
+ | _ ->
70
+ message
71
+ |> Option.map ( fun msg -> " <:LF:>" + escapeLF msg.InnerText)
72
+ |> Option.defaultValue " "
73
+ |> printfn " \n <FAILED::>Test Failed%s "
74
+ Failed
75
+ | _ -> Unknown
62
76
WriteCompletedIn testCase
77
+ testCaseResult
63
78
64
-
65
- let rec OnTestSuiteTestFixture ( testFixture : XmlNode ) =
66
-
79
+ let rec OnTestSuiteTestFixture ( testFixture : XmlNode ): TestResult =
67
80
GetDescription testFixture
68
81
|> Option.orElse ( GetAttribute testFixture " name" )
69
82
|> Option.defaultValue " "
70
83
|> printfn " \n <DESCRIBE::>%s "
71
84
72
- for child in testFixture.ChildNodes do
73
- match child.Name with
74
- | " test-suite" ->
75
- match GetAttribute child " type" with
76
- | Some( " ParameterizedMethod" | " GenericMethod" ) -> OnTestSuiteTestFixture( child)
77
- | _ -> ()
78
- | " test-case" -> OnTestCase( child)
79
- | _ -> ()
80
- WriteCompletedIn( testFixture);
81
-
82
- let rec OnTestSuiteTestSuite ( testSuite : XmlNode ) =
85
+ let suiteResult =
86
+ testFixture.ChildNodes
87
+ |> Seq.cast< XmlNode> |> Seq.toList
88
+ |> List.map ( fun child ->
89
+ match child.Name with
90
+ | " test-suite" ->
91
+ match GetAttribute child " type" with
92
+ | Some( " ParameterizedMethod" | " GenericMethod" ) -> OnTestSuiteTestFixture( child)
93
+ | _ -> Passed
94
+ | " test-case" -> OnTestCase( child)
95
+ | _ -> Passed )
96
+ |> GetSuiteResult
97
+ WriteCompletedIn( testFixture)
98
+ suiteResult
99
+
100
+ let rec OnTestSuiteTestSuite ( testSuite : XmlNode ): TestResult =
83
101
84
102
GetDescription testSuite
85
103
|> Option.orElse ( GetAttribute testSuite " name" )
86
104
|> Option.defaultValue " "
87
105
|> printfn " \n <DESCRIBE::>%s "
88
106
89
- for child in testSuite.SelectNodes " test-suite" do
90
- match GetAttribute child " type" with
91
- | Some( " TestFixture" ) -> OnTestSuiteTestFixture( child)
92
- | _ -> OnTestSuiteTestSuite( child)
107
+ let suiteResult =
108
+ testSuite.SelectNodes " test-suite"
109
+ |> Seq.cast< XmlElement> |> Seq.toList
110
+ |> List.map ( fun child ->
111
+ match GetAttribute child " type" with
112
+ | Some( " TestFixture" ) -> OnTestSuiteTestFixture( child)
113
+ | _ -> OnTestSuiteTestSuite( child) )
114
+ |> GetSuiteResult
115
+
116
+ WriteCompletedIn( testSuite)
93
117
94
- WriteCompletedIn ( testSuite );
118
+ suiteResult
95
119
96
120
97
- let OnTestSuiteAssembly ( testSuite : XmlNode ) =
98
- for child in testSuite.SelectNodes " test-suite" do
121
+ let OnTestSuiteAssembly ( testSuite : XmlNode ): TestResult =
122
+ testSuite.SelectNodes " test-suite"
123
+ |> Seq.cast< XmlElement> |> Seq.toList
124
+ |> List.map ( fun child ->
99
125
match GetAttribute child " type" with
100
126
| Some( " TestFixture" ) -> OnTestSuiteTestFixture( child)
101
- | _ -> OnTestSuiteTestSuite( child)
127
+ | _ -> OnTestSuiteTestSuite( child) )
128
+ |> GetSuiteResult
129
+
102
130
103
- let reportRun ( reportNode : XmlNode ) =
131
+ let reportRun ( reportNode : XmlNode ): TestResult =
104
132
reportNode.SelectSingleNode " test-suite[@type = 'Assembly']"
105
133
|> Option.ofObj
106
- |> Option.iter OnTestSuiteAssembly
134
+ |> Option.map OnTestSuiteAssembly
135
+ |> Option.defaultValue Unknown
107
136
108
137
let testpkg = new TestPackage ( Assembly.GetExecutingAssembly() .Location)
109
138
let engine = new TestEngine()
110
139
use runner = engine.GetRunner( testpkg)
111
140
let reportNode = runner.Run( null , TestFilter.Empty)
112
- // TODO Exit code
113
- reportRun( reportNode)
114
- 0
141
+ if reportRun( reportNode) = Passed then 0 else 1
0 commit comments