[C#] Cleaned up .NET testing script for Mono (#6016)

* Cleaned up .NET testing script for Mono

Cleaned up the .NET testing script to make it a little better. It
purposefully doesn't delete the .NET installer and SDk after running the
script, so that they can be used in subsequent invocations. This greatly
speeds up the script.

The downloaded files are ignored by git by default. They can be
explicitly cleaned up by runnning the clean script (clean.sh).

* Trying using older Version indicator

* Remove lins to monsterdata and reference it directly.

* Updated appveryor script to remove copying of files no longer needed

* Continue to update appveyor script to work. Disabled CS0169 in ByteBufferTest
This commit is contained in:
Derek Bailey 2020-08-17 13:10:10 -07:00 committed by GitHub
parent 63cc0eec4e
commit db2aa9b4ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 92 additions and 42 deletions

View File

@ -107,16 +107,15 @@ test_script:
# Have to compile this here rather than in "build" above because AppVeyor only
# supports building one project??
- "cd FlatBuffers.Test"
- "copy ..\\monsterdata_test.mon Resources\\"
- "copy ..\\monsterdata_test.json Resources\\"
- "dotnet new sln"
- "dotnet sln add FlatBuffers.Test.csproj"
- "nuget restore"
- "msbuild.exe /property:Configuration=Release;OutputPath=tempcs /verbosity:minimal FlatBuffers.Test.csproj"
- "tempcs\\FlatBuffers.Test.exe"
- "mkdir .tmp"
- "msbuild.exe /property:Configuration=Release;OutputPath=.tmp /verbosity:minimal FlatBuffers.Test.csproj"
- ".tmp\\FlatBuffers.Test.exe"
# Run tests with UNSAFE_BYTEBUFFER
- "msbuild.exe /property:Configuration=Release;UnsafeByteBuffer=true;OutputPath=tempcsUnsafe /verbosity:minimal FlatBuffers.Test.csproj"
- "tempcsUnsafe\\FlatBuffers.Test.exe"
- "msbuild.exe /property:Configuration=Release;UnsafeByteBuffer=true;OutputPath=.tmp /verbosity:minimal FlatBuffers.Test.csproj"
- ".tmp\\FlatBuffers.Test.exe"
# TODO: add more languages.
- "cd ..\\.."

4
tests/FlatBuffers.Test/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
dotnet-install.sh
.dotnet_tmp/
.tmp/
packages/

View File

@ -591,11 +591,14 @@ namespace FlatBuffers.Test
Assert.Throws<ArgumentException>(() => uut.Put(1024, data));
}
#pragma warning disable 0169
// These are purposely not used and the warning is suppress
private struct dummyStruct
{
int a;
float b;
}
#pragma warning restore 0169
[FlatBuffersTestMethod]
public void ByteBuffer_Put_Array_IncorrectType_Throws()

View File

@ -9,6 +9,7 @@
<RootNamespace>FlatBuffers.Test</RootNamespace>
<AssemblyName>FlatBuffers.Test</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<RuntimeIdentifier>win</RuntimeIdentifier>
<LangVersion>4</LangVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
@ -36,6 +37,11 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);UNSAFE_BYTEBUFFER</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.12.0.3\lib\net35\Newtonsoft.Json.dll</HintPath>

View File

@ -114,13 +114,13 @@ namespace FlatBuffers.Test
// Dump to output directory so we can inspect later, if needed
#if ENABLE_SPAN_T
var data = fbb.DataBuffer.ToSizedArray();
string filename = @"Resources/monsterdata_cstest" + (sizePrefix ? "_sp" : "") + ".mon";
string filename = @".tmp/monsterdata_cstest" + (sizePrefix ? "_sp" : "") + ".mon";
File.WriteAllBytes(filename, data);
#else
using (var ms = fbb.DataBuffer.ToMemoryStream(fbb.DataBuffer.Position, fbb.Offset))
{
var data = ms.ToArray();
string filename = @"Resources/monsterdata_cstest" + (sizePrefix ? "_sp" : "") + ".mon";
string filename = @".tmp/monsterdata_cstest" + (sizePrefix ? "_sp" : "") + ".mon";
File.WriteAllBytes(filename, data);
}
#endif
@ -282,7 +282,7 @@ namespace FlatBuffers.Test
[FlatBuffersTestMethod]
public void CanReadCppGeneratedWireFile()
{
var data = File.ReadAllBytes(@"Resources/monsterdata_test.mon");
var data = File.ReadAllBytes(@"../monsterdata_test.mon");
var bb = new ByteBuffer(data);
TestBuffer(bb);
TestObjectAPI(Monster.GetRootAsMonster(bb));
@ -291,7 +291,7 @@ namespace FlatBuffers.Test
[FlatBuffersTestMethod]
public void CanReadJsonFile()
{
var jsonText = File.ReadAllText(@"Resources/monsterdata_test.json");
var jsonText = File.ReadAllText(@"../monsterdata_test.json");
var mon = MonsterT.DeserializeFromJson(jsonText);
var fbb = new FlatBufferBuilder(1);
fbb.Finish(Monster.Pack(fbb, mon).Value);

View File

@ -1,41 +1,31 @@
#!/bin/sh
# Restore nuget packages
mkdir dotnet_tmp
curl -OL https://dot.net/v1/dotnet-install.sh
chmod +x dotnet-install.sh
./dotnet-install.sh --version latest --install-dir dotnet_tmp
dotnet_tmp/dotnet new sln
dotnet_tmp/dotnet sln add FlatBuffers.Test.csproj
curl -OL https://dist.nuget.org/win-x86-commandline/v5.5.1/nuget.exe
mono nuget.exe restore
PROJ_FILE=FlatBuffers.Test.csproj
# Copy Test Files
cp ../monsterdata_test.mon Resources/
cp ../monsterdata_test.json Resources/
TEMP_DOTNET_DIR=.dotnet_tmp
TEMP_BIN=.tmp
[ -d $TEMP_DOTNET_DIR ] || mkdir $TEMP_DOTNET_DIR
[ -f dotnet-install.sh ] || curl -OL https://dot.net/v1/dotnet-install.sh
./dotnet-install.sh --version latest --install-dir $TEMP_DOTNET_DIR
DOTNET=$TEMP_DOTNET_DIR/dotnet
$DOTNET new sln
$DOTNET sln add $PROJ_FILE
$DOTNET restore -r linux-x64 $PROJ_FILE
# Testing C# on Linux using Mono.
msbuild -property:Configuration=Release,OutputPath=tempcs -verbosity:minimal FlatBuffers.Test.csproj
mono tempcs/FlatBuffers.Test.exe
rm -fr tempcs
rm Resources/monsterdata_cstest.mon
rm Resources/monsterdata_cstest_sp.mon
msbuild -property:Configuration=Release,OutputPath=$TEMP_BIN -verbosity:minimal $PROJ_FILE
mono $TEMP_BIN/FlatBuffers.Test.exe
rm -fr $TEMP_BIN
# Repeat with unsafe versions
msbuild -property:Configuration=Release,UnsafeByteBuffer=true,OutputPath=$TEMP_BIN -verbosity:minimal $PROJ_FILE
mono $TEMP_BIN/FlatBuffers.Test.exe
rm -fr $TEMP_BIN
msbuild -property:Configuration=Release,UnsafeByteBuffer=true,OutputPath=tempcsUnsafe -verbosity:minimal FlatBuffers.Test.csproj
mono tempcsUnsafe/FlatBuffers.Test.exe
rm -fr tempcsUnsafe
rm Resources/monsterdata_cstest.mon
rm Resources/monsterdata_cstest_sp.mon
# Remove Temp Files
rm -fr dotnet_tmp
rm -fr packages
rm dotnet-install.sh
rm nuget.exe
rm FlatBuffers.Test.sln
rm Resources/monsterdata_test.mon
rm Resources/monsterdata_test.json
rm -rf obj

View File

@ -0,0 +1,38 @@
# .NET Tests
## Running on Linux
### Prerequisites
To run the tests on a Linux a few prerequisites are needed:
1) mono
2) msbuild
### Running
To run the tests:
```
./NetTest.sh
```
This will download the .NET installer and core SDK if those are not already
installed. Then it will build the tests using `msbuild` and run the resulting
test binary with `mono`.
After running the tests, the downloaded .NET installer and SDK are *not* removed
as they can be reused in subsequent invocations. The files are ignored by git by
default, and can remain in the working directory.
### Cleaning
If you want to clean up the downloaded .NET installer and SDK, run:
```
./clean.sh
```
This will wipe away the downloaded files and directories. Those will be
automatically re-downloaded when running `NetTest.sh`.

10
tests/FlatBuffers.Test/clean.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
# Remove files and directory that are needed to build and run the .NET tests.
# The script NetTest.sh installs these as needed.
[ -d .dotnet_tmp ] && rm -rf .dotnet_tmp
[ -d packages ] && rm -rf packages
[ -d .tmp ] && rm -rf .tmp
[ -f nuget.exe ] && rm nuget.exe
[ -f dotnet-intall.sh ] && rm dotnet-install.sh