diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/FscOptionTests.fs b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/FscOptionTests.fs new file mode 100644 index 00000000000..7b46bbd9d7e --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/FscOptionTests.fs @@ -0,0 +1,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 + + [] + let ``fsc --parseonly succeeds on valid source`` () = + Fs """printfn "Hello, World" """ + |> asExe + |> ignoreWarnings + |> withOptions ["--parseonly"] + |> compile + |> shouldSucceed + |> ignore + + [] + let ``fsc --parseonly catches parse error`` () = + Fs """let x 1""" + |> asExe + |> ignoreWarnings + |> withOptions ["--parseonly"] + |> compile + |> shouldFail + |> ignore + + // --typecheckonly + + [] + let ``fsc --typecheckonly succeeds on valid source`` () = + Fs """printfn "Hello, World" """ + |> asExe + |> ignoreWarnings + |> withOptions ["--typecheckonly"] + |> compile + |> shouldSucceed + |> ignore + + [] + let ``fsc --typecheckonly catches type error`` () = + Fs """let x: int = "not an int" """ + |> asExe + |> ignoreWarnings + |> withOptions ["--typecheckonly"] + |> compile + |> shouldFail + |> withErrorCode 1 + |> ignore + + // --consolecolors + + [] + [] + [] + [] + let ``fsc --consolecolors switch`` option = + Fs """printfn "Hello, World" """ + |> asExe + |> withOptions [option] + |> compile + |> shouldSucceed + |> ignore + + // --preferreduilang + + [] + let ``fsc --preferreduilang en is accepted`` () = + Fs """printfn "Hello, World" """ + |> asExe + |> withOptions ["--preferreduilang:en"] + |> compile + |> shouldSucceed + |> ignore + + [] + let ``fsc --preferreduilang ja is accepted`` () = + Fs """printfn "Hello, World" """ + |> asExe + |> withOptions ["--preferreduilang:ja"] + |> compile + |> shouldSucceed + |> ignore + + // --abortonerror + + [] + 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 + + [] + [] + [] + let ``fsc --jit optimization switch`` option = + Fs """printfn "Hello, World" """ + |> asExe + |> ignoreWarnings + |> withOptions [option] + |> compile + |> shouldSucceed + |> ignore + + // --localoptimize + + [] + [] + [] + let ``fsc --localoptimize optimization switch`` option = + Fs """printfn "Hello, World" """ + |> asExe + |> ignoreWarnings + |> withOptions [option] + |> compile + |> shouldSucceed + |> ignore + + // --splitting + + [] + [] + [] + let ``fsc --splitting optimization switch`` option = + Fs """printfn "Hello, World" """ + |> asExe + |> ignoreWarnings + |> withOptions [option] + |> compile + |> shouldSucceed + |> ignore + + // Error cases + + [] + 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 + + [] + let ``fsc --target with invalid value produces error`` () = + Fs """printfn "Hello, World" """ + |> asExe + |> withOptions ["--target:invalid"] + |> compile + |> shouldFail + |> withDiagnosticMessageMatches "Unrecognized target" + |> ignore diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index f236ca6599d..7b707f5d1e5 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -306,6 +306,7 @@ +