summaryrefslogtreecommitdiff
path: root/tests/FlatBuffers.Test
diff options
context:
space:
mode:
authorDerek Bailey <derekbailey@google.com>2020-08-17 13:10:10 -0700
committerGitHub <noreply@github.com>2020-08-17 13:10:10 -0700
commitdb2aa9b4eca0edc94aea9e2059c21ce8786fc762 (patch)
tree7e62ff72edbad30ea9d13acd6519755964499834 /tests/FlatBuffers.Test
parent63cc0eec4e59015c91ab09894cb6822191a28151 (diff)
downloadflatbuffers-db2aa9b4eca0edc94aea9e2059c21ce8786fc762.tar.gz
flatbuffers-db2aa9b4eca0edc94aea9e2059c21ce8786fc762.tar.bz2
flatbuffers-db2aa9b4eca0edc94aea9e2059c21ce8786fc762.zip
[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
Diffstat (limited to 'tests/FlatBuffers.Test')
-rw-r--r--tests/FlatBuffers.Test/.gitignore4
-rw-r--r--tests/FlatBuffers.Test/ByteBufferTests.cs3
-rw-r--r--tests/FlatBuffers.Test/FlatBuffers.Test.csproj6
-rw-r--r--tests/FlatBuffers.Test/FlatBuffersExampleTests.cs8
-rwxr-xr-xtests/FlatBuffers.Test/NetTest.sh56
-rw-r--r--tests/FlatBuffers.Test/README.md38
-rw-r--r--tests/FlatBuffers.Test/Resources/.gitkeep0
-rwxr-xr-xtests/FlatBuffers.Test/clean.sh10
8 files changed, 88 insertions, 37 deletions
diff --git a/tests/FlatBuffers.Test/.gitignore b/tests/FlatBuffers.Test/.gitignore
new file mode 100644
index 00000000..badc8274
--- /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 faa6a6a6..98e917c1 100644
--- a/tests/FlatBuffers.Test/ByteBufferTests.cs
+++ b/tests/FlatBuffers.Test/ByteBufferTests.cs
@@ -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()
diff --git a/tests/FlatBuffers.Test/FlatBuffers.Test.csproj b/tests/FlatBuffers.Test/FlatBuffers.Test.csproj
index c9abb350..e26f918e 100644
--- a/tests/FlatBuffers.Test/FlatBuffers.Test.csproj
+++ b/tests/FlatBuffers.Test/FlatBuffers.Test.csproj
@@ -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>
@@ -37,6 +38,11 @@
<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>
</Reference>
diff --git a/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs b/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs
index 97a32aeb..1324c8cb 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 ce360817..44e77e11 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
-
-# Copy Test Files
-cp ../monsterdata_test.mon Resources/
-cp ../monsterdata_test.json Resources/
+PROJ_FILE=FlatBuffers.Test.csproj
-# Testing C# on Linux using Mono.
+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
-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
+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=$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 00000000..41b6983e
--- /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 e69de29b..00000000
--- a/tests/FlatBuffers.Test/Resources/.gitkeep
+++ /dev/null
diff --git a/tests/FlatBuffers.Test/clean.sh b/tests/FlatBuffers.Test/clean.sh
new file mode 100755
index 00000000..41f6a4a5
--- /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