-
Notifications
You must be signed in to change notification settings - Fork 867
Expand file tree
/
Copy pathDependencyManagerLineParserTests.fs
More file actions
200 lines (166 loc) · 7.79 KB
/
Copy pathDependencyManagerLineParserTests.fs
File metadata and controls
200 lines (166 loc) · 7.79 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace FSharp.DependencyManager.UnitTests
open System
open System.Linq
open FSharp.DependencyManager.Nuget
open Xunit
type DependencyManagerLineParserTests() =
let parseBinLogPath text =
let _, binLogPath, _ = FSharpDependencyManager.parsePackageReference ".fsx" [text]
binLogPath
let parseSingleReference text =
let packageReferences, _, _ = FSharpDependencyManager.parsePackageReference ".fsx" [text]
packageReferences.Single()
[<Fact>]
member _.``Binary logging defaults to disabled``() =
let _, binLogPath, _ = FSharpDependencyManager.parsePackageReference ".fsx" []
Assert.Equal(None, binLogPath)
[<Fact>]
member _.``Binary logging can be set to default path``() =
let binLogPath = parseBinLogPath "bl=true"
Assert.Equal(Some (None: string option), binLogPath)
[<Fact>]
member _.``Binary logging can be disabled``() =
let binLogPath = parseBinLogPath "bl=false"
Assert.Equal(None, binLogPath)
[<Fact>]
member _.``Binary logging can be set to specific location``() =
let binLogPath = parseBinLogPath "bl=path/to/file.binlog"
Assert.Equal(Some(Some "path/to/file.binlog"), binLogPath)
[<Fact>]
member _.``Bare binary log argument isn't parsed as a package name: before``() =
let packageReferences, binLogPath, _ = FSharpDependencyManager.parsePackageReference ".fsx" ["bl, MyPackage"]
Assert.Equal("MyPackage", packageReferences.Single().Include)
Assert.Equal(Some (None: string option), binLogPath)
[<Fact>]
member _.``Bare binary log argument isn't parsed as a package name: middle``() =
let packageReferences, binLogPath, _ = FSharpDependencyManager.parsePackageReference ".fsx" ["MyPackage, bl, 1.2.3.4"]
Assert.Equal("MyPackage", packageReferences.Single().Include)
Assert.Equal("1.2.3.4", packageReferences.Single().Version)
Assert.Equal(Some (None: string option), binLogPath)
[<Fact>]
member _.``Bare binary log argument isn't parsed as a package name: after``() =
let packageReferences, binLogPath, _ = FSharpDependencyManager.parsePackageReference ".fsx" ["MyPackage, bl"]
Assert.Equal("MyPackage", packageReferences.Single().Include)
Assert.Equal(Some (None: string option), binLogPath)
[<Fact>]
member _.``Package named 'bl' can be explicitly referenced``() =
let packageReferences, binLogPath, _ = FSharpDependencyManager.parsePackageReference ".fsx" ["Include=bl"]
Assert.Equal("bl", packageReferences.Single().Include)
Assert.Equal(None, binLogPath)
[<Fact>]
member _.``Package named 'bl' can be explicitly referenced with binary logging``() =
let packageReferences, binLogPath, _ = FSharpDependencyManager.parsePackageReference ".fsx" ["Include=bl,bl"]
Assert.Equal("bl", packageReferences.Single().Include)
Assert.Equal(Some (None: string option), binLogPath)
[<Fact>]
member _.``Parse explicitly specified package name``() =
let pr = parseSingleReference "Include=MyPackage"
Assert.Equal("MyPackage", pr.Include)
[<Fact>]
member _.``Parse implicitly specified package name``() =
let pr = parseSingleReference "MyPackage"
Assert.Equal("MyPackage", pr.Include)
[<Fact>]
member _.``Parse version number``() =
let pr = parseSingleReference "MyPackage, Version=1.2.3.4"
Assert.Equal("1.2.3.4", pr.Version)
[<Fact>]
member _.``Parse implicitly specified package name and implicitly specified version number``() =
let pr = parseSingleReference "MyPackage, 1.2.3.4"
Assert.Equal("MyPackage", pr.Include)
Assert.Equal("1.2.3.4", pr.Version)
[<Fact>]
member _.``Parse single restore source``() =
let pr = parseSingleReference "MyPackage, RestoreSources=MyRestoreSource"
Assert.Equal("MyRestoreSource", pr.RestoreSources)
[<Fact>]
member _.``Parse multiple restore sources``() =
let pr = parseSingleReference "MyPackage, RestoreSources=MyRestoreSource1, RestoreSources=MyRestoreSource2"
Assert.Equal("MyRestoreSource1;MyRestoreSource2", pr.RestoreSources)
[<Fact>]
member _.``Parse script``() =
let pr = parseSingleReference "MyPackage, Script=SomeScript"
Assert.Equal("SomeScript", pr.Script)
[<Fact>]
member _.``Include strings that look different but parse the same are reduced to a single item``() =
let prs, _, _ =
[ "MyPackage, Version=1.2.3.4"
"Include=MyPackage, Version=1.2.3.4" ]
|> FSharpDependencyManager.parsePackageReference ".fsx"
let pr = prs.Single()
Assert.Equal("MyPackage", pr.Include)
[<Fact>]
member _.``Timeout none is -1``() =
let _, _, timeout =
[ "timeout=none" ]
|> FSharpDependencyManager.parsePackageReference ".fsx"
Assert.Equal(timeout, Some -1)
[<Fact>]
member _.``Timeout 1000 is 1000``() =
let _, _, timeout =
[ "timeout=1000" ]
|> FSharpDependencyManager.parsePackageReference ".fsx"
Assert.Equal(timeout, Some 1000)
[<Fact>]
member _.``Timeout 0 is 0``() =
let _, _, timeout =
[ "timeout=0" ]
|> FSharpDependencyManager.parsePackageReference ".fsx"
Assert.Equal(timeout, Some 0)
[<Fact>]
member _.``Timeout for many values is the last specified ascending``() =
let _, _, timeout =
[ "timeout=none"
"timeout=1"
"timeout=10"
"timeout=100"
]
|> FSharpDependencyManager.parsePackageReference ".fsx"
Assert.Equal(timeout, Some 100)
[<Fact>]
member _.``Timeout for many values is the last specified descending``() =
let _, _, timeout =
[ "timeout=10000"
"timeout=1000"
"timeout=100"
"timeout=10"
]
|> FSharpDependencyManager.parsePackageReference ".fsx"
Assert.Equal(timeout, Some 10)
[<Fact>]
member _.``Timeout invalid : timeout``() =
try
[ "timeout" ]
|> FSharpDependencyManager.parsePackageReference ".fsx" |> ignore
Assert.True(false, "ArgumentException expected") //Assert.Fail
with
| :? ArgumentException -> ()
| _ -> Assert.True(false, "ArgumentException expected") //Assert.Fail
[<Fact>]
member _.``Timeout invalid timeout=``() =
try
[ "timeout=" ]
|> FSharpDependencyManager.parsePackageReference ".fsx" |> ignore
Assert.True(false, "ArgumentException expected") //Assert.Fail
with
| :? ArgumentException -> ()
| _ -> Assert.True(false, "ArgumentException expected") //Assert.Fail
[<Fact>]
member _.``Timeout invalid timeout=nonesuch``() =
try
[ "timeout=nonesuch" ]
|> FSharpDependencyManager.parsePackageReference ".fsx" |> ignore
Assert.True(false, "ArgumentException expected") //Assert.Fail
with
| :? ArgumentException -> ()
| _ -> Assert.True(false, "ArgumentException expected") //Assert.Fail
[<Fact>]
member _.``Timeout invalid timeout=-20``() =
try
[ "timeout=-20" ]
|> FSharpDependencyManager.parsePackageReference ".fsx" |> ignore
Assert.True(false, "ArgumentException expected") //Assert.Fail
with
| :? ArgumentException -> ()
| _ -> Assert.True(false, "ArgumentException expected") //Assert.Fail