Skip to content

Commit 9a29bed

Browse files
reactivate test - Help is displayed correctly (#13792)
* tcconfig/tcconfigbuilder * add --bufferwidth * fantomas * oops Co-authored-by: Vlad Zarytovskii <[email protected]>
1 parent d8a546d commit 9a29bed

File tree

11 files changed

+85
-65
lines changed

11 files changed

+85
-65
lines changed

src/Compiler/Driver/CompilerConfig.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,8 @@ type TcConfigBuilder =
551551

552552
mutable fxResolver: FxResolver option
553553

554+
mutable bufferWidth: int option
555+
554556
// Is F# Interactive using multi-assembly emit?
555557
mutable fsiMultiAssemblyEmit: bool
556558

@@ -741,6 +743,7 @@ type TcConfigBuilder =
741743
shadowCopyReferences = false
742744
useSdkRefs = true
743745
fxResolver = None
746+
bufferWidth = None
744747
fsiMultiAssemblyEmit = true
745748
internalTestSpanStackReferring = false
746749
noConditionalErasure = false
@@ -1163,6 +1166,7 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
11631166
errorRecovery e range0
11641167
[]
11651168

1169+
member _.bufferWidth = data.bufferWidth
11661170
member _.fsiMultiAssemblyEmit = data.fsiMultiAssemblyEmit
11671171
member _.FxResolver = data.FxResolver
11681172
member _.primaryAssembly = data.primaryAssembly

src/Compiler/Driver/CompilerConfig.fsi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ type TcConfigBuilder =
452452

453453
mutable fxResolver: FxResolver option
454454

455+
mutable bufferWidth: int option
456+
455457
mutable fsiMultiAssemblyEmit: bool
456458

457459
rangeForErrors: range
@@ -746,13 +748,16 @@ type TcConfig =
746748
member alwaysCallVirt: bool
747749

748750
member noDebugAttributes: bool
751+
749752
member useReflectionFreeCodeGen: bool
750753

751754
/// If true, indicates all type checking and code generation is in the context of fsi.exe
752755
member isInteractive: bool
753756

754757
member isInvalidationSupported: bool
755758

759+
member bufferWidth: int option
760+
756761
/// Indicates if F# Interactive is using single-assembly emit via Reflection.Emit, where internals are available.
757762
member fsiMultiAssemblyEmit: bool
758763

src/Compiler/Driver/CompilerOptions.fs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,27 @@ let compilerOptionUsage (CompilerOption (s, tag, spec, _, _)) =
115115

116116
let nl = Environment.NewLine
117117

118-
let getCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOption) =
118+
let getCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOption) width =
119119
let sb = StringBuilder()
120120

121121
let flagWidth = 42 // fixed width for printing of flags, e.g. --debug:{full|pdbonly|portable|embedded}
122122
let defaultLineWidth = 80 // the fallback width
123123

124124
let lineWidth =
125-
try
126-
Console.BufferWidth
127-
with e ->
128-
defaultLineWidth
125+
match width with
126+
| None ->
127+
try
128+
Console.BufferWidth
129+
with _ ->
130+
defaultLineWidth
131+
| Some w -> w
129132

130133
let lineWidth =
131134
if lineWidth = 0 then
132135
defaultLineWidth
133136
else
134-
lineWidth (* Have seen BufferWidth=0 on Linux/Mono *)
137+
lineWidth (* Have seen BufferWidth=0 on Linux/Mono Coreclr for sure *)
138+
135139
// Lines have this form: <flagWidth><space><description>
136140
// flagWidth chars - for flags description or padding on continuation lines.
137141
// single space - space.
@@ -159,14 +163,14 @@ let getCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOpti
159163
let _ = sb.Append $"{nl}"
160164
sb.ToString()
161165

162-
let getPublicOptions (heading, opts) =
163-
if not (isNil opts) then
164-
$"{nl}{nl}\t\t{heading}{nl}"
165-
+ (opts |> List.map getCompilerOption |> String.concat "")
166-
else
167-
""
166+
let getPublicOptions heading opts width =
167+
match opts with
168+
| [] -> ""
169+
| _ ->
170+
$"{nl}{nl} {heading}{nl}"
171+
+ (opts |> List.map (fun t -> getCompilerOption t width) |> String.concat "")
168172

169-
let GetCompilerOptionBlocks blocks =
173+
let GetCompilerOptionBlocks blocks width =
170174
let sb = new StringBuilder()
171175

172176
let publicBlocks =
@@ -182,7 +186,7 @@ let GetCompilerOptionBlocks blocks =
182186
let headingOptions =
183187
publicBlocks |> List.filter (fun (h2, _) -> heading = h2) |> List.collect snd
184188

185-
let _ = sb.Append(getPublicOptions (heading, headingOptions))
189+
let _ = sb.Append(getPublicOptions heading headingOptions width)
186190
Set.add heading doneHeadings
187191

188192
List.fold consider Set.empty publicBlocks |> ignore<Set<string>>
@@ -1462,6 +1466,14 @@ let internalFlags (tcConfigB: TcConfigBuilder) =
14621466
None
14631467
)
14641468

1469+
CompilerOption(
1470+
"bufferwidth",
1471+
tagNone,
1472+
OptionInt((fun v -> tcConfigB.bufferWidth <- Some v)),
1473+
Some(InternalCommandLineOption("--bufferWidth", rangeCmdArgs)),
1474+
None
1475+
)
1476+
14651477
CompilerOption(
14661478
"detuple",
14671479
tagNone,
@@ -1997,7 +2009,8 @@ let GetBannerText tcConfigB =
19972009

19982010
/// FSC only help. (FSI has it's own help function).
19992011
let GetHelpFsc tcConfigB (blocks: CompilerOptionBlock list) =
2000-
GetBannerText tcConfigB + GetCompilerOptionBlocks blocks
2012+
2013+
GetBannerText tcConfigB + GetCompilerOptionBlocks blocks tcConfigB.bufferWidth
20012014

20022015
let GetVersion tcConfigB =
20032016
$"{tcConfigB.productNameForBannerText}{nl}"

src/Compiler/Driver/CompilerOptions.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ and CompilerOptionBlock =
4343
| PublicOptions of heading: string * options: CompilerOption list
4444
| PrivateOptions of options: CompilerOption list
4545

46-
val GetCompilerOptionBlocks: CompilerOptionBlock list -> string
46+
val GetCompilerOptionBlocks: CompilerOptionBlock list -> width: int option -> string
4747

4848
val DumpCompilerOptionBlocks: CompilerOptionBlock list -> unit // for QA
4949

src/Compiler/Interactive/fsi.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ type internal FsiCommandLineOptions(fsi: FsiEvaluationSessionHostConfig,
885885
Console.Write (GetBannerText tcConfigB)
886886
fprintfn fsiConsoleOutput.Out ""
887887
fprintfn fsiConsoleOutput.Out "%s" (FSIstrings.SR.fsiUsage(executableFileNameWithoutExtension.Value))
888-
Console.Write (GetCompilerOptionBlocks blocks)
888+
Console.Write (GetCompilerOptionBlocks blocks tcConfigB.bufferWidth)
889889
exit 0
890890

891891
// option tags

tests/FSharp.Compiler.Service.Tests/ConsoleOnlyOptionsTests.fs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,25 @@ module FSharp.Compiler.Service.Tests.ConsoleOnlyOptionsTests
55
open System
66
open System.IO
77
open FSharp.Compiler.CompilerOptions
8+
open FSharp.Compiler.Text.Range
89
open NUnit.Framework
910
open TestDoubles
1011

1112
[<Test>]
12-
[<Ignore "Failing in main, disabling until resolved">]
13-
let ``Help is displayed correctly`` () =
14-
try
15-
if System.Console.BufferWidth < 80 then
16-
System.Console.BufferWidth <- 80
17-
with _ -> ()
13+
let ``fsc help text is displayed correctly`` () =
1814

19-
let builder = getArbitraryTcConfigBuilder()
20-
builder.showBanner <- false // We don't need the banner
21-
22-
let blocks = GetCoreFscCompilerOptions builder
15+
let builder = getArbitraryTcConfigBuilder()
16+
builder.showBanner <- false // We don't need the banner
17+
builder.TurnWarningOff(rangeCmdArgs, "75") // We are going to use a test only flag
18+
builder.bufferWidth <- Some 80 // Fixed width 80
19+
20+
let expectedHelp = File.ReadAllText $"{__SOURCE_DIRECTORY__}/expected-help-output.bsl"
2321

24-
let expectedHelp = File.ReadAllText $"{__SOURCE_DIRECTORY__}/expected-help-output.bsl"
25-
let help = GetHelpFsc builder blocks
22+
let blocks = GetCoreFscCompilerOptions builder
23+
let help = GetHelpFsc builder blocks
24+
let actualHelp = help.Replace("\r\n", Environment.NewLine)
2625

27-
let actualHelp = help.Replace("\r\n", Environment.NewLine)
28-
Assert.AreEqual(expectedHelp, actualHelp, $"Console width: {System.Console.BufferWidth}\nExpected: {expectedHelp}\n Actual: {actualHelp}") |> ignore
26+
Assert.AreEqual(expectedHelp, actualHelp, $"Expected: '{expectedHelp}'\n Actual: '{actualHelp}'") |> ignore
2927

3028
[<Test>]
3129
let ``Version is displayed correctly`` () =

tests/FSharp.Compiler.Service.Tests/expected-help-output.bsl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
- OUTPUT FILES -
3+
- OUTPUT FILES -
44
--out:<file> Name of the output file (Short form:
55
-o)
66
--target:exe Build a console executable
@@ -46,15 +46,15 @@
4646
the specified file path.
4747

4848

49-
- INPUT FILES -
49+
- INPUT FILES -
5050
--reference:<file> Reference an assembly (Short form:
5151
-r)
5252
--compilertool:<file> Reference an assembly or directory
5353
containing a design time tool (Short
5454
form: -t)
5555

5656

57-
- RESOURCES -
57+
- RESOURCES -
5858
--win32icon:<file> Specify a Win32 icon file (.ico)
5959
--win32res:<file> Specify a Win32 resource file (.res)
6060
--win32manifest:<file> Specify a Win32 manifest file
@@ -67,7 +67,7 @@
6767
name>[,public|private]]
6868

6969

70-
- CODE GENERATION -
70+
- CODE GENERATION -
7171
--debug[+|-] Emit debug information (Short form:
7272
-g)
7373
--debug:{full|pdbonly|portable|embedded} Specify debugging type: full,
@@ -99,7 +99,7 @@
9999
constructs using reflection
100100

101101

102-
- ERRORS AND WARNINGS -
102+
- ERRORS AND WARNINGS -
103103
--warnaserror[+|-] Report all warnings as errors
104104
--warnaserror[+|-]:<warn;...> Report specific warnings as errors
105105
--warn:<n> Set a warning level (0-5)
@@ -110,7 +110,7 @@
110110
color
111111

112112

113-
- LANGUAGE -
113+
- LANGUAGE -
114114
--langversion:{?|version|latest|preview} Display the allowed values for
115115
language version, specify language
116116
version such as 'latest' or
@@ -121,7 +121,7 @@
121121
--mlcompatibility Ignore ML compatibility warnings
122122

123123

124-
- MISCELLANEOUS -
124+
- MISCELLANEOUS -
125125
--nologo Suppress compiler copyright message
126126
--version Display compiler version banner and
127127
exit
@@ -130,7 +130,7 @@
130130
--@<file> Read response file for more options
131131

132132

133-
- ADVANCED -
133+
- ADVANCED -
134134
--codepage:<n> Specify the codepage used to read
135135
source files
136136
--utf8output Output messages in UTF-8 encoding

tests/fsharpqa/Source/CompilerOptions/fsc/help/help40.437.1033.bsl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Microsoft (R) F# Compiler version 12.0.0.0 for F# 6.0
22
Copyright (c) Microsoft Corporation. All Rights Reserved.
33

44

5-
- OUTPUT FILES -
5+
- OUTPUT FILES -
66
--out:<file> Name of the output file (Short form:
77
-o)
88
--target:exe Build a console executable
@@ -48,15 +48,15 @@ Copyright (c) Microsoft Corporation. All Rights Reserved.
4848
the specified file path.
4949

5050

51-
- INPUT FILES -
51+
- INPUT FILES -
5252
--reference:<file> Reference an assembly (Short form:
5353
-r)
5454
--compilertool:<file> Reference an assembly or directory
5555
containing a design time tool (Short
5656
form: -t)
5757

5858

59-
- RESOURCES -
59+
- RESOURCES -
6060
--win32icon:<file> Specify a Win32 icon file (.ico)
6161
--win32res:<file> Specify a Win32 resource file (.res)
6262
--win32manifest:<file> Specify a Win32 manifest file
@@ -69,7 +69,7 @@ Copyright (c) Microsoft Corporation. All Rights Reserved.
6969
name>[,public|private]]
7070

7171

72-
- CODE GENERATION -
72+
- CODE GENERATION -
7373
--debug[+|-] Emit debug information (Short form:
7474
-g)
7575
--debug:{full|pdbonly|portable|embedded} Specify debugging type: full,
@@ -101,7 +101,7 @@ Copyright (c) Microsoft Corporation. All Rights Reserved.
101101
constructs using reflection
102102

103103

104-
- ERRORS AND WARNINGS -
104+
- ERRORS AND WARNINGS -
105105
--warnaserror[+|-] Report all warnings as errors
106106
--warnaserror[+|-]:<warn;...> Report specific warnings as errors
107107
--warn:<n> Set a warning level (0-5)
@@ -112,7 +112,7 @@ Copyright (c) Microsoft Corporation. All Rights Reserved.
112112
color
113113

114114

115-
- LANGUAGE -
115+
- LANGUAGE -
116116
--langversion:{?|version|latest|preview} Display the allowed values for
117117
language version, specify language
118118
version such as 'latest' or
@@ -123,7 +123,7 @@ Copyright (c) Microsoft Corporation. All Rights Reserved.
123123
--mlcompatibility Ignore ML compatibility warnings
124124

125125

126-
- MISCELLANEOUS -
126+
- MISCELLANEOUS -
127127
--nologo Suppress compiler copyright message
128128
--version Display compiler version banner and
129129
exit
@@ -132,7 +132,7 @@ Copyright (c) Microsoft Corporation. All Rights Reserved.
132132
--@<file> Read response file for more options
133133

134134

135-
- ADVANCED -
135+
- ADVANCED -
136136
--codepage:<n> Specify the codepage used to read
137137
source files
138138
--utf8output Output messages in UTF-8 encoding

tests/fsharpqa/Source/CompilerOptions/fsi/exename/help40.437.1033.bsl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Usage: fsharpi <options> [script.fsx [<arguments>]]
33

44

5-
- INPUT FILES -
5+
- INPUT FILES -
66
--use:<file> Use the given file on startup as
77
initial input
88
--load:<file> #load the given file on startup
@@ -16,7 +16,7 @@ Usage: fsharpi <options> [script.fsx [<arguments>]]
1616
fsi.CommandLineArgs
1717

1818

19-
- CODE GENERATION -
19+
- CODE GENERATION -
2020
--debug[+|-] Emit debug information (Short form:
2121
-g)
2222
--debug:{full|pdbonly|portable|embedded} Specify debugging type: full,
@@ -42,7 +42,7 @@ Usage: fsharpi <options> [script.fsx [<arguments>]]
4242
constructs using reflection
4343

4444

45-
- ERRORS AND WARNINGS -
45+
- ERRORS AND WARNINGS -
4646
--warnaserror[+|-] Report all warnings as errors
4747
--warnaserror[+|-]:<warn;...> Report specific warnings as errors
4848
--warn:<n> Set a warning level (0-5)
@@ -53,7 +53,7 @@ Usage: fsharpi <options> [script.fsx [<arguments>]]
5353
color
5454

5555

56-
- LANGUAGE -
56+
- LANGUAGE -
5757
--langversion:{?|version|latest|preview} Display the allowed values for
5858
language version, specify language
5959
version such as 'latest' or
@@ -64,15 +64,15 @@ Usage: fsharpi <options> [script.fsx [<arguments>]]
6464
--mlcompatibility Ignore ML compatibility warnings
6565

6666

67-
- MISCELLANEOUS -
67+
- MISCELLANEOUS -
6868
--nologo Suppress compiler copyright message
6969
--version Display compiler version banner and
7070
exit
7171
--help Display this usage message (Short
7272
form: -?)
7373

7474

75-
- ADVANCED -
75+
- ADVANCED -
7676
--codepage:<n> Specify the codepage used to read
7777
source files
7878
--utf8output Output messages in UTF-8 encoding

0 commit comments

Comments
 (0)