diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 655b977..7d115f8 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -56,13 +56,17 @@ jobs: echo $env:PATH dotnet --info Remove-Item $env:LocalAppData\Microsoft\dotnet/* -Recurse -Force -ErrorAction SilentlyContinue + - name: Setup dotnet 2.2.402 + uses: ./ + with: + dotnet-version: 2.2.402 - name: Setup dotnet 3.1.201 uses: ./ with: dotnet-version: 3.1.201 - name: Verify dotnet if: runner.os != 'windows' - run: __tests__/verify-dotnet.sh 3.1.201 + run: __tests__/verify-dotnet.sh 3.1.201 2.2.402 - name: Verify dotnet (Windows) if: runner.os == 'windows' run: __tests__/verify-dotnet.ps1 3.1.201 @@ -89,12 +93,13 @@ jobs: run: | apt update apt -y install curl - - name: Setup dotnet 3.1.201 + # 2.2 uses nuget to download the JSON nuget package, the package is built into 3.1 + - name: Setup dotnet 2.2.402 uses: ./ with: - dotnet-version: 3.1.201 + dotnet-version: 2.2.402 - name: Verify dotnet - run: __tests__/verify-dotnet.sh 3.1.201 + run: __tests__/verify-dotnet.sh 2.2.402 test-bypass-proxy: runs-on: ubuntu-latest @@ -106,9 +111,10 @@ jobs: uses: actions/checkout@v2 - name: Clear tool cache run: rm -rf "/usr/share/dotnet" - - name: Setup dotnet 3.1.201 + # 2.2 uses nuget to download the JSON nuget package, the package is built into 3.1 + - name: Setup dotnet 2.2.402 uses: ./ with: - dotnet-version: 3.1.201 + dotnet-version: 2.2.402 - name: Verify dotnet - run: __tests__/verify-dotnet.sh 3.1.201 + run: __tests__/verify-dotnet.sh 2.2.402 diff --git a/__tests__/sample-csproj/Program.cs b/__tests__/sample-csproj/Program.cs index 807ab56..e52bc6e 100644 --- a/__tests__/sample-csproj/Program.cs +++ b/__tests__/sample-csproj/Program.cs @@ -1,13 +1,16 @@ -using System; -using Newtonsoft.Json; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Text.Json; +using System; namespace sample_csproj { - class Program + [TestClass] + public class Program { - static void Main(string[] args) + [TestMethod] + public void TestMethod1() { - var json = JsonConvert.SerializeObject(new[] {"Hello", "World!" }); + var json = JsonSerializer.Serialize(new[] {"Hello", "World!" }); Console.WriteLine(json); } } diff --git a/__tests__/sample-csproj/runtimeconfig.template.json b/__tests__/sample-csproj/runtimeconfig.template.json deleted file mode 100644 index 18708fd..0000000 --- a/__tests__/sample-csproj/runtimeconfig.template.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "runtimeOptions": { - "configProperties": { - "System.Globalization.Invariant": true - } - } -} \ No newline at end of file diff --git a/__tests__/sample-csproj/sample.csproj b/__tests__/sample-csproj/sample.csproj index 1aeea5c..7a997fb 100644 --- a/__tests__/sample-csproj/sample.csproj +++ b/__tests__/sample-csproj/sample.csproj @@ -1,13 +1,18 @@ - Exe - netcoreapp3.0 + netcoreapp3.1;netcoreapp2.2 sample_csproj + + false - + + + + + diff --git a/__tests__/verify-dotnet.ps1 b/__tests__/verify-dotnet.ps1 index d3f0303..b253807 100755 --- a/__tests__/verify-dotnet.ps1 +++ b/__tests__/verify-dotnet.ps1 @@ -8,13 +8,23 @@ Write-Host "Found '$dotnet'" $version = & $dotnet --version | Out-String | ForEach-Object { $_.Trim() } Write-Host "Version $version" -# if ($version -ne $args[0]) -# { -# Write-Host "PATH='$env:path'" -# Write-Host "gcm dotnet:" -# gcm dotnet | fl -# throw "Unexpected version" -# } +if ($version -ne $args[0]) +{ + Write-Host "PATH='$env:path'" + throw "Unexpected version" +} + +if ($args[1]) +{ + # SDKs are listed on multiple lines with the path afterwards in square brackets + $version = & $dotnet --list-sdks | ForEach-Object { $_.SubString(0, $_.IndexOf('[')).Trim() } + Write-Host "Version $version" + if (-not ($version -contains $args[1])) + { + Write-Host "PATH='$env:path'" + throw "Unexpected version" + } +} Write-Host "Building sample csproj" & $dotnet build __tests__/sample-csproj/ --no-cache @@ -24,9 +34,20 @@ if ($LASTEXITCODE -ne 0) } Write-Host "Testing compiled app" -$sample_output = "$(__tests__/sample-csproj/bin/Debug/netcoreapp3.0/sample.exe)".Trim() +$sample_output = "$(dotnet test __tests__/sample-csproj/ --no-build)" Write-Host "Sample output: $sample_output" -if ($sample_output -notlike "*Hello*World*") +# For Side-by-Side installs we want to run the tests twice, for a single install the tests will run once +if ($args[1]) { - throw "Unexpected output" + if ($sample_output -notlike "*Test Run Successful.*Test Run Successful.*") + { + throw "Unexpected output" + } +} +else +{ + if ($sample_output -notlike "*Test Run Successful.*") + { + throw "Unexpected output" + } } diff --git a/__tests__/verify-dotnet.sh b/__tests__/verify-dotnet.sh index bdb2a46..9807577 100755 --- a/__tests__/verify-dotnet.sh +++ b/__tests__/verify-dotnet.sh @@ -10,13 +10,30 @@ if [ -z "$(echo $dotnet_version | grep $1)" ]; then exit 1 fi +if [ -n "$2" ]; then + dotnet_version="$(dotnet --list-sdks)" + echo "Found dotnet version '$dotnet_version'" + if [ -z "$(echo $dotnet_version | grep $2)" ]; then + echo "Unexpected version" + exit 1 + fi +fi + echo "Building sample csproj" dotnet build __tests__/sample-csproj/ --no-cache || exit 1 echo "Testing compiled app" -sample_output=$(dotnet run --project __tests__/sample-csproj/ --no-build) +sample_output=$(dotnet test __tests__/sample-csproj/ --no-build) echo "Sample output: $sample_output" -if [ -z "$(echo $sample_output | grep Hello)" ]; then - echo "Unexpected output" - exit 1 +# For Side-by-Side installs we want to run the tests twice, for a single install the tests will run once +if [ -n "$2" ]; then + if [ -z "$(echo $sample_output | grep "Test Run Successful.*Test Run Successful.")" ]; then + echo "Unexpected output" + exit 1 + fi +else + if [ -z "$(echo $sample_output | grep "Test Run Successful.")" ]; then + echo "Unexpected output" + exit 1 + fi fi \ No newline at end of file