Skip to content

Commit

Permalink
Windows support (#43)
Browse files Browse the repository at this point in the history
* More Windows Spec Fixes

Handle differences in exit status representation, and fixup more names.

* CI on Windows

Add a job to run the comiler on Windows too.

* Powershell on Windows

* Set Line Endings for Scheme Files

* Set Encoding on Stdout

* UTF-8 Code Page on CI

* Force Output Encoding on Windows

Trying to get unicode output working for tests.
  • Loading branch information
iwillspeak authored Oct 22, 2021
1 parent b2d3d4b commit 599d2e4
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ root = true
[*]
insert_final_newline = true

[*.{scm,sld}]
indent_style = space
indent_size = 4
end_of_line = lf

[*.cs]
indent_style = space
indent_size = 4
Expand Down
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Scheme files in our spec folder are line ending sensitive. Without this our
# specs would fail as diagnostics have different byte indices.
*.scm text eol=lf
*.sld text eol=lf
29 changes: 25 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,31 @@ trigger:
include:
- 'v*'

pool:
vmImage: ubuntu-latest
jobs:

steps:
- job: Windows
pool:
vmImage: 'windows-latest'
steps:
- task: UseDotNet@2
displayName: 'Use .NET 5.0 sdk'
inputs:
packageType: sdk
version: 5.0.x
- pwsh: |
chcp 65001
dotnet build --configuration $(configuration)
dotnet test --no-build --configuration $(configuration) --logger 'trx' --logger 'console;verbosity=normal'
- task: PublishTestResults@2
condition: always()
inputs:
testResultsFormat: 'VSTest'
testResultsFiles: '**/TestResults/*.trx'

- job: Linux
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UseDotNet@2
displayName: 'Use .NET 5.0 sdk'
inputs:
Expand All @@ -39,4 +60,4 @@ steps:
dotnet nuget push --api-key $API_KEY --source "NuGetOrg" $(Build.ArtifactStagingDirectory)/*.nupkg
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags'))
env:
API_KEY: $(NuGetOrgApiKey)
API_KEY: $(NuGetOrgApiKey)
9 changes: 9 additions & 0 deletions src/Serehfa/Write.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Text;
using Serehfa.Attributes;
using System.Runtime.InteropServices;

namespace Serehfa
{
Expand All @@ -9,6 +10,14 @@ namespace Serehfa
[LispLibrary("scheme", "write")]
public static class Write
{
static Write()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Console.OutputEncoding = Encoding.UTF8;
}
}

/// <summary>
/// The newline method. This is a prime candidate for being moved to
/// a pure scheme definition.
Expand Down
16 changes: 11 additions & 5 deletions test/Feersum.Tests/SpecTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ open System.IO
open Snapper
open System.Diagnostics
open SyntaxUtils
open System.Text

// This type has to be public so `Snapper` can see it.
type TestExecutionResult =
{ Output: string
; Error: string
; Exit: int }
; Exit: byte }

let specDir = Path.Join(__SOURCE_DIRECTORY__, "..", "..", "spec")
let specBin = Path.Join(specDir, "bin")
Expand Down Expand Up @@ -43,6 +44,8 @@ let private runExample host exePath =
p.StartInfo <- ProcessStartInfo(host)
p.StartInfo.ArgumentList.Add(exePath)
p.StartInfo.UseShellExecute <- false
p.StartInfo.StandardErrorEncoding <- Encoding.UTF8
p.StartInfo.StandardOutputEncoding <- Encoding.UTF8
// TODO: support spec tests with `.input` files.
// p.StartInfo.RedirectStandardInput <- true
p.StartInfo.RedirectStandardOutput <- true
Expand All @@ -56,7 +59,9 @@ let private runExample host exePath =
p.WaitForExit()
{ Output = output.[0] |> normaliseEndings
; Error = output.[1] |> normaliseEndings
; Exit = p.ExitCode }
// Exit codes on windows are full integers. Clamp everything to a byte so we
// have partiy with POSIX systems
; Exit = byte ((uint p.ExitCode) &&& 0xFFu) }

let private parseDirectives (sourcePath: string) =
let parseDirective (line: string) =
Expand Down Expand Up @@ -112,16 +117,17 @@ let ``spec tests compile and run`` specPath configuration =
// Compile the output assembly, and run the appropriate assertions
let options = { options with OutputType = Exe; References = references }
let exePath = artifactpath options specPath
let specName = specPath |> normalisePath
match compileFile options exePath sourcePath with
| [] ->
if shouldFail then
failwith "Expected compilation failure!"
let r = runExample "dotnet" exePath
r.ShouldMatchChildSnapshot(specPath)
r.ShouldMatchChildSnapshot(specName)
| diags ->
if not shouldFail then
failwithf "Compilation error: %A" diags
(diags |> diagSanitiser).ShouldMatchChildSnapshot(specPath)
(diags |> diagSanitiser).ShouldMatchChildSnapshot(specName)

let public getParseTestData () =
Seq.append librarySpecs executableSpecs
Expand All @@ -132,4 +138,4 @@ let public getParseTestData () =
let ``spec tests parse result`` s =
let node, diagnostics = parseFile (Path.Join(specDir, s))
let tree = (node |> nodeSanitiser, diagnostics |> diagSanitiser)
tree.ShouldMatchSnapshot(Core.SnapshotId(snapDir, "Parse", s))
tree.ShouldMatchSnapshot(Core.SnapshotId(snapDir, "Parse", s |> normalisePath))

0 comments on commit 599d2e4

Please sign in to comment.