diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/Fsc/ParserErrors.fs b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/Fsc/ParserErrors.fs new file mode 100644 index 00000000000..15d896680d5 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/Fsc/ParserErrors.fs @@ -0,0 +1,117 @@ +// 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 + +/// Tests for compiler options parser error handling across many options +module ParserErrors = + + // ================================================================= + // Missing argument — options that require a parameter (error 224) + // ================================================================= + + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + let ``options requiring a parameter produce error 224 when missing`` (option: string) = + Fs """module M""" + |> withOptions [option] + |> compile + |> shouldFail + |> withErrorCode 224 + |> withDiagnosticMessageMatches "Option requires parameter" + |> ignore + + // ================================================================= + // Invalid integer argument — options expecting int get a non-integer + // ================================================================= + + [] + [] + [] + let ``int options with non-integer argument produce error 241`` (option: string) = + Fs """module M""" + |> withOptions [option] + |> compile + |> shouldFail + |> withErrorCode 241 + |> withDiagnosticMessageMatches "is not a valid integer argument" + |> ignore + + // ================================================================= + // Invalid warn level — out of valid range 0-5 + // ================================================================= + + [] + let ``warn with negative level produces error 1050`` () = + Fs """module M""" + |> withOptions ["--warn:-1"] + |> compile + |> shouldFail + |> withErrorCode 1050 + |> withDiagnosticMessageMatches "Invalid warning level" + |> ignore + + // ================================================================= + // Invalid target value + // ================================================================= + + [] + let ``target with unrecognized value produces error 1048`` () = + Fs """module M""" + |> withOptions ["--target:dll"] + |> compile + |> shouldFail + |> withErrorCode 1048 + |> withDiagnosticMessageMatches "Unrecognized target" + |> ignore + + // ================================================================= + // Invalid checksum algorithm + // ================================================================= + + [] + let ``checksumalgorithm with unsupported algorithm produces error 1065`` () = + Fs """module M""" + |> withOptions ["--checksumalgorithm:MD5"] + |> compile + |> shouldFail + |> withErrorCode 1065 + |> withDiagnosticMessageMatches "Algorithm.*is not supported" + |> ignore + + // ================================================================= + // Unrecognized option (error 243) + // ================================================================= + + [] + [] + [] // case-sensitive: --optimize (parsed as --optimize+) works, --Optimize does not + [] + let ``unrecognized options produce error 243`` (option: string) = + Fs """module M""" + |> withOptions [option] + |> compile + |> shouldFail + |> withErrorCode 243 + |> withDiagnosticMessageMatches "Unrecognized option" + |> ignore diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/Fsc/UncoveredOptions.fs b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/Fsc/UncoveredOptions.fs new file mode 100644 index 00000000000..dc0c6e0762f --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/Fsc/UncoveredOptions.fs @@ -0,0 +1,109 @@ +// 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 + +/// Smoke tests for compiler options that have no dedicated test coverage +module UncoveredOptions = + + // ================================================================= + // Switch options (+/-) — verify parser accepts both polarities + // ================================================================= + + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + let ``switch options are accepted by the parser`` (option: string) = + Fs """module M""" + |> withOptions [option] + |> ignoreWarnings + |> typecheck + |> shouldSucceed + |> ignore + + // ================================================================= + // Unit options (no argument) — verify parser accepts them + // ================================================================= + + [] + [] + [] + [] + [] + [] // typecheck only — compile would write .fsi files + [] + [] + let ``unit options are accepted by the parser`` (option: string) = + Fs """module M""" + |> withOptions [option] + |> ignoreWarnings + |> typecheck + |> shouldSucceed + |> ignore + + // ================================================================= + // String options with valid values — verify parser + compilation + // ================================================================= + + [] + [] + [] + let ``checksumalgorithm with valid algorithm is accepted`` (algorithm: string) = + Fs """module M""" + |> withOptions [$"--checksumalgorithm:{algorithm}"] + |> compile + |> shouldSucceed + |> ignore + + [] + [] + [] + [] + [] + let ``target with valid values is accepted`` (option: string) = + Fs """module M""" + |> withOptions [option] + |> ignoreWarnings + |> compile + |> shouldSucceed + |> ignore + + // ================================================================= + // Compilation modes + // ================================================================= + + [] + let ``parseonly does not report type errors`` () = + Fs """let x: int = "not an int" """ + |> asExe + |> withOptions ["--parseonly"] + |> ignoreWarnings + |> compile + |> shouldSucceed + |> ignore + + // ================================================================= + // Diagnostic format options + // ================================================================= + + [] + let ``maxerrors with valid value is accepted`` () = + Fs """module M""" + |> withOptions ["--maxerrors:10"] + |> compile + |> shouldSucceed + |> ignore diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index f5d1048408e..b39533447d5 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -417,6 +417,8 @@ + +