Skip to content

Commit

Permalink
Upgrade to .NET 9 (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
BNAndras authored Mar 4, 2025
1 parent e841a37 commit d325133
Show file tree
Hide file tree
Showing 51 changed files with 231 additions and 90 deletions.
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0.100-alpine3.16-amd64 AS build
FROM mcr.microsoft.com/dotnet/sdk:9.0.200-alpine3.21-amd64 AS build

WORKDIR /tmp

# Pre-install packages for offline usage
RUN dotnet new console && \
dotnet add package Microsoft.NET.Test.Sdk -v 17.4.1 && \
dotnet add package xunit -v 2.4.2 && \
dotnet add package xunit.runner.visualstudio -v 2.4.5
dotnet add package xunit.runner.visualstudio -v 2.4.5 && \
dotnet add package Microsoft.NET.Test.Sdk -v 17.12.0 && \
dotnet add package xunit -v 2.8.1 && \
dotnet add package xunit.runner.visualstudio -v 3.0.1

# Build runtime image
FROM mcr.microsoft.com/dotnet/sdk:7.0.100-alpine3.16-amd64 AS runtime
FROM mcr.microsoft.com/dotnet/sdk:9.0.200-alpine3.21-amd64 AS runtime

RUN apk add --no-cache bash jq

WORKDIR /opt/test-runner

# Enable rolling forward the .NET SDK used to be backwards-compatible
ENV DOTNET_ROLL_FORWARD Major
ENV DOTNET_ROLL_FORWARD=Major

COPY --from=build /root/.nuget/packages/ /root/.nuget/packages/
COPY bin/ bin/
Expand Down
8 changes: 4 additions & 4 deletions bin/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ for test_dir in tests/*; do

# TODO: this is a temporary fix around the fact that tests are not returned in order
# and the .message property can thus not be checked
if [ "${test_dir_name}" == "example-all-fail" ] ||
[ "${test_dir_name}" == "example-partial-fail" ]; then
if [ "${test_dir_name}" == "all-fail" ] ||
[ "${test_dir_name}" == "partial-fail" ]; then
cp "${expected_results_file_path}" "${expected_results_original_file_path}"
actual_message=$(jq -r '.message' "${results_file_path}")
jq --arg m "${actual_message}" '.message = $m' "${expected_results_original_file_path}" > "${tmp_results_file_path}" && mv "${tmp_results_file_path}" "${expected_results_file_path}"
Expand All @@ -49,8 +49,8 @@ for test_dir in tests/*; do

# TODO: this is a temporary fix around the fact that tests are not returned in order
# and the .message property can thus not be checked
if [ "${test_dir_name}" == "example-all-fail" ] ||
[ "${test_dir_name}" == "example-partial-fail" ]; then
if [ "${test_dir_name}" == "all-fail" ] ||
[ "${test_dir_name}" == "partial-fail" ]; then
mv "${expected_results_original_file_path}" "${expected_results_file_path}"
fi
done
Expand Down
8 changes: 6 additions & 2 deletions bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ fi
slug="$1"
input_dir="${2%/}"
output_dir="${3%/}"
exercise=$(echo "${slug}" | sed -r 's/(^|-)([a-z])/\U\2/g')
exercise=$(echo "${slug}" | awk -F'-' '{ for (i=1; i<=NF; i++) { $i = toupper(substr($i,1,1)) substr($i,2) } } 1' OFS='')
tests_file="${input_dir}/$(jq -r '.files.test[0]' "${input_dir}/.meta/config.json")"
tests_file_original="${tests_file}.original"
results_file="${output_dir}/results.json"
project_file="${input_dir}/${exercise}.vbproj"

# Create the output directory if it doesn't exist
mkdir -p "${output_dir}"
Expand All @@ -39,11 +40,14 @@ cp "${tests_file}" "${tests_file_original}"
# Unskip tests
sed -i -E 's/Skip *:= *"Remove this Skip property to run this test"//' "${tests_file}"

# Fixup target framework
sed -i -E 's#<TargetFramework>(.+?)</TargetFramework>#<TargetFramework>net9.0</TargetFramework>#' "${project_file}"

pushd "${input_dir}" > /dev/null

# Run the tests for the provided implementation file and redirect stdout and
# stderr to capture it
test_output=$(dotnet test 2>&1)
test_output=$(dotnet restore --source /root/.nuget/packages/ && dotnet test -c release --no-restore 2>&1)
exit_code=$?

popd > /dev/null
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
],
"files": {
"solution": [
"Leap.vb"
"AllFail.vb"
],
"test": [
"LeapTests.vb"
"AllFailTests.vb"
],
"example": [
".meta/Example.vb"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1" />
</ItemGroup>

</Project>
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/all-fail/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": 1,
"status": "fail",
"message": "[xUnit.net 00:00:00.11] AllFail.LeapTests.Year_divisible_by_400_but_not_by_125_is_still_a_leap_year [FAIL]\n[xUnit.net 00:00:00.12] AllFail.LeapTests.Year_divisible_by_4_not_divisible_by_100_in_leap_year [FAIL]\n[xUnit.net 00:00:00.12] AllFail.LeapTests.Year_divisible_by_400_in_leap_year [FAIL]\n[xUnit.net 00:00:00.12] AllFail.LeapTests.Year_divisible_by_4_and_5_is_still_a_leap_year [FAIL]\n[xUnit.net 00:00:00.12] AllFail.LeapTests.Year_not_divisible_by_4_in_common_year [FAIL]\n Failed AllFail.LeapTests.Year_divisible_by_400_but_not_by_125_is_still_a_leap_year [3 ms]\n Error Message:\n Assert.True() Failure\nExpected: True\nActual: False\n Stack Trace:\n at AllFail.LeapTests.Year_divisible_by_400_but_not_by_125_is_still_a_leap_year() in /solution/AllFailTests.vb:line 41\n at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)\n at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)\n Failed AllFail.LeapTests.Year_divisible_by_4_not_divisible_by_100_in_leap_year [< 1 ms]\n Error Message:\n Assert.True() Failure\nExpected: True\nActual: False\n Stack Trace:\n at AllFail.LeapTests.Year_divisible_by_4_not_divisible_by_100_in_leap_year() in /solution/AllFailTests.vb:line 16\n at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)\n at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)\n Failed AllFail.LeapTests.Year_divisible_by_400_in_leap_year [< 1 ms]\n Error Message:\n Assert.True() Failure\nExpected: True\nActual: False\n Stack Trace:\n at AllFail.LeapTests.Year_divisible_by_400_in_leap_year() in /solution/AllFailTests.vb:line 36\n at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)\n at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)\n Failed AllFail.LeapTests.Year_divisible_by_4_and_5_is_still_a_leap_year [< 1 ms]\n Error Message:\n Assert.True() Failure\nExpected: True\nActual: False\n Stack Trace:\n at AllFail.LeapTests.Year_divisible_by_4_and_5_is_still_a_leap_year() in /solution/AllFailTests.vb:line 21\n at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)\n at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)\n Failed AllFail.LeapTests.Year_not_divisible_by_4_in_common_year [< 1 ms]\n Error Message:\n Assert.False() Failure\nExpected: False\nActual: True\n Stack Trace:\n at AllFail.LeapTests.Year_not_divisible_by_4_in_common_year() in /solution/AllFailTests.vb:line 6\n at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)\n at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)\n\nFailed! - Failed: 5, Passed: 4, Skipped: 0, Total: 9, - AllFail.dll (net9.0)"
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
],
"files": {
"solution": [
"Leap.vb"
"EmptyFile.vb"
],
"test": [
"LeapTests.vb"
"EmptyFileTests.vb"
],
"example": [
".meta/Example.vb"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1" />
</ItemGroup>

</Project>
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/empty-file/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": 1,
"status": "fail",
"message": "/solution/EmptyFileTests.vb(6,24): error BC30451: 'Leap' is not declared. It may be inaccessible due to its protection level. [/solution/EmptyFile.vbproj]\n/solution/EmptyFileTests.vb(11,24): error BC30451: 'Leap' is not declared. It may be inaccessible due to its protection level. [/solution/EmptyFile.vbproj]\n/solution/EmptyFileTests.vb(16,23): error BC30451: 'Leap' is not declared. It may be inaccessible due to its protection level. [/solution/EmptyFile.vbproj]\n/solution/EmptyFileTests.vb(21,23): error BC30451: 'Leap' is not declared. It may be inaccessible due to its protection level. [/solution/EmptyFile.vbproj]\n/solution/EmptyFileTests.vb(26,24): error BC30451: 'Leap' is not declared. It may be inaccessible due to its protection level. [/solution/EmptyFile.vbproj]\n/solution/EmptyFileTests.vb(31,24): error BC30451: 'Leap' is not declared. It may be inaccessible due to its protection level. [/solution/EmptyFile.vbproj]\n/solution/EmptyFileTests.vb(36,23): error BC30451: 'Leap' is not declared. It may be inaccessible due to its protection level. [/solution/EmptyFile.vbproj]\n/solution/EmptyFileTests.vb(41,23): error BC30451: 'Leap' is not declared. It may be inaccessible due to its protection level. [/solution/EmptyFile.vbproj]\n/solution/EmptyFileTests.vb(46,24): error BC30451: 'Leap' is not declared. It may be inaccessible due to its protection level. [/solution/EmptyFile.vbproj]"
}
5 changes: 0 additions & 5 deletions tests/example-all-fail/expected_results.json

This file was deleted.

5 changes: 0 additions & 5 deletions tests/example-empty-file/expected_results.json

This file was deleted.

5 changes: 0 additions & 5 deletions tests/example-partial-fail/expected_results.json

This file was deleted.

22 changes: 0 additions & 22 deletions tests/example-syntax-error/.meta/config.json

This file was deleted.

13 changes: 0 additions & 13 deletions tests/example-syntax-error/Leap.vbproj

This file was deleted.

5 changes: 0 additions & 5 deletions tests/example-syntax-error/expected_results.json

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
],
"files": {
"solution": [
"Leap.vb"
"Net7.vb"
],
"test": [
"LeapTests.vb"
"Net7Tests.vb"
],
"example": [
".meta/Example.vb"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions tests/partial-fail/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"blurb": "Given a year, report if it is a leap year.",
"authors": [
"ch020"
],
"contributors": [
"axtens"
],
"files": {
"solution": [
"PartialFail.vb"
],
"test": [
"PartialFailTests.vb"
],
"example": [
".meta/Example.vb"
]
},
"source": "JavaRanch Cattle Drive, exercise 3",
"source_url": "http://www.javaranch.com/leap.jsp"
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1" />
</ItemGroup>

</Project>
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/partial-fail/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": 1,
"status": "fail",
"message": "[xUnit.net 00:00:00.11] PartialFail.LeapTests.Year_divisible_by_4_and_5_is_still_a_leap_year [FAIL]\n[xUnit.net 00:00:00.11] PartialFail.LeapTests.Year_divisible_by_4_not_divisible_by_100_in_leap_year [FAIL]\n Failed PartialFail.LeapTests.Year_divisible_by_4_and_5_is_still_a_leap_year [1 ms]\n Error Message:\n Assert.True() Failure\nExpected: True\nActual: False\n Stack Trace:\n at PartialFail.LeapTests.Year_divisible_by_4_and_5_is_still_a_leap_year() in /solution/PartialFailTests.vb:line 21\n at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)\n at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)\n Failed PartialFail.LeapTests.Year_divisible_by_4_not_divisible_by_100_in_leap_year [< 1 ms]\n Error Message:\n Assert.True() Failure\nExpected: True\nActual: False\n Stack Trace:\n at PartialFail.LeapTests.Year_divisible_by_4_not_divisible_by_100_in_leap_year() in /solution/PartialFailTests.vb:line 16\n at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)\n at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)\n\nFailed! - Failed: 2, Passed: 7, Skipped: 0, Total: 9, - PartialFail.dll (net9.0)"
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
],
"files": {
"solution": [
"Leap.vb"
"Success.vb"
],
"test": [
"LeapTests.vb"
"SuccessTests.vb"
],
"example": [
".meta/Example.vb"
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/success/Success.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Public Module Leap
Public Function IsLeapYear(ByVal year As Integer) As Boolean
Return year Mod 400 = 0 OrElse (year Mod 100 <> 0 AndAlso year Mod 4 = 0)
End Function
End Module
13 changes: 13 additions & 0 deletions tests/success/Success.vbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1" />
</ItemGroup>

</Project>
File renamed without changes.
4 changes: 4 additions & 0 deletions tests/success/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": 1,
"status": "pass"
}
5 changes: 5 additions & 0 deletions tests/syntax-error/.meta/Example.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Public Module Leap
Public Function IsLeapYear(ByVal year As Integer) As Boolean
Return year Mod 400 = 0 OrElse (year Mod 100 <> 0 AndAlso year Mod 4 = 0)
End Function
End Module
22 changes: 22 additions & 0 deletions tests/syntax-error/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"blurb": "Given a year, report if it is a leap year.",
"authors": [
"ch020"
],
"contributors": [
"axtens"
],
"files": {
"solution": [
"SyntaxError.vb"
],
"test": [
"SyntaxErrorTests.vb"
],
"example": [
".meta/Example.vb"
]
},
"source": "JavaRanch Cattle Drive, exercise 3",
"source_url": "http://www.javaranch.com/leap.jsp"
}
Loading

0 comments on commit d325133

Please sign in to comment.