diff --git a/appveyor.yml b/appveyor.yml index 634a5215c..6655f3cdd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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 ..\\.." diff --git a/tests/FlatBuffers.Test/.gitignore b/tests/FlatBuffers.Test/.gitignore new file mode 100644 index 000000000..badc82747 --- /dev/null +++ b/tests/FlatBuffers.Test/.gitignore @@ -0,0 +1,4 @@ +dotnet-install.sh +.dotnet_tmp/ +.tmp/ +packages/ \ No newline at end of file diff --git a/tests/FlatBuffers.Test/ByteBufferTests.cs b/tests/FlatBuffers.Test/ByteBufferTests.cs index faa6a6a66..98e917c11 100644 --- a/tests/FlatBuffers.Test/ByteBufferTests.cs +++ b/tests/FlatBuffers.Test/ByteBufferTests.cs @@ -591,11 +591,14 @@ namespace FlatBuffers.Test Assert.Throws(() => 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() diff --git a/tests/FlatBuffers.Test/FlatBuffers.Test.csproj b/tests/FlatBuffers.Test/FlatBuffers.Test.csproj index c9abb3500..e26f918eb 100644 --- a/tests/FlatBuffers.Test/FlatBuffers.Test.csproj +++ b/tests/FlatBuffers.Test/FlatBuffers.Test.csproj @@ -9,6 +9,7 @@ FlatBuffers.Test FlatBuffers.Test v3.5 + win 4 512 @@ -36,6 +37,11 @@ true $(DefineConstants);UNSAFE_BYTEBUFFER + + + 12.0.3 + + packages\Newtonsoft.Json.12.0.3\lib\net35\Newtonsoft.Json.dll diff --git a/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs b/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs index 97a32aeb8..1324c8cb8 100644 --- a/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs +++ b/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs @@ -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); diff --git a/tests/FlatBuffers.Test/NetTest.sh b/tests/FlatBuffers.Test/NetTest.sh index ce3608170..44e77e11d 100755 --- a/tests/FlatBuffers.Test/NetTest.sh +++ b/tests/FlatBuffers.Test/NetTest.sh @@ -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 diff --git a/tests/FlatBuffers.Test/README.md b/tests/FlatBuffers.Test/README.md new file mode 100644 index 000000000..41b6983ea --- /dev/null +++ b/tests/FlatBuffers.Test/README.md @@ -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`. + + diff --git a/tests/FlatBuffers.Test/Resources/.gitkeep b/tests/FlatBuffers.Test/Resources/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/FlatBuffers.Test/clean.sh b/tests/FlatBuffers.Test/clean.sh new file mode 100755 index 000000000..41f6a4a59 --- /dev/null +++ b/tests/FlatBuffers.Test/clean.sh @@ -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