Skip to content

Commit 294ef06

Browse files
authored
Merge pull request #3168 from Numpsy/test_space_path
Try to fix problems with the integration tests when there is a space …
2 parents d21ab68 + 034b7b1 commit 294ef06

File tree

8 files changed

+31
-44
lines changed

8 files changed

+31
-44
lines changed

src/Fantomas.Tests/Integration/ByteOrderMarkTests.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let private getInitialBytes file =
2020
let ``byte-order mark should be preserved, 795`` () =
2121
use fileFixture = new TemporaryFileCodeSample(Source, true)
2222

23-
let { ExitCode = exitCode } = runFantomasTool fileFixture.Filename
23+
let { ExitCode = exitCode } = runFantomasTool [ fileFixture.Filename ]
2424
exitCode |> should equal 0
2525

2626
let expectedPreamble = Encoding.UTF8.GetPreamble()
@@ -34,8 +34,7 @@ let ``preserve byte-order from original file`` () =
3434
use outputFixture = new OutputFile()
3535

3636
let { ExitCode = exitCode } =
37-
sprintf "--out %s %s" outputFixture.Filename inputFixture.Filename
38-
|> runFantomasTool
37+
[ "--out"; outputFixture.Filename; inputFixture.Filename ] |> runFantomasTool
3938

4039
exitCode |> should equal 0
4140

src/Fantomas.Tests/Integration/CheckTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ let ``honor ignore file when processing a folder`` () =
131131
use inputFixture = new FantomasIgnoreFile("*.fsx")
132132

133133
let { Output = output } =
134-
runFantomasTool (sprintf "--check .%c%s" Path.DirectorySeparatorChar subFolder)
134+
runFantomasTool [ "--check"; $".%c{Path.DirectorySeparatorChar}%s{subFolder}" ]
135135

136136
output |> should not' (contain "ignored")
137137

src/Fantomas.Tests/Integration/ConfigTests.fs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ open NUnit.Framework
55
open FsUnit
66
open Fantomas.Tests.TestHelpers
77

8-
[<Literal>]
9-
let DetailedVerbosity = "--verbosity d"
8+
let DetailedVerbosity = [ "--verbosity"; "d" ]
109

1110
[<Literal>]
1211
let NormalVerbosity = "--verbosity n"
@@ -28,7 +27,7 @@ end_of_line=lf
2827
"""
2928
)
3029

31-
let args = sprintf "%s %s" DetailedVerbosity fileFixture.Filename
30+
let args = DetailedVerbosity @ [ fileFixture.Filename ]
3231
let { ExitCode = exitCode; Output = output } = runFantomasTool args
3332
exitCode |> should equal 0
3433
output |> should contain (sprintf "Processing %s" fileFixture.Filename)
@@ -48,7 +47,7 @@ end_of_line=cr
4847
"""
4948
)
5049

51-
let args = sprintf "%s %s" DetailedVerbosity fileFixture.Filename
50+
let args = DetailedVerbosity @ [ fileFixture.Filename ]
5251
let { ExitCode = exitCode; Output = output } = runFantomasTool args
5352
exitCode |> should equal 1
5453
Assert.That(output, Does.Contain "Carriage returns are not valid for F# code, please use one of 'lf' or 'crlf'")
@@ -77,7 +76,7 @@ end_of_line = %s
7776
setting
7877
)
7978

80-
let { ExitCode = exitCode } = runFantomasTool fileFixture.Filename
79+
let { ExitCode = exitCode } = runFantomasTool [ fileFixture.Filename ]
8180
exitCode |> should equal 0
8281

8382
let result = System.IO.File.ReadAllText(fileFixture.Filename)
@@ -99,7 +98,7 @@ end_of_line = lf
9998
"""
10099
)
101100

102-
let { ExitCode = exitCode } = runFantomasTool fileFixture.Filename
101+
let { ExitCode = exitCode } = runFantomasTool [ fileFixture.Filename ]
103102
exitCode |> should equal 0
104103

105104
let result = System.IO.File.ReadAllText(fileFixture.Filename)

src/Fantomas.Tests/Integration/ForceTests.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ open NUnit.Framework
55
open FsUnit
66
open Fantomas.Tests.TestHelpers
77

8-
[<Literal>]
9-
let Verbosity = "--verbosity d"
8+
let Verbosity = [ "--verbosity"; "d" ]
109

1110
// The day this test fails because Fantomas can format the file, is the day you can remove this file.
1211

@@ -24,7 +23,7 @@ let ``code that was invalid should be still be written`` () =
2423
use outputFixture = new OutputFile()
2524

2625
let { ExitCode = exitCode; Output = output } =
27-
runFantomasTool $"%s{Verbosity} --force --out %s{outputFixture.Filename} %s{sourceFile}"
26+
runFantomasTool (Verbosity @ [ "--force"; "--out"; outputFixture.Filename; sourceFile ])
2827

2928
exitCode |> should equal 0
3029
output |> should contain "was not valid after formatting"

src/Fantomas.Tests/Integration/IgnoreFilesTests.fs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ open Fantomas.Tests.TestHelpers
88
[<Literal>]
99
let Source = "let foo = 47"
1010

11-
[<Literal>]
12-
let Verbosity = "--verbosity d"
11+
let Verbosity = [ "--verbosity"; "d" ]
1312

1413
[<Test>]
1514
let ``ignore all fs files`` () =
@@ -21,8 +20,7 @@ let ``ignore all fs files`` () =
2120
use outputFixture = new OutputFile()
2221

2322
let { ExitCode = exitCode } =
24-
sprintf "--out %s %s" outputFixture.Filename inputFixture.Filename
25-
|> runFantomasTool
23+
[ "--out"; outputFixture.Filename; inputFixture.Filename ] |> runFantomasTool
2624

2725
exitCode |> should equal 0
2826
File.Exists outputFixture.Filename |> should equal false
@@ -34,7 +32,7 @@ let ``ignore specific file`` () =
3432
use inputFixture = new TemporaryFileCodeSample(Source, fileName = fileName)
3533

3634
use ignoreFixture = new FantomasIgnoreFile("A.fs")
37-
let args = sprintf "%s %s" Verbosity inputFixture.Filename
35+
let args = Verbosity @ [ inputFixture.Filename ]
3836
let { ExitCode = exitCode; Output = output } = runFantomasTool args
3937
exitCode |> should equal 0
4038

@@ -53,7 +51,7 @@ let ``ignore specific file in subfolder`` () =
5351
use ignoreFixture = new FantomasIgnoreFile(sprintf "%s/%s/A.fs" sub1 sub2)
5452

5553
let { ExitCode = exitCode } =
56-
runFantomasTool (sprintf "--check .%c%s" Path.DirectorySeparatorChar sub1)
54+
runFantomasTool [ "--check"; $".%c{Path.DirectorySeparatorChar}%s{sub1}" ]
5755

5856
exitCode |> should equal 0
5957

@@ -64,7 +62,7 @@ let ``don't ignore other files`` () =
6462
use inputFixture = new TemporaryFileCodeSample(Source, fileName = fileName)
6563

6664
use ignoreFixture = new FantomasIgnoreFile("A.fs")
67-
let args = sprintf "%s %s" Verbosity inputFixture.Filename
65+
let args = Verbosity @ [ inputFixture.Filename ]
6866
let { ExitCode = exitCode; Output = output } = runFantomasTool args
6967
exitCode |> should equal 0
7068

@@ -83,7 +81,7 @@ let ``ignore file in folder`` () =
8381
use ignoreFixture = new FantomasIgnoreFile("A.fs")
8482

8583
let { ExitCode = exitCode; Output = output } =
86-
runFantomasTool $"%s{Verbosity} .%c{Path.DirectorySeparatorChar}%s{subFolder}"
84+
runFantomasTool (Verbosity @ [ $".%c{Path.DirectorySeparatorChar}%s{subFolder}" ])
8785

8886
exitCode |> should equal 0
8987
File.ReadAllText inputFixture.Filename |> should equal Source
@@ -99,7 +97,7 @@ let ``ignore file while checking`` () =
9997
use ignoreFixture = new FantomasIgnoreFile("A.fs")
10098

10199
let { ExitCode = exitCode; Output = output } =
102-
sprintf "%s %s --check" Verbosity inputFixture.Filename |> runFantomasTool
100+
[ "--check"; yield! Verbosity; inputFixture.Filename ] |> runFantomasTool
103101

104102
exitCode |> should equal 0
105103

@@ -116,7 +114,7 @@ let ``ignore file in folder while checking`` () =
116114
use ignoreFixture = new FantomasIgnoreFile("A.fs")
117115

118116
let { ExitCode = exitCode } =
119-
runFantomasTool (sprintf ".%c%s --check" Path.DirectorySeparatorChar subFolder)
117+
runFantomasTool [ $".%c{Path.DirectorySeparatorChar}%s{subFolder}"; "--check" ]
120118

121119
exitCode |> should equal 0
122120
File.ReadAllText inputFixture.Filename |> should equal Source
@@ -132,7 +130,7 @@ let ``honor ignore file when processing a folder`` () =
132130
use inputFixture = new FantomasIgnoreFile("*.fsx")
133131

134132
let { Output = output } =
135-
runFantomasTool (sprintf "%s .%c%s" Verbosity Path.DirectorySeparatorChar subFolder)
133+
runFantomasTool (Verbosity @ [ $".%c{Path.DirectorySeparatorChar}%s{subFolder}" ])
136134

137135
output |> should not' (contain "ignored")
138136
output |> should contain "A.fs was formatted"

src/Fantomas.Tests/Integration/MultiplePathsTests.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ let UserCode = "let a = 9"
1111
[<Literal>]
1212
let FormattedCode = "let a = 9\n"
1313

14-
[<Literal>]
15-
let Verbosity = "--verbosity d"
14+
let Verbosity = [ "--verbosity"; "d" ]
1615

1716
let private fileContentMatches (expectedContent: string) (actualPath: string) : unit =
1817
if File.Exists(actualPath) then
@@ -48,7 +47,7 @@ let ``format multiple paths recursively`` () =
4847
use fileFixtureThree = new TemporaryFileCodeSample(UserCode, subFolder = "sub")
4948

5049
let arguments =
51-
sprintf "%s \"%s\" \"%s\" \"sub\"" Verbosity fileFixtureOne.Filename fileFixtureTwo.Filename
50+
Verbosity @ [ fileFixtureOne.Filename; fileFixtureTwo.Filename; "sub" ]
5251

5352
let { ExitCode = exitCode; Output = output } = runFantomasTool arguments
5453

src/Fantomas.Tests/Integration/WriteTests.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ let FormattedCode = "let a = 9\n"
1111
[<Literal>]
1212
let UnformattedCode = "let a = 9"
1313

14-
[<Literal>]
15-
let Verbosity = "--verbosity d"
14+
let Verbosity = [ "--verbosity"; "d" ]
1615

1716
[<Test>]
1817
let ``correctly formatted file should not be written, 1984`` () =
@@ -27,7 +26,7 @@ end_of_line=lf
2726
)
2827

2928
use inputFixture = new TemporaryFileCodeSample(FormattedCode, fileName = fileName)
30-
let args = sprintf "%s %s" Verbosity inputFixture.Filename
29+
let args = Verbosity @ [ inputFixture.Filename ]
3130
let { ExitCode = exitCode; Output = output } = runFantomasTool args
3231
exitCode |> should equal 0
3332

@@ -38,7 +37,7 @@ let ``incorrectly formatted file should be written`` () =
3837
let fileName = "A"
3938

4039
use inputFixture = new TemporaryFileCodeSample(UnformattedCode, fileName = fileName)
41-
let args = sprintf "%s %s" Verbosity inputFixture.Filename
40+
let args = Verbosity @ [ inputFixture.Filename ]
4241
let { ExitCode = exitCode; Output = output } = runFantomasTool args
4342
exitCode |> should equal 0
4443

@@ -52,7 +51,8 @@ let ``file should be written to out folder when input folder has trailing slash`
5251
use outputFolder = new OutputFolder()
5352

5453
let arguments =
55-
sprintf @"%s subsrc%c --out %s" Verbosity Path.DirectorySeparatorChar outputFolder.Foldername
54+
Verbosity
55+
@ [ $"subsrc%c{Path.DirectorySeparatorChar}"; "--out"; outputFolder.Foldername ]
5656

5757
let { ExitCode = exitCode; Output = output } = runFantomasTool arguments
5858

@@ -67,7 +67,7 @@ let ``file should be written to out folder when input folder has no trailing sla
6767

6868
use outputFolder = new OutputFolder()
6969

70-
let arguments = sprintf @"%s subsrc --out %s" Verbosity outputFolder.Foldername
70+
let arguments = Verbosity @ [ "subsrc"; "--out"; outputFolder.Foldername ]
7171

7272
let { ExitCode = exitCode; Output = output } = runFantomasTool arguments
7373

src/Fantomas.Tests/TestHelpers.fs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ let getFantomasToolStartInfo arguments : ProcessStartInfo =
130130
if not (File.Exists fantomasDll) then
131131
failwithf $"The fantomas dll at \"%s{fantomasDll}\" does not exist!"
132132

133-
let startInfo = ProcessStartInfo("dotnet")
133+
let argumentArray = fantomasDll :: arguments
134+
let startInfo = ProcessStartInfo("dotnet", argumentArray)
134135
startInfo.UseShellExecute <- false
135-
startInfo.Arguments <- sprintf "%s %s" fantomasDll arguments
136136
startInfo.WorkingDirectory <- Path.GetTempPath()
137137
startInfo.RedirectStandardOutput <- true
138138
startInfo.RedirectStandardError <- true
@@ -150,14 +150,7 @@ let runFantomasTool arguments : FantomasToolResult =
150150
Error = error }
151151

152152
let checkCode (files: string list) : FantomasToolResult =
153-
let files =
154-
files |> List.map (fun file -> sprintf "\"%s\"" file) |> String.concat " "
155-
156-
let arguments = sprintf "--check %s" files
153+
let arguments = "--check" :: files
157154
runFantomasTool arguments
158155

159-
let formatCode (files: string list) : FantomasToolResult =
160-
let arguments =
161-
files |> List.map (fun file -> sprintf "\"%s\"" file) |> String.concat " "
162-
163-
runFantomasTool arguments
156+
let formatCode (files: string list) : FantomasToolResult = runFantomasTool files

0 commit comments

Comments
 (0)