forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFscOptionTests.fs
More file actions
165 lines (140 loc) · 3.99 KB
/
FscOptionTests.fs
File metadata and controls
165 lines (140 loc) · 3.99 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
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace CompilerOptions.Fsc
open Xunit
open FSharp.Test.Compiler
module FscOptionTests =
// --parseonly
[<Fact>]
let ``fsc --parseonly succeeds on valid source`` () =
Fs """printfn "Hello, World" """
|> asExe
|> ignoreWarnings
|> withOptions ["--parseonly"]
|> compile
|> shouldSucceed
|> ignore
[<Fact>]
let ``fsc --parseonly catches parse error`` () =
Fs """let x 1"""
|> asExe
|> ignoreWarnings
|> withOptions ["--parseonly"]
|> compile
|> shouldFail
|> ignore
// --typecheckonly
[<Fact>]
let ``fsc --typecheckonly succeeds on valid source`` () =
Fs """printfn "Hello, World" """
|> asExe
|> ignoreWarnings
|> withOptions ["--typecheckonly"]
|> compile
|> shouldSucceed
|> ignore
[<Fact>]
let ``fsc --typecheckonly catches type error`` () =
Fs """let x: int = "not an int" """
|> asExe
|> ignoreWarnings
|> withOptions ["--typecheckonly"]
|> compile
|> shouldFail
|> withErrorCode 1
|> ignore
// --consolecolors
[<InlineData("--consolecolors")>]
[<InlineData("--consolecolors+")>]
[<InlineData("--consolecolors-")>]
[<Theory>]
let ``fsc --consolecolors switch`` option =
Fs """printfn "Hello, World" """
|> asExe
|> withOptions [option]
|> compile
|> shouldSucceed
|> ignore
// --preferreduilang
[<Fact>]
let ``fsc --preferreduilang en is accepted`` () =
Fs """printfn "Hello, World" """
|> asExe
|> withOptions ["--preferreduilang:en"]
|> compile
|> shouldSucceed
|> ignore
[<Fact>]
let ``fsc --preferreduilang ja is accepted`` () =
Fs """printfn "Hello, World" """
|> asExe
|> withOptions ["--preferreduilang:ja"]
|> compile
|> shouldSucceed
|> ignore
// --abortonerror
[<Fact>]
let ``fsc --abortonerror stops on first error`` () =
Fs """
let x: int = "not an int"
let y: string = 42
"""
|> asExe
|> withOptions ["--abortonerror"]
|> compile
|> shouldFail
|> ignore
// --jit
[<InlineData("--jit+")>]
[<InlineData("--jit-")>]
[<Theory>]
let ``fsc --jit optimization switch`` option =
Fs """printfn "Hello, World" """
|> asExe
|> ignoreWarnings
|> withOptions [option]
|> compile
|> shouldSucceed
|> ignore
// --localoptimize
[<InlineData("--localoptimize+")>]
[<InlineData("--localoptimize-")>]
[<Theory>]
let ``fsc --localoptimize optimization switch`` option =
Fs """printfn "Hello, World" """
|> asExe
|> ignoreWarnings
|> withOptions [option]
|> compile
|> shouldSucceed
|> ignore
// --splitting
[<InlineData("--splitting+")>]
[<InlineData("--splitting-")>]
[<Theory>]
let ``fsc --splitting optimization switch`` option =
Fs """printfn "Hello, World" """
|> asExe
|> ignoreWarnings
|> withOptions [option]
|> compile
|> shouldSucceed
|> ignore
// Error cases
[<Fact>]
let ``fsc --warn with invalid value produces error`` () =
Fs """printfn "Hello, World" """
|> asExe
|> withOptions ["--warn:invalid"]
|> compile
|> shouldFail
|> withDiagnosticMessageMatches "not a valid integer argument"
|> ignore
[<Fact>]
let ``fsc --target with invalid value produces error`` () =
Fs """printfn "Hello, World" """
|> asExe
|> withOptions ["--target:invalid"]
|> compile
|> shouldFail
|> withDiagnosticMessageMatches "Unrecognized target"
|> ignore