Skip to content

Commit a7c3667

Browse files
committed
Merge branch 'dev'
2 parents 06af46e + 7491b7e commit a7c3667

35 files changed

+1585
-1191
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ build/
66
testrunner/
77
[Oo]bj/
88
[Bb]in/
9+
[Bb]ackup/
910
_ReSharper*/
1011
_UpgradeReport*
1112

XakeLibTests/ActionTests.fs

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
module ``action block allows``
2+
3+
open NUnit.Framework
4+
open Xake
5+
6+
7+
let makeStringList() = new System.Collections.Generic.List<string>()
8+
let DebugOptions = {ExecOptions.Default with FailOnError = true; FileLog = ""}
9+
10+
[<Test>]
11+
let ``executes the body``() =
12+
13+
let wasExecuted = ref false
14+
15+
do xake DebugOptions {
16+
phony "main" (action {
17+
wasExecuted := true
18+
})
19+
}
20+
21+
Assert.IsTrue(!wasExecuted)
22+
23+
[<Test>]
24+
let ``execution is ordered``() =
25+
26+
let wasExecuted = ref false
27+
28+
let errorlist = makeStringList()
29+
let note = errorlist.Add
30+
31+
do xake DebugOptions {
32+
phony "main" (action {
33+
do note "1"
34+
wasExecuted := true
35+
do note "2"
36+
})
37+
}
38+
39+
do note "3"
40+
41+
Assert.IsTrue(!wasExecuted)
42+
Assert.That(errorlist, Is.EquivalentTo(["1"; "2"; "3"]))
43+
44+
[<Test>]
45+
let ``allows async operations``() =
46+
47+
let wasExecuted = ref false
48+
49+
let errorlist = makeStringList()
50+
let note = errorlist.Add
51+
52+
do xake DebugOptions {
53+
phony "main" (action {
54+
do! async {note "1"}
55+
wasExecuted := true
56+
do! async {note "2"}
57+
do note "3"
58+
})
59+
}
60+
61+
do note "4"
62+
63+
Assert.IsTrue(!wasExecuted)
64+
Assert.That(errorlist, Is.EqualTo(["1"; "2"; "3"; "4"]))
65+
66+
[<Test>]
67+
let ``do! action``() =
68+
69+
let wasExecuted = ref false
70+
71+
let errorlist = makeStringList()
72+
let note = errorlist.Add
73+
74+
let noteAction t = action {do note t}
75+
76+
do xake DebugOptions {
77+
phony "main" (action {
78+
do! noteAction "1"
79+
wasExecuted := true
80+
do! noteAction "2"
81+
do note "3"
82+
})
83+
}
84+
85+
do note "4"
86+
87+
Assert.IsTrue(!wasExecuted)
88+
Assert.That(errorlist, Is.EqualTo(["1"; "2"; "3"; "4"]))
89+
90+
91+
[<Test>]
92+
let ``do! action with result ignored``() =
93+
94+
let wasExecuted = ref false
95+
96+
let errorlist = makeStringList()
97+
let note = errorlist.Add
98+
99+
let testee t =
100+
action {
101+
do note t
102+
return t
103+
}
104+
105+
do xake DebugOptions {
106+
phony "main" (action {
107+
do! (testee "1") |> Action.Ignore
108+
wasExecuted := true
109+
do! testee "2" |> Action.Ignore
110+
do note "3"
111+
})
112+
}
113+
114+
do note "4"
115+
116+
Assert.IsTrue(!wasExecuted)
117+
Assert.That(errorlist, Is.EqualTo(["1"; "2"; "3"; "4"] |> List.toArray))
118+
119+
120+
[<Test>]
121+
let ``let! returning value``() =
122+
123+
let errorlist = makeStringList()
124+
let note = errorlist.Add
125+
126+
let testee t =
127+
action {
128+
return t
129+
}
130+
131+
do xake DebugOptions {
132+
phony "main" (action {
133+
let! s1 = testee "1"
134+
do note s1
135+
let! s2 = testee ("2+" + s1)
136+
do note s2
137+
do note "3"
138+
})
139+
}
140+
141+
Assert.That(errorlist, Is.EqualTo(["1"; "2+1"; "3"] |> List.toArray))
142+
143+
[<Test>]
144+
let ``if of various kinds``() =
145+
146+
let errorlist = makeStringList()
147+
let note = errorlist.Add
148+
149+
let iif f a b =
150+
action {
151+
return if f then a else b
152+
}
153+
154+
do xake DebugOptions {
155+
phony "main" (action {
156+
if true then
157+
do note "i1-t"
158+
else
159+
do note "i1-f"
160+
161+
if false then
162+
()
163+
else
164+
do note "i2-f"
165+
166+
let! s1 = iif true "2" "2f"
167+
let! s1 = if s1 = "2" then iif true "2" "2f" else action {return "2"}
168+
do note s1
169+
do note "3"
170+
})
171+
}
172+
173+
Assert.That(errorlist, Is.EqualTo(["i1-t"; "i2-f"; "2"; "3"] |> List.toArray))
174+
175+
[<Test>]
176+
let ``if without else``() =
177+
178+
let errorlist = makeStringList()
179+
let note = errorlist.Add
180+
181+
let iif f a b =
182+
action {
183+
return if f then a else b
184+
}
185+
186+
do xake DebugOptions {
187+
188+
phony "main" (action {
189+
if true then
190+
do note "i1-t"
191+
192+
let! s1 = iif true "2" "2f"
193+
if s1 = "2" then
194+
do note "3"
195+
196+
for _ in [1..5] do
197+
()
198+
199+
do note "4"
200+
})
201+
}
202+
203+
Assert.That(errorlist, Is.EqualTo(["i1-t"; "3"; "4"] |> List.toArray))
204+
205+
[<Test>]
206+
let ``for and while``() =
207+
208+
let errorlist = makeStringList()
209+
let note = errorlist.Add
210+
211+
do xake DebugOptions {
212+
213+
phony "main" (action {
214+
215+
let! s1 = action {return "122"}
216+
let s2 = s1
217+
do note "1"
218+
219+
for i in [1..3] do
220+
do! trace Info "%A" i
221+
do note (sprintf "i=%i" i)
222+
223+
let j = ref 3
224+
while !j < 5 do
225+
do note (sprintf "j=%i" !j)
226+
j := !j + 1
227+
228+
do note "4"
229+
})
230+
}
231+
232+
Assert.That(errorlist, Is.EqualTo(["1"; "i=1"; "i=2"; "i=3"; "j=3"; "j=4"; "4"] |> List.toArray))
233+
234+
[<Test; Explicit>]
235+
let ``try catch finally``() =
236+
237+
let errorlist = makeStringList()
238+
let note = errorlist.Add
239+
240+
do xake DebugOptions {
241+
242+
phony "main" (action {
243+
244+
let! s1 = action {return "122"}
245+
do note s1
246+
247+
note "before try"
248+
249+
// try
250+
// printfn "Body executed"
251+
// do note "try"
252+
// finally
253+
// printfn "Finally executed"
254+
// do note "finally"
255+
256+
// try
257+
// failwith "ee"
258+
// with e ->
259+
// do note e.Message
260+
261+
do note "4"
262+
})
263+
}
264+
265+
// "2222"; "ee";
266+
printfn "%A" errorlist
267+
Assert.That(errorlist, Is.EqualTo(["122"; "try"; "finally"; "4"] |> List.toArray))
268+
269+
// TODO use!, try with exception within action
270+

XakeLibTests/CommandLineTests.fs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ open NUnit.Framework
55

66
open Xake
77

8-
[<TestFixture (Description = "Command line tests")>]
9-
type CommandLineTests() =
8+
[<TestFixture>]
9+
type ``Command line interface``() =
1010

1111
let currentDir = Path.Combine (__SOURCE_DIRECTORY__, "../bin")
12+
let XakeOptions = ExecOptions.Default
1213

13-
[<Test (Description = "Verifies reading common switches")>]
14-
member test.AcceptKnownSwitches() =
14+
[<Test>]
15+
member test.``accepts various switches``() =
1516

1617
let scriptOptions = ref XakeOptions
1718
let args =
@@ -37,8 +38,8 @@ type CommandLineTests() =
3738
Assert.AreEqual(Verbosity.Loud, finalOptions.ConLogLevel)
3839
Assert.AreEqual([("AA", "BBB"); ("AA1", "CCC")], finalOptions.Vars)
3940

40-
[<Test (Description = "Verifies reading target list")>]
41-
member test.ReadsTargets() =
41+
[<Test>]
42+
member test.``reads target lists``() =
4243

4344
let scriptOptions = ref XakeOptions
4445
let executed2 = ref false
@@ -63,17 +64,17 @@ type CommandLineTests() =
6364
Assert.IsTrue !executed2
6465

6566

66-
[<Test (Description = "Verifies reading incorrect"); Ignore>]
67-
member test.WarnsOnIncorrectSwitch() =
67+
[<Test; Ignore>]
68+
member test.``warns on incorrect switch``() =
6869

6970
do xakeArgs ["/xxx"] XakeOptions {
7071
want ["ss"]
7172
}
7273

7374
//raise <| new System.NotImplementedException()
7475

75-
[<Test (Description = "Verifies that command line is ignored when Ignore option is set")>]
76-
member test.IgnoresCommandLine() =
76+
[<Test>]
77+
member test.``supports ignoring command line``() =
7778

7879
let scriptOptions = ref XakeOptions
7980
let args =

XakeLibTests/FileTasksTests.fs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ open Xake.FileTasks
1010
open Xake.Storage
1111

1212
[<TestFixture>]
13-
type FileTasksTests() =
13+
type ``File tasks module``() =
1414

15-
let TestOptions = {XakeOptions with Threads = 1; Targets = ["main"]; ConLogLevel = Chatty; FileLogLevel = Silent}
15+
let TestOptions = {ExecOptions.Default with Threads = 1; Targets = ["main"]; ConLogLevel = Chatty; FileLogLevel = Silent}
1616

1717
[<Test>]
18-
member this.DeleteSimple() =
18+
member this.``allows delete file``() =
1919
"." </> ".xake" |> File.Delete
2020

2121
let execCount = ref 0
@@ -38,7 +38,7 @@ type FileTasksTests() =
3838
Assert.IsFalse <| File.Exists ("samplefile")
3939

4040
[<Test>]
41-
member this.DeleteByMask() =
41+
member this.``allows delete file by mask``() =
4242
"." </> ".xake" |> File.Delete
4343
let execCount = ref 0
4444

@@ -61,7 +61,7 @@ type FileTasksTests() =
6161
["$$1"; "$$2"] |> List.iter (Assert.IsFalse << File.Exists)
6262

6363
[<Test>]
64-
member this.DeleteMany() =
64+
member this.``allows to delete by several masks``() =
6565
"." </> ".xake" |> File.Delete
6666
do xake TestOptions {
6767
rules [
@@ -80,14 +80,14 @@ type FileTasksTests() =
8080
["$aa"; "$bb"] |> List.iter (Assert.IsFalse << File.Exists)
8181

8282
[<Test>]
83-
member this.CopySimple() =
83+
member this.``supports simple file copy``() =
8484
"." </> ".xake" |> File.Delete
8585
do xake TestOptions {
8686
rules [
8787
"main" => action {
88-
do! writeLog Error "Running inside 'main' rule"
88+
do! trace Error "Running inside 'main' rule"
8989
do! need ["aaa"; "clean"]
90-
do! cp "aaa" "aaa-copy"
90+
do! copyFile "aaa" "aaa-copy"
9191
}
9292

9393
"clean" => action {

0 commit comments

Comments
 (0)