Skip to content

Commit 658267c

Browse files
Upgrade to .NET 8 (#218)
* Upgrade to .NET 8 * Fix typing * Update * Upgrade F# core * Initial fix * Upgrade to latest Fantomas * Upgrade FCS * Fix * Start rewriting * Fix rewriting
1 parent e611dea commit 658267c

File tree

27 files changed

+163
-89
lines changed

27 files changed

+163
-89
lines changed

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:7.0.401-alpine3.18-amd64 AS build
1+
FROM mcr.microsoft.com/dotnet/sdk:8.0.201-alpine3.19-amd64 AS build
22

33
WORKDIR /tmp
44

@@ -19,6 +19,7 @@ RUN dotnet add package FsCheck -v 2.16.3
1919
RUN dotnet add package FsCheck.Xunit -v 2.14.3
2020
RUN dotnet add package FSharp.Core -v 6.0.1
2121
RUN dotnet add package FSharp.Core -v 7.0.400
22+
RUN dotnet add package FSharp.Core -v 8.0.101
2223
RUN dotnet add package FParsec -v 1.1.1
2324

2425
WORKDIR /app
@@ -32,7 +33,7 @@ COPY src/Exercism.TestRunner.FSharp/ ./
3233
RUN dotnet publish -r linux-musl-x64 -c Release -o /opt/test-runner --no-restore --self-contained true
3334

3435
# Build runtime image
35-
FROM mcr.microsoft.com/dotnet/sdk:7.0.401-alpine3.18-amd64 AS runtime
36+
FROM mcr.microsoft.com/dotnet/sdk:8.0.201-alpine3.19-amd64 AS runtime
3637
WORKDIR /opt/test-runner
3738

3839
# Enable rolling forward the .NET SDK used to be backwards-compatible

src/Exercism.TestRunner.FSharp/Exercism.TestRunner.FSharp.fsproj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
@@ -20,11 +20,10 @@
2020

2121
<ItemGroup>
2222
<PackageReference Include="CommandLineParser" Version="2.9.1" />
23-
<PackageReference Include="Fantomas.Core" Version="5.1.5" />
24-
<PackageReference Include="Fantomas.FCS" Version="5.1.5" />
23+
<PackageReference Include="Fantomas.Core" Version="6.3.3" />
24+
<PackageReference Include="Fantomas.FCS" Version="6.3.3" />
2525
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
26-
<PackageReference Include="FsUnit.xUnit" Version="5.3.0" />
27-
<PackageReference Update="FSharp.Core" Version="7.0.0" />
26+
<PackageReference Update="FSharp.Core" Version="8.0.200" />
2827
</ItemGroup>
2928

3029
</Project>

src/Exercism.TestRunner.FSharp/Rewrite.fs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module Exercism.TestRunner.FSharp.Rewrite
33
open System.IO
44
open Exercism.TestRunner.FSharp.Core
55
open Exercism.TestRunner.FSharp.Visitor
6-
open FSharp.Compiler.Syntax
7-
open FSharp.Compiler.Text
86
open Fantomas.Core
7+
open Fantomas.FCS.Syntax
8+
open Fantomas.FCS.Text
99
open Fantomas.FCS.Parse
1010

1111
type ParseResult =
@@ -18,13 +18,6 @@ type RewriteResult =
1818

1919
type EnableAllTests() =
2020
inherit SyntaxVisitor()
21-
22-
default this.VisitSynAttributeList(attrs: SynAttributeList) : SynAttributeList =
23-
base.VisitSynAttributeList(
24-
{ attrs with
25-
Attributes =
26-
attrs.Attributes
27-
|> List.filter (fun attr -> attr.TypeName.LongIdent.Head.idText <> "Ignore") })
2821

2922
override _.VisitSynAttribute(attr: SynAttribute) : SynAttribute =
3023
let isSkipExpr expr =
@@ -33,32 +26,42 @@ type EnableAllTests() =
3326
| _ -> false
3427

3528
match attr.ArgExpr with
36-
| SynExpr.Paren(expr, leftParenRange, rightParenRange, range) ->
29+
| SynExpr.Paren(expr, leftParenRange, rightParenRange, range) ->
3730
match expr with
38-
| SynExpr.App _ when isSkipExpr expr ->
39-
let newExpr = SynExpr.Const(SynConst.Unit, attr.ArgExpr.Range)
40-
base.VisitSynAttribute({ attr with ArgExpr = newExpr })
31+
| SynExpr.App _ when isSkipExpr(expr) ->
32+
let noAttributesArgExpr = SynExpr.Const(SynConst.Unit, attr.ArgExpr.Range)
33+
base.VisitSynAttribute({ attr with ArgExpr = noAttributesArgExpr })
4134
| SynExpr.Tuple(iStruct, exprs, commaRanges, tplRange) ->
42-
let newExpr =
43-
SynExpr.Paren(
44-
SynExpr.Tuple(iStruct, exprs |> List.filter (isSkipExpr >> not), commaRanges, tplRange), leftParenRange, rightParenRange, range)
45-
base.VisitSynAttribute({ attr with ArgExpr = newExpr })
35+
match List.tryFindIndex isSkipExpr exprs with
36+
| Some index ->
37+
let newExpr =
38+
SynExpr.Paren(
39+
SynExpr.Tuple(
40+
iStruct,
41+
exprs |> List.removeAt index,
42+
commaRanges |> List.removeAt (index - 1), tplRange
43+
),
44+
leftParenRange,
45+
rightParenRange,
46+
range)
47+
base.VisitSynAttribute({ attr with ArgExpr = newExpr })
48+
| None -> base.VisitSynAttribute(attr)
4649
| _ -> base.VisitSynAttribute(attr)
4750
| _ -> base.VisitSynAttribute(attr)
4851

4952
let private parseFile (filePath: string) =
5053
if File.Exists(filePath) then
5154
let source = File.ReadAllText(filePath)
52-
let sourceText = source |> SourceText.ofString
53-
let tree, diagnostics = parseFile false sourceText []
54-
Some tree // TODO: use diagnostics to determine success
55+
let sourceText = source |> SourceText.ofString
56+
let tree, _ = CodeFormatter.ParseAsync(false, source) |> Async.RunSynchronously |> Array.head
57+
Some tree
5558
|> Option.map (fun tree -> ParseSuccess(source, sourceText, tree))
5659
|> Option.defaultValue ParseError
5760
else
5861
ParseError
5962

60-
let private toCode code tree =
61-
CodeFormatter.FormatASTAsync(tree, code, FormatConfig.FormatConfig.Default)
63+
let private toCode tree =
64+
CodeFormatter.FormatASTAsync(tree)
6265
|> Async.RunSynchronously
6366
|> SourceText.ofString
6467

@@ -67,12 +70,17 @@ let private enableAllTests parsedInput =
6770

6871
let private rewriteProjectFile (context: TestRunContext) =
6972
let originalProjectFile = File.ReadAllText(context.ProjectFile)
70-
originalProjectFile, originalProjectFile.Replace("net5.0", "net6.0").Replace("net6.0", "net7.0")
73+
let rewrittenProjectFile =
74+
originalProjectFile
75+
.Replace("net5.0", "net8.0")
76+
.Replace("net6.0", "net8.0")
77+
.Replace("net7.0", "net8.0")
78+
originalProjectFile, rewrittenProjectFile
7179

7280
let rewriteTests (context: TestRunContext) =
7381
match parseFile context.TestsFile with
74-
| ParseSuccess (originalSource, originalSourceText, originalTestTree) ->
75-
let rewrittenTestCode = originalTestTree |> enableAllTests |> toCode originalSource
76-
let (originalProjectFile, rewrittenProjectFile) = rewriteProjectFile context
82+
| ParseSuccess (originalSource, originalSourceText, originalTestTree) ->
83+
let rewrittenTestCode = originalTestTree |> enableAllTests |> toCode
84+
let originalProjectFile, rewrittenProjectFile = rewriteProjectFile context
7785
RewriteSuccess(originalSourceText, originalTestTree, rewrittenTestCode, originalProjectFile, rewrittenProjectFile)
7886
| ParseError -> RewriteError

src/Exercism.TestRunner.FSharp/Testing.fs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
module Exercism.TestRunner.FSharp.Testing
22

3-
open System
43
open System.Diagnostics
54
open System.IO
65
open System.Text.RegularExpressions
76
open System.Xml.Serialization
87
open Exercism.TestRunner.FSharp.Core
98
open Exercism.TestRunner.FSharp.Rewrite
109
open Exercism.TestRunner.FSharp.Visitor
11-
open FSharp.Compiler.Syntax
12-
open FSharp.Compiler.Text
10+
open Fantomas.FCS.Syntax
11+
open Fantomas.FCS.Text
1312

1413
module String =
1514
let normalize (str: string) = str.Replace("\r\n", "\n").Trim()
1615

1716
let isNullOrWhiteSpace = System.String.IsNullOrWhiteSpace
1817

1918
module Process =
20-
let exec fileName arguments workingDirectory =
19+
let exec (fileName: string) (arguments: string) workingDirectory =
2120
let psi = ProcessStartInfo(fileName, arguments)
2221
psi.WorkingDirectory <- workingDirectory
2322
psi.RedirectStandardInput <- true
@@ -257,7 +256,9 @@ module DotnetCli =
257256

258257
let runTests originalTestCode originalTestTree context =
259258
let solutionDir = Path.GetDirectoryName(context.TestsFile)
260-
Process.exec "dotnet" $"test --verbosity=quiet --logger \"trx;LogFileName=%s{Path.GetFileName(context.TestResultsFile)}\" /flp:v=q" solutionDir
259+
260+
Process.exec "dotnet" "restore --source /root/.nuget/packages/" solutionDir
261+
Process.exec "dotnet" $"test --no-restore --verbosity=quiet --logger \"trx;LogFileName=%s{Path.GetFileName(context.TestResultsFile)}\" /flp:v=q" solutionDir
261262

262263
let buildErrors = parseBuildErrors context
263264

0 commit comments

Comments
 (0)