Skip to content

Commit

Permalink
Merge pull request #5876 from jtattermusch/csharp_win_tests
Browse files Browse the repository at this point in the history
C# testing improvements
  • Loading branch information
jtattermusch authored Mar 13, 2019
2 parents 93533f7 + 60a889e commit db1d4dc
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 7 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion appveyor.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions csharp/buildall.bat
Original file line number Diff line number Diff line change
@@ -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%
6 changes: 3 additions & 3 deletions csharp/buildall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,8 @@ public void NaNValuesComparedBitwise()
var list2 = new RepeatedField<double> { SampleNaNs.Regular, SampleNaNs.PayloadFlipped };
var list3 = new RepeatedField<double> { 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));
Expand Down
5 changes: 3 additions & 2 deletions csharp/src/Google.Protobuf.Test/EqualityTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ public static void AssertEquality<T>(T first, T second) where T : IEquatable<T>
Assert.AreEqual(first.GetHashCode(), second.GetHashCode());
}

public static void AssertInequality<T>(T first, T second) where T : IEquatable<T>
public static void AssertInequality<T>(T first, T second, bool checkHashcode = true) where T : IEquatable<T>
{
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());
}
Expand Down
4 changes: 4 additions & 0 deletions kokoro/release/csharp/windows/build_nuget.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions kokoro/windows/csharp/build.bat
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions kokoro/windows/csharp/continuous.cfg
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit db1d4dc

Please sign in to comment.