-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests, to simplify test execution because are compiler inside the test project, not in an external project like the integration tests Use test assets from protobuff repo Convert `package directive` integration test to unit test
- Loading branch information
1 parent
547a09f
commit 267e7c5
Showing
14 changed files
with
570 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,3 +249,4 @@ paket-files/ | |
target/ | ||
/example/bundle.fs | ||
.store | ||
*.proto.fs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module GoogleProtobufTest.V3.CompatibilityTests | ||
|
||
// based on https://github.com/protocolbuffers/protobuf/blob/d9ccd0c0e6bbda9bf4476088eeb46b02d7dcd327/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/JsonParserTest.cs | ||
|
||
open System | ||
open System.IO | ||
open Expecto | ||
open Expecto.Logging | ||
open Expecto.Logging.Message | ||
open Fleece | ||
open Newtonsoft | ||
open protobuf_unittest3 | ||
|
||
let jsonTests = | ||
testList "json" [ | ||
testCase "Original field name accepted" (fun () -> | ||
let json = """{ "singleInt32": 10 }""" | ||
match parseJson json with | ||
| Result.Ok msg -> | ||
Expect.equal (Some(10)) msg.singleInt32 (sprintf "Failed to deserialize singleInt32, msg was %A" msg) | ||
Expect.equal None msg.singleInt64 (sprintf "Expected default 0 on singleInt64, msg was %A" msg) | ||
Expect.equal None msg.singleString (sprintf "Expected default empty string, msg was %A" msg) | ||
| Result.Error err -> | ||
failwithf "Failed to parse json: %A" err | ||
) | ||
] | ||
|
||
let tests = | ||
testList "compatibility" [ | ||
jsonTests | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProtoFile Include="schemas\falanx_test.proto" /> | ||
<ProtoFile Include="schemas\bundle_with_package.proto" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Compatibility.fs" /> | ||
<Compile Include="Tests.fs" /> | ||
<Compile Include="Program.fs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="paket.references" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\Falanx.Proto.Codec.Binary\Falanx.Proto.Codec.Binary.fsproj" /> | ||
<ProjectReference Include="..\..\Falanx.Proto.Codec.Json\Falanx.Proto.Codec.Json.fsproj" /> | ||
</ItemGroup> | ||
<!-- use the falanx generator binary directly --> | ||
<PropertyGroup> | ||
<FalanxSdk_GeneratorExeHost>dotnet </FalanxSdk_GeneratorExeHost> | ||
<FalanxSdk_GeneratorExe>..\..\Falanx.Tool\bin\$(Configuration)\netcoreapp2.1\falanx.dll</FalanxSdk_GeneratorExe> | ||
</PropertyGroup> | ||
<!-- include to enable the generator for these formats --> | ||
<Import Project="..\..\Falanx.Proto.Codec.Binary\build\Falanx.Proto.Codec.Binary.props" /> | ||
<Import Project="..\..\Falanx.Proto.Codec.Json\build\Falanx.Proto.Codec.Json.props" /> | ||
<!-- do import directly the falanx sdk target, instead from package --> | ||
<Target Name="FalanxSdkGenerateCode" BeforeTargets="BeforeCompile" Inputs="@(ProtoFile)" Outputs="%(Identity).fs"> | ||
<PropertyGroup> | ||
<_FalanxOutPath>%(ProtoFile.OutputPath)</_FalanxOutPath> | ||
<_FalanxOutPath Condition=" '$(_FalanxOutPath)' == '' ">%(ProtoFile.Identity).fs</_FalanxOutPath> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<FalanxSdk_CodeGenArgs Include="--inputfile "%(ProtoFile.Identity)"" /> | ||
<FalanxSdk_CodeGenArgs Include="--outputfile "$(_FalanxOutPath)"" /> | ||
<FalanxSdk_CodeGenArgs Include="--defaultnamespace "$(RootNamespace)"" /> | ||
<FalanxSdk_CodeGenArgs Include="--serializer %(FalanxSdkSerializer.Identity)" /> | ||
</ItemGroup> | ||
<!-- Use dotnet to execute the process. --> | ||
<Exec Command="$(FalanxSdk_GeneratorExeHost)"$(FalanxSdk_GeneratorExe)" @(FalanxSdk_CodeGenArgs -> '%(Identity)', ' ')" | ||
WorkingDirectory="$(MSBuildThisFileDirectory)" /> | ||
<ItemGroup> | ||
<CompileBefore Include="$(_FalanxOutPath)" /> | ||
<FileWrites Include="$(_FalanxOutPath)" /> | ||
</ItemGroup> | ||
</Target> | ||
<Import Project="..\..\.paket\Paket.Restore.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Falanx.Program | ||
|
||
open Expecto | ||
open System | ||
open System.IO | ||
|
||
let tests () = | ||
[ GoogleProtobufTest.V3.CompatibilityTests.tests | ||
Falanx.Tests.tests ] | ||
|> testList "unit" | ||
|> testSequenced | ||
|
||
[<EntryPoint>] | ||
let main argv = | ||
let artifactsDir = | ||
IO.Path.Combine(__SOURCE_DIRECTORY__,"..","..","artifact") | ||
|> Path.GetFullPath | ||
|
||
let resultsPath = IO.Path.Combine(artifactsDir,"test_results","TestResults.Unit.xml") | ||
|
||
let writeResults = TestResults.writeNUnitSummary (resultsPath, "Falanx.Tests") | ||
let config = defaultConfig.appendSummaryHandler writeResults | ||
|
||
Tests.runTestsWithArgs config argv (tests ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Falanx.Tests | ||
|
||
open System | ||
open System.IO | ||
open Expecto | ||
open Expecto.Logging | ||
open Expecto.Logging.Message | ||
open Fleece | ||
open Newtonsoft | ||
|
||
let jsonTests = | ||
testList "json" [ | ||
testCase "package directive" (fun () -> | ||
let json = """{ "martId": 10, "memberId": "a" }""" | ||
match parseJson json with | ||
| Result.Ok (msg: Sample.Tests.WithPackage.BundleRequest) -> | ||
Expect.equal (Some(10)) msg.martId (sprintf "Failed to deserialize martId, msg was %A" msg) | ||
Expect.equal (Some "a") msg.memberId (sprintf "Failed to deserialize memberId, msg was %A" msg) | ||
| Result.Error err -> | ||
failwithf "Failed to parse json: %A" err | ||
) | ||
] | ||
|
||
let tests = | ||
testList "general" [ | ||
jsonTests | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
group IntegrationTests | ||
|
||
FSharp.Core | ||
Expecto | ||
Expecto.TestResults |
5 changes: 1 addition & 4 deletions
5
test/examples/sample5 pkg/bundle.proto → ...x.Tests/schemas/bundle_with_package.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
syntax = "proto3"; | ||
|
||
package Sample.Tests; | ||
package Sample.Tests.WithPackage; | ||
|
||
message BundleRequest { | ||
int32 martId = 1; | ||
string member_id = 2; | ||
string channel_type = 3; | ||
repeated string retail_skus = 4; | ||
|
||
} |
Oops, something went wrong.