|
| 1 | +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. |
| 2 | + |
| 3 | +namespace CompilerOptions.Fsc |
| 4 | + |
| 5 | +open Xunit |
| 6 | +open FSharp.Test.Compiler |
| 7 | + |
| 8 | +module FscOptionTests = |
| 9 | + |
| 10 | + // --parseonly |
| 11 | + |
| 12 | + [<Fact>] |
| 13 | + let ``fsc --parseonly succeeds on valid source`` () = |
| 14 | + Fs """printfn "Hello, World" """ |
| 15 | + |> asExe |
| 16 | + |> ignoreWarnings |
| 17 | + |> withOptions ["--parseonly"] |
| 18 | + |> compile |
| 19 | + |> shouldSucceed |
| 20 | + |> ignore |
| 21 | + |
| 22 | + [<Fact>] |
| 23 | + let ``fsc --parseonly catches parse error`` () = |
| 24 | + Fs """let x 1""" |
| 25 | + |> asExe |
| 26 | + |> ignoreWarnings |
| 27 | + |> withOptions ["--parseonly"] |
| 28 | + |> compile |
| 29 | + |> shouldFail |
| 30 | + |> ignore |
| 31 | + |
| 32 | + // --typecheckonly |
| 33 | + |
| 34 | + [<Fact>] |
| 35 | + let ``fsc --typecheckonly succeeds on valid source`` () = |
| 36 | + Fs """printfn "Hello, World" """ |
| 37 | + |> asExe |
| 38 | + |> ignoreWarnings |
| 39 | + |> withOptions ["--typecheckonly"] |
| 40 | + |> compile |
| 41 | + |> shouldSucceed |
| 42 | + |> ignore |
| 43 | + |
| 44 | + [<Fact>] |
| 45 | + let ``fsc --typecheckonly catches type error`` () = |
| 46 | + Fs """let x: int = "not an int" """ |
| 47 | + |> asExe |
| 48 | + |> ignoreWarnings |
| 49 | + |> withOptions ["--typecheckonly"] |
| 50 | + |> compile |
| 51 | + |> shouldFail |
| 52 | + |> withErrorCode 1 |
| 53 | + |> ignore |
| 54 | + |
| 55 | + // --consolecolors |
| 56 | + |
| 57 | + [<InlineData("--consolecolors")>] |
| 58 | + [<InlineData("--consolecolors+")>] |
| 59 | + [<InlineData("--consolecolors-")>] |
| 60 | + [<Theory>] |
| 61 | + let ``fsc --consolecolors switch`` option = |
| 62 | + Fs """printfn "Hello, World" """ |
| 63 | + |> asExe |
| 64 | + |> withOptions [option] |
| 65 | + |> compile |
| 66 | + |> shouldSucceed |
| 67 | + |> ignore |
| 68 | + |
| 69 | + // --preferreduilang |
| 70 | + |
| 71 | + [<Fact>] |
| 72 | + let ``fsc --preferreduilang en is accepted`` () = |
| 73 | + Fs """printfn "Hello, World" """ |
| 74 | + |> asExe |
| 75 | + |> withOptions ["--preferreduilang:en"] |
| 76 | + |> compile |
| 77 | + |> shouldSucceed |
| 78 | + |> ignore |
| 79 | + |
| 80 | + [<Fact>] |
| 81 | + let ``fsc --preferreduilang ja is accepted`` () = |
| 82 | + Fs """printfn "Hello, World" """ |
| 83 | + |> asExe |
| 84 | + |> withOptions ["--preferreduilang:ja"] |
| 85 | + |> compile |
| 86 | + |> shouldSucceed |
| 87 | + |> ignore |
| 88 | + |
| 89 | + // --abortonerror |
| 90 | + |
| 91 | + [<Fact>] |
| 92 | + let ``fsc --abortonerror stops on first error`` () = |
| 93 | + Fs """ |
| 94 | +let x: int = "not an int" |
| 95 | +let y: string = 42 |
| 96 | + """ |
| 97 | + |> asExe |
| 98 | + |> withOptions ["--abortonerror"] |
| 99 | + |> compile |
| 100 | + |> shouldFail |
| 101 | + |> ignore |
| 102 | + |
| 103 | + // --jit |
| 104 | + |
| 105 | + [<InlineData("--jit+")>] |
| 106 | + [<InlineData("--jit-")>] |
| 107 | + [<Theory>] |
| 108 | + let ``fsc --jit optimization switch`` option = |
| 109 | + Fs """printfn "Hello, World" """ |
| 110 | + |> asExe |
| 111 | + |> ignoreWarnings |
| 112 | + |> withOptions [option] |
| 113 | + |> compile |
| 114 | + |> shouldSucceed |
| 115 | + |> ignore |
| 116 | + |
| 117 | + // --localoptimize |
| 118 | + |
| 119 | + [<InlineData("--localoptimize+")>] |
| 120 | + [<InlineData("--localoptimize-")>] |
| 121 | + [<Theory>] |
| 122 | + let ``fsc --localoptimize optimization switch`` option = |
| 123 | + Fs """printfn "Hello, World" """ |
| 124 | + |> asExe |
| 125 | + |> ignoreWarnings |
| 126 | + |> withOptions [option] |
| 127 | + |> compile |
| 128 | + |> shouldSucceed |
| 129 | + |> ignore |
| 130 | + |
| 131 | + // --splitting |
| 132 | + |
| 133 | + [<InlineData("--splitting+")>] |
| 134 | + [<InlineData("--splitting-")>] |
| 135 | + [<Theory>] |
| 136 | + let ``fsc --splitting optimization switch`` option = |
| 137 | + Fs """printfn "Hello, World" """ |
| 138 | + |> asExe |
| 139 | + |> ignoreWarnings |
| 140 | + |> withOptions [option] |
| 141 | + |> compile |
| 142 | + |> shouldSucceed |
| 143 | + |> ignore |
| 144 | + |
| 145 | + // Error cases |
| 146 | + |
| 147 | + [<Fact>] |
| 148 | + let ``fsc --warn with invalid value produces error`` () = |
| 149 | + Fs """printfn "Hello, World" """ |
| 150 | + |> asExe |
| 151 | + |> withOptions ["--warn:invalid"] |
| 152 | + |> compile |
| 153 | + |> shouldFail |
| 154 | + |> withDiagnosticMessageMatches "not a valid integer argument" |
| 155 | + |> ignore |
| 156 | + |
| 157 | + [<Fact>] |
| 158 | + let ``fsc --target with invalid value produces error`` () = |
| 159 | + Fs """printfn "Hello, World" """ |
| 160 | + |> asExe |
| 161 | + |> withOptions ["--target:invalid"] |
| 162 | + |> compile |
| 163 | + |> shouldFail |
| 164 | + |> withDiagnosticMessageMatches "Unrecognized target" |
| 165 | + |> ignore |
0 commit comments