diff --git a/Makefile.am b/Makefile.am index 2de08840fefe0..dd564e8838d78 100644 --- a/Makefile.am +++ b/Makefile.am @@ -57,6 +57,7 @@ csharp_EXTRA_DIST= \ csharp/README.md \ csharp/build_packages.bat \ csharp/build_tools.sh \ + csharp/buildall.bat \ csharp/buildall.sh \ csharp/generate_protos.sh \ csharp/install_dotnet_sdk.ps1 \ diff --git a/appveyor.bat b/appveyor.bat index 29ec4922ae9d5..7a35ceb4d678e 100644 --- a/appveyor.bat +++ b/appveyor.bat @@ -38,7 +38,7 @@ dotnet restore dotnet build -c %configuration% || goto error echo Testing C# -dotnet test -c %configuration% -f netcoreapp1.0 Google.Protobuf.Test\Google.Protobuf.Test.csproj || goto error +dotnet test -c %configuration% -f netcoreapp2.1 Google.Protobuf.Test\Google.Protobuf.Test.csproj || goto error dotnet test -c %configuration% -f net451 Google.Protobuf.Test\Google.Protobuf.Test.csproj || goto error goto :EOF diff --git a/csharp/buildall.bat b/csharp/buildall.bat new file mode 100644 index 0000000000000..821ffb3102bec --- /dev/null +++ b/csharp/buildall.bat @@ -0,0 +1,13 @@ +@rem Builds Google.Protobuf and runs the tests + +dotnet build src/Google.Protobuf.sln || goto :error + +echo Running tests. + +dotnet test src/Google.Protobuf.Test/Google.Protobuf.Test.csproj || goto :error + +goto :EOF + +:error +echo Failed! +exit /b %errorlevel% diff --git a/csharp/buildall.sh b/csharp/buildall.sh index 50d8906dceb44..43b5ac3ffb29a 100755 --- a/csharp/buildall.sh +++ b/csharp/buildall.sh @@ -10,8 +10,8 @@ dotnet restore $SRC/Google.Protobuf.sln dotnet build -c $CONFIG $SRC/Google.Protobuf.sln echo Running tests. -# Only test netcoreapp1.0, which uses the .NET Core runtime. +# Only test netcoreapp2.1, which uses the .NET Core runtime. # If we want to test the .NET 4.5 version separately, we could # run Mono explicitly. However, we don't have any differences between -# the .NET 4.5 and netstandard1.0 assemblies. -dotnet test -c $CONFIG -f netcoreapp1.0 $SRC/Google.Protobuf.Test/Google.Protobuf.Test.csproj +# the .NET 4.5 and netstandard2.1 assemblies. +dotnet test -c $CONFIG -f netcoreapp2.1 $SRC/Google.Protobuf.Test/Google.Protobuf.Test.csproj diff --git a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs index 129923b60942b..b3863a4965a10 100644 --- a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs +++ b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs @@ -750,7 +750,8 @@ public void NaNValuesComparedBitwise() var list2 = new RepeatedField { SampleNaNs.Regular, SampleNaNs.PayloadFlipped }; var list3 = new RepeatedField { SampleNaNs.Regular, SampleNaNs.SignallingFlipped }; - EqualityTester.AssertInequality(list1, list2); + // All SampleNaNs have the same hashcode under certain targets (e.g. netcoreapp2.1) + EqualityTester.AssertInequality(list1, list2, checkHashcode: false); EqualityTester.AssertEquality(list1, list3); Assert.True(list1.Contains(SampleNaNs.SignallingFlipped)); Assert.False(list2.Contains(SampleNaNs.SignallingFlipped)); diff --git a/csharp/src/Google.Protobuf.Test/EqualityTester.cs b/csharp/src/Google.Protobuf.Test/EqualityTester.cs index a669baba17bfd..d4b3c1341ac68 100644 --- a/csharp/src/Google.Protobuf.Test/EqualityTester.cs +++ b/csharp/src/Google.Protobuf.Test/EqualityTester.cs @@ -49,13 +49,14 @@ public static void AssertEquality(T first, T second) where T : IEquatable Assert.AreEqual(first.GetHashCode(), second.GetHashCode()); } - public static void AssertInequality(T first, T second) where T : IEquatable + public static void AssertInequality(T first, T second, bool checkHashcode = true) where T : IEquatable { Assert.IsFalse(first.Equals(second)); Assert.IsFalse(first.Equals((object) second)); // While this isn't a requirement, the chances of this test failing due to // coincidence rather than a bug are very small. - if (first != null && second != null) + // For such rare cases, an argument can be used to disable the check. + if (checkHashcode && first != null && second != null) { Assert.AreNotEqual(first.GetHashCode(), second.GetHashCode()); } diff --git a/kokoro/release/csharp/windows/build_nuget.bat b/kokoro/release/csharp/windows/build_nuget.bat index fdb02b06853cb..0ff8db04284ff 100644 --- a/kokoro/release/csharp/windows/build_nuget.bat +++ b/kokoro/release/csharp/windows/build_nuget.bat @@ -7,4 +7,8 @@ cd csharp powershell -File install_dotnet_sdk.ps1 set PATH=%LOCALAPPDATA%\Microsoft\dotnet;%PATH% +@rem Disable some unwanted dotnet options +set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true +set DOTNET_CLI_TELEMETRY_OPTOUT=true + call build_packages.bat diff --git a/kokoro/windows/csharp/build.bat b/kokoro/windows/csharp/build.bat new file mode 100644 index 0000000000000..95224f2eb21d2 --- /dev/null +++ b/kokoro/windows/csharp/build.bat @@ -0,0 +1,14 @@ +@rem enter repo root +cd /d %~dp0\..\..\.. + +cd csharp + +@rem Install dotnet SDK +powershell -File install_dotnet_sdk.ps1 +set PATH=%LOCALAPPDATA%\Microsoft\dotnet;%PATH% + +@rem Disable some unwanted dotnet options +set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true +set DOTNET_CLI_TELEMETRY_OPTOUT=true + +call buildall.bat diff --git a/kokoro/windows/csharp/continuous.cfg b/kokoro/windows/csharp/continuous.cfg new file mode 100644 index 0000000000000..f586585176b10 --- /dev/null +++ b/kokoro/windows/csharp/continuous.cfg @@ -0,0 +1,5 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/windows/csharp/build.bat" +timeout_mins: 1440 diff --git a/tests.sh b/tests.sh index 265a8c0933390..b690dd25367b1 100755 --- a/tests.sh +++ b/tests.sh @@ -117,6 +117,12 @@ build_csharp() { internal_build_cpp NUGET=/usr/local/bin/nuget.exe + # Disable some unwanted dotnet options + export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true + export DOTNET_CLI_TELEMETRY_OPTOUT=true + + # TODO(jtattermusch): is this still needed with "first time experience" + # disabled? # Perform "dotnet new" once to get the setup preprocessing out of the # way. That spews a lot of output (including backspaces) into logs # otherwise, and can cause problems. It doesn't matter if this step