Skip to content

Commit

Permalink
Upgrade to .NET 8 (#218)
Browse files Browse the repository at this point in the history
* Upgrade to .NET 8

* Fix typing

* Update

* Upgrade F# core

* Initial fix

* Upgrade to latest Fantomas

* Upgrade FCS

* Fix

* Start rewriting

* Fix rewriting
  • Loading branch information
ErikSchierboom authored Apr 16, 2024
1 parent e611dea commit 658267c
Show file tree
Hide file tree
Showing 27 changed files with 163 additions and 89 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0.401-alpine3.18-amd64 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0.201-alpine3.19-amd64 AS build

WORKDIR /tmp

Expand All @@ -19,6 +19,7 @@ RUN dotnet add package FsCheck -v 2.16.3
RUN dotnet add package FsCheck.Xunit -v 2.14.3
RUN dotnet add package FSharp.Core -v 6.0.1
RUN dotnet add package FSharp.Core -v 7.0.400
RUN dotnet add package FSharp.Core -v 8.0.101
RUN dotnet add package FParsec -v 1.1.1

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

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

# Enable rolling forward the .NET SDK used to be backwards-compatible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand All @@ -20,11 +20,10 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Fantomas.Core" Version="5.1.5" />
<PackageReference Include="Fantomas.FCS" Version="5.1.5" />
<PackageReference Include="Fantomas.Core" Version="6.3.3" />
<PackageReference Include="Fantomas.FCS" Version="6.3.3" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="FsUnit.xUnit" Version="5.3.0" />
<PackageReference Update="FSharp.Core" Version="7.0.0" />
<PackageReference Update="FSharp.Core" Version="8.0.200" />
</ItemGroup>

</Project>
60 changes: 34 additions & 26 deletions src/Exercism.TestRunner.FSharp/Rewrite.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module Exercism.TestRunner.FSharp.Rewrite
open System.IO
open Exercism.TestRunner.FSharp.Core
open Exercism.TestRunner.FSharp.Visitor
open FSharp.Compiler.Syntax
open FSharp.Compiler.Text
open Fantomas.Core
open Fantomas.FCS.Syntax
open Fantomas.FCS.Text
open Fantomas.FCS.Parse

type ParseResult =
Expand All @@ -18,13 +18,6 @@ type RewriteResult =

type EnableAllTests() =
inherit SyntaxVisitor()

default this.VisitSynAttributeList(attrs: SynAttributeList) : SynAttributeList =
base.VisitSynAttributeList(
{ attrs with
Attributes =
attrs.Attributes
|> List.filter (fun attr -> attr.TypeName.LongIdent.Head.idText <> "Ignore") })

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

match attr.ArgExpr with
| SynExpr.Paren(expr, leftParenRange, rightParenRange, range) ->
| SynExpr.Paren(expr, leftParenRange, rightParenRange, range) ->
match expr with
| SynExpr.App _ when isSkipExpr expr ->
let newExpr = SynExpr.Const(SynConst.Unit, attr.ArgExpr.Range)
base.VisitSynAttribute({ attr with ArgExpr = newExpr })
| SynExpr.App _ when isSkipExpr(expr) ->
let noAttributesArgExpr = SynExpr.Const(SynConst.Unit, attr.ArgExpr.Range)
base.VisitSynAttribute({ attr with ArgExpr = noAttributesArgExpr })
| SynExpr.Tuple(iStruct, exprs, commaRanges, tplRange) ->
let newExpr =
SynExpr.Paren(
SynExpr.Tuple(iStruct, exprs |> List.filter (isSkipExpr >> not), commaRanges, tplRange), leftParenRange, rightParenRange, range)
base.VisitSynAttribute({ attr with ArgExpr = newExpr })
match List.tryFindIndex isSkipExpr exprs with
| Some index ->
let newExpr =
SynExpr.Paren(
SynExpr.Tuple(
iStruct,
exprs |> List.removeAt index,
commaRanges |> List.removeAt (index - 1), tplRange
),
leftParenRange,
rightParenRange,
range)
base.VisitSynAttribute({ attr with ArgExpr = newExpr })
| None -> base.VisitSynAttribute(attr)
| _ -> base.VisitSynAttribute(attr)
| _ -> base.VisitSynAttribute(attr)

let private parseFile (filePath: string) =
if File.Exists(filePath) then
let source = File.ReadAllText(filePath)
let sourceText = source |> SourceText.ofString
let tree, diagnostics = parseFile false sourceText []
Some tree // TODO: use diagnostics to determine success
let sourceText = source |> SourceText.ofString
let tree, _ = CodeFormatter.ParseAsync(false, source) |> Async.RunSynchronously |> Array.head
Some tree
|> Option.map (fun tree -> ParseSuccess(source, sourceText, tree))
|> Option.defaultValue ParseError
else
ParseError

let private toCode code tree =
CodeFormatter.FormatASTAsync(tree, code, FormatConfig.FormatConfig.Default)
let private toCode tree =
CodeFormatter.FormatASTAsync(tree)
|> Async.RunSynchronously
|> SourceText.ofString

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

let private rewriteProjectFile (context: TestRunContext) =
let originalProjectFile = File.ReadAllText(context.ProjectFile)
originalProjectFile, originalProjectFile.Replace("net5.0", "net6.0").Replace("net6.0", "net7.0")
let rewrittenProjectFile =
originalProjectFile
.Replace("net5.0", "net8.0")
.Replace("net6.0", "net8.0")
.Replace("net7.0", "net8.0")
originalProjectFile, rewrittenProjectFile

let rewriteTests (context: TestRunContext) =
match parseFile context.TestsFile with
| ParseSuccess (originalSource, originalSourceText, originalTestTree) ->
let rewrittenTestCode = originalTestTree |> enableAllTests |> toCode originalSource
let (originalProjectFile, rewrittenProjectFile) = rewriteProjectFile context
| ParseSuccess (originalSource, originalSourceText, originalTestTree) ->
let rewrittenTestCode = originalTestTree |> enableAllTests |> toCode
let originalProjectFile, rewrittenProjectFile = rewriteProjectFile context
RewriteSuccess(originalSourceText, originalTestTree, rewrittenTestCode, originalProjectFile, rewrittenProjectFile)
| ParseError -> RewriteError
11 changes: 6 additions & 5 deletions src/Exercism.TestRunner.FSharp/Testing.fs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
module Exercism.TestRunner.FSharp.Testing

open System
open System.Diagnostics
open System.IO
open System.Text.RegularExpressions
open System.Xml.Serialization
open Exercism.TestRunner.FSharp.Core
open Exercism.TestRunner.FSharp.Rewrite
open Exercism.TestRunner.FSharp.Visitor
open FSharp.Compiler.Syntax
open FSharp.Compiler.Text
open Fantomas.FCS.Syntax
open Fantomas.FCS.Text

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

let isNullOrWhiteSpace = System.String.IsNullOrWhiteSpace

module Process =
let exec fileName arguments workingDirectory =
let exec (fileName: string) (arguments: string) workingDirectory =
let psi = ProcessStartInfo(fileName, arguments)
psi.WorkingDirectory <- workingDirectory
psi.RedirectStandardInput <- true
Expand Down Expand Up @@ -257,7 +256,9 @@ module DotnetCli =

let runTests originalTestCode originalTestTree context =
let solutionDir = Path.GetDirectoryName(context.TestsFile)
Process.exec "dotnet" $"test --verbosity=quiet --logger \"trx;LogFileName=%s{Path.GetFileName(context.TestResultsFile)}\" /flp:v=q" solutionDir

Process.exec "dotnet" "restore --source /root/.nuget/packages/" solutionDir
Process.exec "dotnet" $"test --no-restore --verbosity=quiet --logger \"trx;LogFileName=%s{Path.GetFileName(context.TestResultsFile)}\" /flp:v=q" solutionDir

let buildErrors = parseBuildErrors context

Expand Down
Loading

0 comments on commit 658267c

Please sign in to comment.