diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/help/help40.437.1033.bsl b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/misc/compiler_help_output.bsl similarity index 50% rename from tests/fsharpqa/Source/CompilerOptions/fsc/help/help40.437.1033.bsl rename to tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/misc/compiler_help_output.bsl index 193f7d70cb6..90ec39abd82 100644 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/help/help40.437.1033.bsl +++ b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/misc/compiler_help_output.bsl @@ -1,58 +1,38 @@ -Microsoft (R) F# Compiler version 12.0.0.0 for F# 6.0 +Microsoft (R) F# Compiler version 12.5.0.0 for F# 7.0 Copyright (c) Microsoft Corporation. All Rights Reserved. - OUTPUT FILES - ---out: Name of the output file (Short form: - -o) +--out: Name of the output file (Short form: -o) --target:exe Build a console executable --target:winexe Build a Windows executable --target:library Build a library (Short form: -a) ---target:module Build a module that can be added to - another assembly ---delaysign[+|-] Delay-sign the assembly using only - the public portion of the strong - name key ---publicsign[+|-] Public-sign the assembly using only - the public portion of the strong - name key, and mark the assembly as - signed ---doc: Write the xmldoc of the assembly to - the given file +--target:module Build a module that can be added to another assembly +--delaysign[+|-] Delay-sign the assembly using only the public portion of the strong name key +--publicsign[+|-] Public-sign the assembly using only the public portion of the strong name + key, and mark the assembly as signed +--doc: Write the xmldoc of the assembly to the given file --keyfile: Specify a strong name key file ---platform: Limit which platforms this code can - run on: x86, x64, Arm, Arm64, - Itanium, anycpu32bitpreferred, or - anycpu. The default is anycpu. ---compressmetadata[+|-] Compress interface and optimization - data files ---nooptimizationdata Only include optimization - information essential for - implementing inlined constructs. - Inhibits cross-module inlining but - improves binary compatibility. ---nointerfacedata Don't add a resource to the - generated assembly containing - F#-specific metadata ---sig: Print the inferred interface of the - assembly to a file ---allsigs Print the inferred interfaces of all - compilation files to associated +--platform: Limit which platforms this code can run on: x86, x64, Arm, Arm64, Itanium, + anycpu32bitpreferred, or anycpu. The default is anycpu. +--compressmetadata[+|-] Compress interface and optimization data files +--nooptimizationdata Only include optimization information essential for implementing inlined + constructs. Inhibits cross-module inlining but improves binary + compatibility. +--nointerfacedata Don't add a resource to the generated assembly containing F#-specific + metadata +--sig: Print the inferred interface of the assembly to a file +--allsigs Print the inferred interfaces of all compilation files to associated signature files ---nocopyfsharpcore Don't copy FSharp.Core.dll along the - produced binaries ---refonly[+|-] Produce a reference assembly, - instead of a full assembly, as the - primary output ---refout: Produce a reference assembly with - the specified file path. +--nocopyfsharpcore Don't copy FSharp.Core.dll along the produced binaries +--refonly[+|-] Produce a reference assembly, instead of a full assembly, as the primary + output +--refout: Produce a reference assembly with the specified file path. - INPUT FILES - ---reference: Reference an assembly (Short form: - -r) ---compilertool: Reference an assembly or directory - containing a design time tool (Short +--reference: Reference an assembly (Short form: -r) +--compilertool: Reference an assembly or directory containing a design time tool (Short form: -t) @@ -60,45 +40,28 @@ Copyright (c) Microsoft Corporation. All Rights Reserved. --win32icon: Specify a Win32 icon file (.ico) --win32res: Specify a Win32 resource file (.res) --win32manifest: Specify a Win32 manifest file ---nowin32manifest Do not include the default Win32 - manifest +--nowin32manifest Do not include the default Win32 manifest --resource: Embed the specified managed resource ---linkresource: Link the specified resource to this - assembly where the resinfo format is - [,[,public|private]] +--linkresource: Link the specified resource to this assembly where the resinfo format is + [,[,public|private]] - CODE GENERATION - ---debug[+|-] Emit debug information (Short form: - -g) ---debug:{full|pdbonly|portable|embedded} Specify debugging type: full, - portable, embedded, pdbonly. ('full' - is the default if no debuggging type - specified and enables attaching a - debugger to a running program, - 'portable' is a cross-platform - format, 'embedded' is a - cross-platform format embedded into - the output file). ---embed[+|-] Embed all source files in the - portable PDB file ---embed: Embed specific source files in the - portable PDB file ---sourcelink: Source link information file to - embed in the portable PDB file ---optimize[+|-] Enable optimizations (Short form: - -O) +--debug[+|-] Emit debug information (Short form: -g) +--debug:{full|pdbonly|portable|embedded} Specify debugging type: full, portable, embedded, pdbonly. ('full' is the + default if no debuggging type specified and enables attaching a debugger to + a running program, 'portable' is a cross-platform format, 'embedded' is a + cross-platform format embedded into the output file). +--embed[+|-] Embed all source files in the portable PDB file +--embed: Embed specific source files in the portable PDB file +--sourcelink: Source link information file to embed in the portable PDB file +--optimize[+|-] Enable optimizations (Short form: -O) --tailcalls[+|-] Enable or disable tailcalls ---deterministic[+|-] Produce a deterministic assembly - (including module version GUID and +--deterministic[+|-] Produce a deterministic assembly (including module version GUID and timestamp) ---pathmap: Maps physical paths to source path - names output by the compiler ---crossoptimize[+|-] Enable or disable cross-module - optimizations ---reflectionfree Disable implicit generation of - constructs using reflection +--pathmap: Maps physical paths to source path names output by the compiler +--crossoptimize[+|-] Enable or disable cross-module optimizations +--reflectionfree Disable implicit generation of constructs using reflection - ERRORS AND WARNINGS - @@ -106,69 +69,45 @@ Copyright (c) Microsoft Corporation. All Rights Reserved. --warnaserror[+|-]: Report specific warnings as errors --warn: Set a warning level (0-5) --nowarn: Disable specific warning messages ---warnon: Enable specific warnings that may be - off by default ---consolecolors[+|-] Output warning and error messages in - color +--warnon: Enable specific warnings that may be off by default +--consolecolors[+|-] Output warning and error messages in color - LANGUAGE - ---langversion:? Display the allowed values for - language version. ---langversion:{version|latest|preview} Specify language version such as - 'latest' or 'preview'. +--langversion:? Display the allowed values for language version. +--langversion:{version|latest|preview} Specify language version such as 'latest' or 'preview'. --checked[+|-] Generate overflow checks ---define: Define conditional compilation - symbols (Short form: -d) +--define: Define conditional compilation symbols (Short form: -d) --mlcompatibility Ignore ML compatibility warnings - MISCELLANEOUS - --nologo Suppress compiler copyright message ---version Display compiler version banner and - exit ---help Display this usage message (Short - form: -?) +--version Display compiler version banner and exit +--help Display this usage message (Short form: -?) --@ Read response file for more options - ADVANCED - ---codepage: Specify the codepage used to read - source files +--codepage: Specify the codepage used to read source files --utf8output Output messages in UTF-8 encoding ---preferreduilang: Specify the preferred output - language culture name (e.g. es-ES, - ja-JP) ---fullpaths Output messages with fully qualified - paths ---lib: Specify a directory for the include - path which is used to resolve source - files and assemblies (Short form: - -I) ---simpleresolution Resolve assembly references using - directory-based rules rather than - MSBuild resolution ---targetprofile: Specify target framework profile of - this assembly. Valid values are - mscorlib, netcore or netstandard. - Default - mscorlib ---baseaddress:
Base address for the library to be - built ---checksumalgorithm:{SHA1|SHA256} Specify algorithm for calculating - source file checksum stored in PDB. - Supported values are: SHA1 or SHA256 - (default) ---noframework Do not reference the default CLI - assemblies by default ---standalone Statically link the F# library and - all referenced DLLs that depend on - it into the assembly being generated ---staticlink: Statically link the given assembly - and all referenced DLLs that depend - on this assembly. Use an assembly - name e.g. mylib, not a DLL name. +--preferreduilang: Specify the preferred output language culture name (e.g. es-ES, ja-JP) +--fullpaths Output messages with fully qualified paths +--lib: Specify a directory for the include path which is used to resolve source + files and assemblies (Short form: -I) +--simpleresolution Resolve assembly references using directory-based rules rather than MSBuild + resolution +--targetprofile: Specify target framework profile of this assembly. Valid values are + mscorlib, netcore or netstandard. Default - mscorlib +--baseaddress:
Base address for the library to be built +--checksumalgorithm:{SHA1|SHA256} Specify algorithm for calculating source file checksum stored in PDB. + Supported values are: SHA1 or SHA256 (default) +--noframework Do not reference the default CLI assemblies by default +--standalone Statically link the F# library and all referenced DLLs that depend on it + into the assembly being generated +--staticlink: Statically link the given assembly and all referenced DLLs that depend on + this assembly. Use an assembly name e.g. mylib, not a DLL name. --pdb: Name the output debug file --highentropyva[+|-] Enable high-entropy ASLR ---subsystemversion: Specify subsystem version of this - assembly +--subsystemversion: Specify subsystem version of this assembly --quotations-debug[+|-] Emit debug information in quotations diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/misc/misc.fs b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/misc/misc.fs new file mode 100644 index 00000000000..af341cf3685 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/misc/misc.fs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.ComponentTests.CompilerOptions.fsc + +open Xunit +open FSharp.Test +open FSharp.Test.Compiler +open System +open System.IO + +module help_options = + + // ReqENU SOURCE=dummy.fsx COMPILE_ONLY=1 PRECMD="\$FSC_PIPE >help40.txt -? 2>&1" POSTCMD="\$FSI_PIPE --nologo --quiet --exec ..\\..\\..\\comparer.fsx help40.txt help40.437.1033.bsl" # -? + [] + let ``Help - variant 1``() = + FSharp "" + |> asExe + |> withBufferWidth 120 + |> withOptions ["-?"] + |> compile + |> verifyOutputWithBaseline (Path.Combine(__SOURCE_DIRECTORY__, "compiler_help_output.bsl")) + |> shouldSucceed + + // ReqENU SOURCE=dummy.fsx COMPILE_ONLY=1 PRECMD="\$FSC_PIPE >help40.txt /? 2>&1" POSTCMD="\$FSI_PIPE --nologo --quiet --exec ..\\..\\..\\comparer.fsx help40.txt help40.437.1033.bsl" # --help + [] + let ``Help - variant 2``() = + FSharp "" + |> asExe + |> withBufferWidth 120 + |> withOptions ["/?"] + |> compile + |> verifyOutputWithBaseline (Path.Combine(__SOURCE_DIRECTORY__, "compiler_help_output.bsl")) + |> shouldSucceed + + // ReqENU SOURCE=dummy.fsx COMPILE_ONLY=1 PRECMD="\$FSC_PIPE >help40.txt --help 2>&1" POSTCMD="\$FSI_PIPE --nologo --quiet --exec ..\\..\\..\\comparer.fsx help40.txt help40.437.1033.bsl" # /? + [] + let ``Help - variant 3``() = + FSharp "" + |> asExe + |> withBufferWidth 120 + |> withOptions ["--help"] + |> compile + |> verifyOutputWithBaseline (Path.Combine(__SOURCE_DIRECTORY__, "compiler_help_output.bsl")) + |> shouldSucceed diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/times/times.fs b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/times/times.fs index 92b952dda93..a7136b32d0a 100644 --- a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/times/times.fs +++ b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/times/times.fs @@ -51,25 +51,17 @@ module times = [] let ``times - to console`` compilation = - let oldConsole = Console.Out - let sw = new StringWriter() - Console.SetOut(sw) - use _ = {new IDisposable with - member this.Dispose() = Console.SetOut(oldConsole) } - compilation |> asFsx + |> withBufferWidth 120 |> withOptions ["--times"] |> ignoreWarnings |> compile - |> shouldSucceed - |> ignore - - let consoleContents = sw.ToString() - Assert.Contains("Parse inputs",consoleContents) - Assert.Contains("Typecheck",consoleContents) - Assert.Contains("GC0",consoleContents) - Assert.Contains("Duration",consoleContents) + |> verifyOutputContains [| + "Parse inputs" + "Typecheck" + "GC0" + "Duration"|] [] diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 38713136849..e6f92e6a94b 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -209,6 +209,7 @@ + diff --git a/tests/FSharp.Compiler.Private.Scripting.UnitTests/DependencyManagerInteractiveTests.fs b/tests/FSharp.Compiler.Private.Scripting.UnitTests/DependencyManagerInteractiveTests.fs index 034ce9364a2..c37d087e9ea 100644 --- a/tests/FSharp.Compiler.Private.Scripting.UnitTests/DependencyManagerInteractiveTests.fs +++ b/tests/FSharp.Compiler.Private.Scripting.UnitTests/DependencyManagerInteractiveTests.fs @@ -11,8 +11,9 @@ open System.Threading open FSharp.Compiler.Interactive.Shell open FSharp.Compiler.DependencyManager open FSharp.Compiler.Diagnostics -open FSharp.Test.ScriptHelpers open FSharp.DependencyManager.Nuget +open FSharp.Test.ScriptHelpers +open FSharp.Test.Utilities open Internal.Utilities diff --git a/tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs b/tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs index 2c4a8dd198f..1b4676ec74f 100644 --- a/tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs +++ b/tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs @@ -11,6 +11,7 @@ open System.Threading open System.Threading.Tasks open FSharp.Compiler.Interactive.Shell open FSharp.Test.ScriptHelpers +open FSharp.Test.Utilities open Xunit diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index 464ae28ec9c..f6b0c41c94c 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -60,7 +60,8 @@ module rec Compiler = Name: string option IgnoreWarnings: bool References: CompilationUnit list - TargetFramework: TargetFramework } + TargetFramework: TargetFramework + } member this.CreateOutputDirectory() = match this.OutputDirectory with @@ -395,6 +396,9 @@ module rec Compiler = | FS fs -> FS { fs with OutputDirectory = Some (DirectoryInfo(path)) } | _ -> failwith "withOutputDirectory is only supported on F#" + let withBufferWidth (width: int)(cUnit: CompilationUnit) : CompilationUnit = + withOptionsHelper [ $"--bufferwidth:{width}" ] "withBufferWidth is only supported on F#" cUnit + let withDefines (defines: string list) (cUnit: CompilationUnit) : CompilationUnit = withOptionsHelper (defines |> List.map(fun define -> $"--define:{define}")) "withDefines is only supported on F#" cUnit @@ -582,18 +586,22 @@ module rec Compiler = let private compileFSharpCompilation compilation ignoreWarnings (cUnit: CompilationUnit) : CompilationResult = - let ((err: FSharpDiagnostic[], outputFilePath: string), deps) = CompilerAssert.CompileRaw(compilation, ignoreWarnings) + use redirect = new RedirectConsole() + let ((err: FSharpDiagnostic[], rc: int, outputFilePath: string), deps) = + CompilerAssert.CompileRaw(compilation, ignoreWarnings) + // Create and stash the console output let diagnostics = err |> fromFSharpDiagnostic - let result = - { OutputPath = None - Dependencies = deps - Adjust = 0 - PerFileErrors = diagnostics - Diagnostics = diagnostics |> List.map snd - Output = None - Compilation = cUnit } + let result = { + OutputPath = None + Dependencies = deps + Adjust = 0 + PerFileErrors = diagnostics + Diagnostics = diagnostics |> List.map snd + Output = Some (RunOutput.ExecutionOutput { ExitCode = rc; StdOut = redirect.Output(); StdErr = redirect.ErrorOutput() }) + Compilation = cUnit + } let (errors, warnings) = partitionErrors result.Diagnostics @@ -1021,6 +1029,62 @@ module rec Compiler = let verifyBaselines = verifyBaseline >> verifyILBaseline + let normalizeNewlines output = + let regex = new Regex("(\r\n|\r|\n)", RegexOptions.Singleline ||| RegexOptions.ExplicitCapture) + let result = regex.Replace(output, System.Environment.NewLine) + result + + let regexStrip output pattern flags = + let regex = new Regex(pattern, flags) + let result = regex.Replace(output, "") + result + + let stripEnvironment output = + let pattern = @"(---------------------------------------------------------------(\r\n|\r|\n)).*(\n---------------------------------------------------------------(\r\n|\r|\n))" + let result = regexStrip output pattern (RegexOptions.Singleline ||| RegexOptions.ExplicitCapture) + result + + let stripVersion output = + let pattern = @"(Microsoft \(R\) (.*) version (.*) F# (.*))" + let result = regexStrip output pattern (RegexOptions.Multiline ||| RegexOptions.ExplicitCapture) + result + + let getOutput (cResult: CompilationResult) : string option = + let result = + match cResult with + | CompilationResult.Failure f -> failwith $"Build failure: {f}" + | CompilationResult.Success output -> + match output.Output with + | Some (EvalOutput _) -> None + | Some (ExecutionOutput eo) -> + match eo.StdOut with + | null -> None + | output -> Some (stripVersion (stripEnvironment (normalizeNewlines output))) + | None -> None + result + + let verifyOutput (expected: string) (cResult: CompilationResult) : CompilationResult = + match getOutput cResult with + | None -> cResult + | Some actual -> + let expected = stripVersion (normalizeNewlines expected) + if expected <> actual then + failwith $"""Output does not match expected: ------------{Environment.NewLine}{expected}{Environment.NewLine}Actual: ------------{Environment.NewLine}{actual}{Environment.NewLine}""" + else + cResult + + let verifyOutputWithBaseline path = + verifyOutput (File.ReadAllText(path).Replace(@"\r\n", Environment.NewLine)) + + let verifyOutputContains (expected: string array) (cResult: CompilationResult) : CompilationResult = + match getOutput cResult with + | None -> cResult + | Some actual -> + for item in expected do + if not(actual.Contains(item)) then + failwith $"""Output does not match expected: ------------{Environment.NewLine}{item}{Environment.NewLine}Actual: ------------{Environment.NewLine}{actual}{Environment.NewLine}""" + cResult + type ImportScope = { Kind: ImportDefinitionKind; Name: string } type PdbVerificationOption = diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index e0fcacb5af1..44c7890efe9 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -342,14 +342,13 @@ module rec CompilerAssertHelpers = yield "-o:" + outputFilePath yield (if isExe then "--target:exe" else "--target:library") yield! (defaultProjectOptions targetFramework).OtherOptions -// yield! TargetFrameworkUtil.getFileReferences targetFramework yield! options |] // Generate a response file, purely for diagnostic reasons. File.WriteAllLines(Path.ChangeExtension(outputFilePath, ".rsp"), args) - let errors, _ = checker.Compile args |> Async.RunImmediate - errors, outputFilePath + let errors, rc = checker.Compile args |> Async.RunImmediate + errors, rc, outputFilePath let compileDisposable (outputDirectory:DirectoryInfo) isExe options targetFramework nameOpt (sources:SourceCodeFileKind list) = let disposeFile path = @@ -461,11 +460,11 @@ module rec CompilerAssertHelpers = let tmp = Path.Combine(outputPath.FullName, Path.ChangeExtension(fileName, ".dll")) disposals.Add({ new IDisposable with member _.Dispose() = File.Delete tmp }) cmpl.EmitAsFile tmp - (([||], tmp), []), false) + (([||], 0, tmp), []), false) let compilationRefs = compiledRefs - |> List.map (fun (((errors, outputFilePath), _), staticLink) -> + |> List.map (fun (((errors, _, outputFilePath), _), staticLink) -> assertErrors 0 ignoreWarnings errors [||] let rOption = "-r:" + outputFilePath if staticLink then @@ -483,7 +482,7 @@ module rec CompilerAssertHelpers = compilationRefs, deps - let compileCompilationAux outputDirectory (disposals: ResizeArray) ignoreWarnings (cmpl: Compilation) : (FSharpDiagnostic[] * string) * string list = + let compileCompilationAux outputDirectory (disposals: ResizeArray) ignoreWarnings (cmpl: Compilation) : (FSharpDiagnostic[] * int * string) * string list = let compilationRefs, deps = evaluateReferences outputDirectory disposals ignoreWarnings cmpl let isExe, sources, options, targetFramework, name = @@ -595,7 +594,7 @@ open CompilerAssertHelpers type CompilerAssert private () = static let compileExeAndRunWithOptions options (source: SourceCodeFileKind) = - compile true options source (fun (errors, outputExe) -> + compile true options source (fun (errors, _, outputExe) -> if errors.Length > 0 then Assert.Fail (sprintf "Compile had warnings and/or errors: %A" errors) @@ -604,7 +603,7 @@ type CompilerAssert private () = ) static let compileLibraryAndVerifyILWithOptions options (source: SourceCodeFileKind) (f: ILVerifier -> unit) = - compile false options source (fun (errors, outputFilePath) -> + compile false options source (fun (errors, _, outputFilePath) -> let errors = errors |> Array.filter (fun x -> x.Severity = FSharpDiagnosticSeverity.Error) if errors.Length > 0 then @@ -616,7 +615,7 @@ type CompilerAssert private () = static let compileLibraryAndVerifyDebugInfoWithOptions options (expectedFile: string) (source: SourceCodeFileKind) = let options = [| yield! options; yield"--test:DumpDebugInfo" |] - compile false options source (fun (errors, outputFilePath) -> + compile false options source (fun (errors, _, outputFilePath) -> let errors = errors |> Array.filter (fun x -> x.Severity = FSharpDiagnosticSeverity.Error) if errors.Length > 0 then @@ -652,7 +651,7 @@ Updated automatically, please check diffs in your pull request, changes must be static member CompileWithErrors(cmpl: Compilation, expectedErrors, ?ignoreWarnings) = let ignoreWarnings = defaultArg ignoreWarnings false - compileCompilation ignoreWarnings cmpl (fun ((errors, _), _) -> + compileCompilation ignoreWarnings cmpl (fun ((errors, _, _), _) -> assertErrors 0 ignoreWarnings errors expectedErrors) static member Compile(cmpl: Compilation, ?ignoreWarnings) = @@ -681,7 +680,7 @@ Updated automatically, please check diffs in your pull request, changes must be let beforeExecute = defaultArg beforeExecute copyDependenciesToOutputDir let newProcess = defaultArg newProcess false let onOutput = defaultArg onOutput (fun _ -> ()) - compileCompilation ignoreWarnings cmpl (fun ((errors, outputFilePath), deps) -> + compileCompilation ignoreWarnings cmpl (fun ((errors, _, outputFilePath), deps) -> assertErrors 0 ignoreWarnings errors [||] beforeExecute outputFilePath deps if newProcess then @@ -857,12 +856,12 @@ Updated automatically, please check diffs in your pull request, changes must be CompilerAssert.TypeCheckWithErrors source [| expectedSeverity, expectedErrorNumber, expectedErrorRange, expectedErrorMsg |] static member CompileExeWithOptions(options, (source: SourceCodeFileKind)) = - compile true options source (fun (errors, _) -> + compile true options source (fun (errors, _, _) -> if errors.Length > 0 then Assert.Fail (sprintf "Compile had warnings and/or errors: %A" errors)) static member CompileExeWithOptions(options, (source: string)) = - compile true options (SourceCodeFileKind.Create("test.fs", source)) (fun (errors, _) -> + compile true options (SourceCodeFileKind.Create("test.fs", source)) (fun (errors, _, _) -> if errors.Length > 0 then Assert.Fail (sprintf "Compile had warnings and/or errors: %A" errors)) diff --git a/tests/FSharp.Test.Utilities/DirectoryAttribute.fs b/tests/FSharp.Test.Utilities/DirectoryAttribute.fs index f7c3a380aa3..8133d0dacb9 100644 --- a/tests/FSharp.Test.Utilities/DirectoryAttribute.fs +++ b/tests/FSharp.Test.Utilities/DirectoryAttribute.fs @@ -121,23 +121,23 @@ type DirectoryAttribute(dir: string) = let fsBslSource = readFileOrDefault fsBslFilePath let ilBslSource = readFileOrDefault ilBslFilePath - { - Source = SourceCodeFileKind.Create(sourceFilePath) - AdditionalSources = [] - Baseline = + { Source = SourceCodeFileKind.Create(sourceFilePath) + AdditionalSources = [] + Baseline = Some { SourceFilename = Some sourceFilePath FSBaseline = { FilePath = fsOutFilePath; BslSource=fsBslFilePath; Content = fsBslSource } ILBaseline = { FilePath = ilOutFilePath; BslSource=ilBslFilePath ; Content = ilBslSource } } - Options = [] - OutputType = Library - Name = Some filename - IgnoreWarnings = false - References = [] - OutputDirectory = outputDirectory - TargetFramework = TargetFramework.Current} |> FS + Options = [] + OutputType = Library + Name = Some filename + IgnoreWarnings = false + References = [] + OutputDirectory = outputDirectory + TargetFramework = TargetFramework.Current + } |> FS member _.BaselineSuffix with get() = baselineSuffix and set v = baselineSuffix <- v member _.Includes with get() = includes and set v = includes <- v diff --git a/tests/FSharp.Test.Utilities/ScriptHelpers.fs b/tests/FSharp.Test.Utilities/ScriptHelpers.fs index 588dad184c8..14f19c2e4c4 100644 --- a/tests/FSharp.Test.Utilities/ScriptHelpers.fs +++ b/tests/FSharp.Test.Utilities/ScriptHelpers.fs @@ -11,65 +11,7 @@ open FSharp.Compiler open FSharp.Compiler.Interactive.Shell open FSharp.Compiler.Diagnostics open FSharp.Compiler.EditorServices - -type CapturedTextReader() = - inherit TextReader() - let queue = Queue() - member _.ProvideInput(text: string) = - for c in text.ToCharArray() do - queue.Enqueue(c) - override _.Peek() = - if queue.Count > 0 then queue.Peek() |> int else -1 - override _.Read() = - if queue.Count > 0 then queue.Dequeue() |> int else -1 - -type RedirectConsoleInput() = - let oldStdIn = Console.In - let newStdIn = new CapturedTextReader() - do Console.SetIn(newStdIn) - member _.ProvideInput(text: string) = - newStdIn.ProvideInput(text) - interface IDisposable with - member _.Dispose() = - Console.SetIn(oldStdIn) - newStdIn.Dispose() - -type EventedTextWriter() = - inherit TextWriter() - let sb = StringBuilder() - let lineWritten = Event() - member _.LineWritten = lineWritten.Publish - override _.Encoding = Encoding.UTF8 - override _.Write(c: char) = - if c = '\n' then - let line = - let v = sb.ToString() - if v.EndsWith("\r") then v.Substring(0, v.Length - 1) - else v - sb.Clear() |> ignore - lineWritten.Trigger(line) - else sb.Append(c) |> ignore - -type RedirectConsoleOutput() = - let outputProduced = Event() - let errorProduced = Event() - let oldStdOut = Console.Out - let oldStdErr = Console.Error - let newStdOut = new EventedTextWriter() - let newStdErr = new EventedTextWriter() - do newStdOut.LineWritten.Add outputProduced.Trigger - do newStdErr.LineWritten.Add errorProduced.Trigger - do Console.SetOut(newStdOut) - do Console.SetError(newStdErr) - member _.OutputProduced = outputProduced.Publish - member _.ErrorProduced = errorProduced.Publish - interface IDisposable with - member _.Dispose() = - Console.SetOut(oldStdOut) - Console.SetError(oldStdErr) - newStdOut.Dispose() - newStdErr.Dispose() - +open FSharp.Test.Utilities [] type LangVersion = diff --git a/tests/FSharp.Test.Utilities/Utilities.fs b/tests/FSharp.Test.Utilities/Utilities.fs index 106a4003108..7fcd2ce96cf 100644 --- a/tests/FSharp.Test.Utilities/Utilities.fs +++ b/tests/FSharp.Test.Utilities/Utilities.fs @@ -8,11 +8,13 @@ open System.Reflection open System.Collections.Immutable open System.Diagnostics open System.Threading +open System.Text open System.Threading.Tasks open Microsoft.CodeAnalysis open Microsoft.CodeAnalysis.CSharp open TestFramework open NUnit.Framework +open System.Collections.Generic type TheoryForNETCOREAPPAttribute() = inherit Xunit.TheoryAttribute() @@ -35,6 +37,83 @@ type FactForDESKTOPAttribute() = // This file mimics how Roslyn handles their compilation references for compilation testing module Utilities = + type CapturedTextReader() = + inherit TextReader() + let queue = Queue() + member _.ProvideInput(text: string) = + for c in text.ToCharArray() do + queue.Enqueue(c) + override _.Peek() = + if queue.Count > 0 then queue.Peek() |> int else -1 + override _.Read() = + if queue.Count > 0 then queue.Dequeue() |> int else -1 + + type RedirectConsoleInput() = + let oldStdIn = Console.In + let newStdIn = new CapturedTextReader() + do Console.SetIn(newStdIn) + member _.ProvideInput(text: string) = + newStdIn.ProvideInput(text) + interface IDisposable with + member _.Dispose() = + Console.SetIn(oldStdIn) + newStdIn.Dispose() + + type EventedTextWriter() = + inherit TextWriter() + let sb = StringBuilder() + let lineWritten = Event() + member _.LineWritten = lineWritten.Publish + override _.Encoding = Encoding.UTF8 + override _.Write(c: char) = + if c = '\n' then + let line = + let v = sb.ToString() + if v.EndsWith("\r") then v.Substring(0, v.Length - 1) + else v + sb.Clear() |> ignore + lineWritten.Trigger(line) + else sb.Append(c) |> ignore + + type RedirectConsoleOutput() = + let outputProduced = Event() + let errorProduced = Event() + let oldStdOut = Console.Out + let oldStdErr = Console.Error + let newStdOut = new EventedTextWriter() + let newStdErr = new EventedTextWriter() + + do newStdOut.LineWritten.Add outputProduced.Trigger + do newStdErr.LineWritten.Add errorProduced.Trigger + do Console.SetOut(newStdOut) + do Console.SetError(newStdErr) + + member _.OutputProduced = outputProduced.Publish + + member _.ErrorProduced = errorProduced.Publish + + interface IDisposable with + member _.Dispose() = + Console.SetOut(oldStdOut) + Console.SetError(oldStdErr) + newStdOut.Dispose() + newStdErr.Dispose() + + type RedirectConsole() = + let redirector = new RedirectConsoleOutput() + let outputLines = StringBuilder() + let errorLines = StringBuilder() + + do redirector.OutputProduced.Add (fun line -> outputLines.AppendLine line |>ignore) + do redirector.ErrorProduced.Add(fun line -> errorLines.AppendLine line |>ignore) + + member _.Output () = outputLines.ToString() + + member _.ErrorOutput () = errorLines.ToString() + + interface IDisposable with + member _.Dispose() = (redirector :> IDisposable).Dispose() + type Async with static member RunImmediate (computation: Async<'T>, ?cancellationToken ) = let cancellationToken = defaultArg cancellationToken Async.DefaultCancellationToken diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/help/.gitignore b/tests/fsharpqa/Source/CompilerOptions/fsc/help/.gitignore deleted file mode 100644 index 5641b0f57a4..00000000000 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/help/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# generated as part of the test -help40.txt diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/help/dummy.fsx b/tests/fsharpqa/Source/CompilerOptions/fsc/help/dummy.fsx deleted file mode 100644 index c5ecbb36434..00000000000 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/help/dummy.fsx +++ /dev/null @@ -1,3 +0,0 @@ -// #NoMT #CompilerOptions #RequiresENU -#light -exit 0 diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/help/env.lst b/tests/fsharpqa/Source/CompilerOptions/fsc/help/env.lst deleted file mode 100644 index d6e7a56c5cd..00000000000 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/help/env.lst +++ /dev/null @@ -1,6 +0,0 @@ -# ReqENU means that the test is non-localized - -ReqENU SOURCE=dummy.fsx COMPILE_ONLY=1 PRECMD="\$FSC_PIPE >help40.txt -? 2>&1" POSTCMD="\$FSI_PIPE --nologo --quiet --exec ..\\..\\..\\comparer.fsx help40.txt help40.437.1033.bsl" # -? -ReqENU SOURCE=dummy.fsx COMPILE_ONLY=1 PRECMD="\$FSC_PIPE >help40.txt --help 2>&1" POSTCMD="\$FSI_PIPE --nologo --quiet --exec ..\\..\\..\\comparer.fsx help40.txt help40.437.1033.bsl" # --help -ReqENU SOURCE=dummy.fsx COMPILE_ONLY=1 PRECMD="\$FSC_PIPE >help40.txt /? 2>&1" POSTCMD="\$FSI_PIPE --nologo --quiet --exec ..\\..\\..\\comparer.fsx help40.txt help40.437.1033.bsl" # /? - diff --git a/tests/fsharpqa/Source/test.lst b/tests/fsharpqa/Source/test.lst index a7fb13f0495..3c3f91f031b 100644 --- a/tests/fsharpqa/Source/test.lst +++ b/tests/fsharpqa/Source/test.lst @@ -10,7 +10,6 @@ CompilerOptions01,NoMT,Determinism CompilerOptions\fsc\determinism CompilerOptions01,NoMT CompilerOptions\fsc\dumpAllCommandLineOptions CompilerOptions01,NoMT CompilerOptions\fsc\flaterrors CompilerOptions02,NoMT,gcc CompilerOptions\fsc\gccerrors -CompilerOptions01,NoMT,help CompilerOptions\fsc\help CompilerOptions01,NoMT CompilerOptions\fsc\highentropyva CompilerOptions01,NoMT CompilerOptions\fsc\langversion CompilerOptions01,NoMT CompilerOptions\fsc\lib