Skip to content

Commit

Permalink
Merge pull request #8 from neosmart/github-ci
Browse files Browse the repository at this point in the history
Add CI

We should refactor the tests project to also run under .NET 2.0/4.0 where possible.
  • Loading branch information
mqudsi authored Apr 27, 2024
2 parents 079207f + 9685398 commit aa07828
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: .NET

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ${{ matrix.dotnet.os }}-latest

strategy:
matrix:
dotnet: [
{ os: 'windows', version: '2', tfm: 'net20' },
{ os: 'windows', version: '4', tfm: 'net40' },
{ os: 'ubuntu', version: '6', tfm: 'net6.0' },
{ os: 'ubuntu', version: '8', tfm: 'net8.0' },
]

steps:
- uses: actions/checkout@v4
- name: Setup .NET
if: endsWith(matrix.dotnet.tfm, '.0') # only for .NET core
uses: actions/setup-dotnet@v4
id: stepid
with:
dotnet-version: ${{ matrix.dotnet.version }}
# Without global.json, tests will be executed under the latest installed version!
- name: Create temporary global.json
if: endsWith(matrix.dotnet.tfm, '.0') # only for .NET core
run: echo '{"sdk":{"version":"${{steps.stepid.outputs.dotnet-version}}"}}' > ./global.json
- name: Restore packages
run: dotnet restore UrlBase64/UrlBase64.csproj -p:Configuration=Release -p:TargetFrameworks="${{ matrix.dotnet.tfm }}" -p:LangVersion="latest" --verbosity normal
- name: Build solution
run: dotnet build UrlBase64/UrlBase64.csproj -p:Configuration=Release -p:TargetFrameworks="${{ matrix.dotnet.tfm }}" -p:LangVersion="latest" --verbosity normal
- name: Run tests
if: endsWith(matrix.dotnet.tfm, '.0') # only for .NET core
run: dotnet test -p:Configuration=Release --verbosity normal -p:TargetFrameworks="${{ matrix.dotnet.tfm }}" -p:LangVersion="latest"
2 changes: 1 addition & 1 deletion Benchmark/Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions Tests/EncodeDecode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ public void DecodeNonUrlSafeBase64()
{
// Decoding regular base64 input with + instead of -
var input = "Q29udGFpbnMgYSBwbHVzIMOlw6bDn+KApuKIgsuaxpLiiIY=";
byte[] expected = [0x43, 0x6F, 0x6E, 0x74, 0x61, 0x69, 0x6E, 0x73, 0x20, 0x61, 0x20, 0x70, 0x6C, 0x75, 0x73, 0x20, 0xC3, 0xA5, 0xC3, 0xA6, 0xC3, 0x9F, 0xE2, 0x80, 0xA6, 0xE2, 0x88, 0x82, 0xCB, 0x9A, 0xC6, 0x92, 0xE2, 0x88, 0x86];
byte[] expected = new byte[] { 0x43, 0x6F, 0x6E, 0x74, 0x61, 0x69, 0x6E, 0x73, 0x20, 0x61, 0x20, 0x70, 0x6C, 0x75, 0x73, 0x20, 0xC3, 0xA5, 0xC3, 0xA6, 0xC3, 0x9F, 0xE2, 0x80, 0xA6, 0xE2, 0x88, 0x82, 0xCB, 0x9A, 0xC6, 0x92, 0xE2, 0x88, 0x86 };
var actual = UrlBase64.Decode(input);
CollectionAssert.AreEqual(expected, actual, "Mismatch in comparison results!");

// Decoding regular base64 input with / instead of _
input = "Q29udGFpbnMgYSBzbGFzaCDDuOKImsucw5/iiILiiJrLmsOn4oiC4omkw58=";
expected = [0x43, 0x6F, 0x6E, 0x74, 0x61, 0x69, 0x6E, 0x73, 0x20, 0x61, 0x20, 0x73, 0x6C, 0x61, 0x73, 0x68, 0x20, 0xC3, 0xB8, 0xE2, 0x88, 0x9A, 0xCB, 0x9C, 0xC3, 0x9F, 0xE2, 0x88, 0x82, 0xE2, 0x88, 0x9A, 0xCB, 0x9A, 0xC3, 0xA7, 0xE2, 0x88, 0x82, 0xE2, 0x89, 0xA4, 0xC3, 0x9F];
expected = new byte[] { 0x43, 0x6F, 0x6E, 0x74, 0x61, 0x69, 0x6E, 0x73, 0x20, 0x61, 0x20, 0x73, 0x6C, 0x61, 0x73, 0x68, 0x20, 0xC3, 0xB8, 0xE2, 0x88, 0x9A, 0xCB, 0x9C, 0xC3, 0x9F, 0xE2, 0x88, 0x82, 0xE2, 0x88, 0x9A, 0xCB, 0x9A, 0xC3, 0xA7, 0xE2, 0x88, 0x82, 0xE2, 0x89, 0xA4, 0xC3, 0x9F };
actual = UrlBase64.Decode(input);
CollectionAssert.AreEqual(expected, actual, "Mismatch in comparison results!");
}
Expand All @@ -196,7 +196,7 @@ public void DecodeInvalid()
Assert.ThrowsException<FormatException>(() => UrlBase64.Decode("!!"));

// ...and this doesn't
UrlBase64.Decode(UrlBase64.Encode([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]));
UrlBase64.Decode(UrlBase64.Encode(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }));
}
}

Expand Down
4 changes: 2 additions & 2 deletions UrlBase64/UrlBase64.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</None>
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard1.0' And '$(TargetFramework)' != 'net20' And '$(TargetFramework)' != 'net40'">
<DefineConstants>$(DefineConstants);WITH_SPAN</DefineConstants>
</PropertyGroup>

Expand All @@ -74,4 +74,4 @@
<LangVersion>10.0</LangVersion>
</PropertyGroup>

</Project>
</Project>

0 comments on commit aa07828

Please sign in to comment.