nanopb: add tests via passthru.tests

This commit is contained in:
Wael Nasreddine 2020-06-05 13:29:52 -07:00 committed by Wael Nasreddine
parent 47361447f8
commit c0810058be
No known key found for this signature in database
GPG Key ID: FD437548E0BF0F5F
10 changed files with 132 additions and 0 deletions

View File

@ -52,6 +52,13 @@ in stdenv.mkDerivation rec {
chmod +x $out/bin/protoc-gen-nanopb
'';
passthru.tests = {
simple-proto2 = callPackage ./test-simple-proto2 {};
simple-proto3 = callPackage ./test-simple-proto3 {};
message-with-annotations = callPackage ./test-message-with-annotations {};
message-with-options = callPackage ./test-message-with-options {};
};
meta = with lib; {
inherit (protobuf.meta) platforms;

View File

@ -0,0 +1,27 @@
{ stdenv, protobuf, nanopb }:
stdenv.mkDerivation {
name = "nanopb-test-message-with-annotations";
meta.timeout = 60;
src = ./.;
# protoc requires any .proto file to be compiled to reside within it's
# proto_path. By default the current directory is automatically added to the
# proto_path. I tried using --proto_path ${./.} ${./simple.proto} and it did
# not work because they end up in the store at different locations.
installPhase = ":";
buildPhase = ''
mkdir $out
${protobuf}/bin/protoc --proto_path=. --proto_path=${nanopb}/share/nanopb/generator/proto --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out withannotations.proto
'';
docheck = true;
checkphase = ''
grep -q WithAnnotations $out/withannotations.pb.c || (echo "error: WithAnnotations not found in $out/withannotations.pb.c"; exit 1)
grep -q WithAnnotations $out/withannotations.pb.h || (echo "error: WithAnnotations not found in $out/withannotations.pb.h"; exit 1)
grep -q "pb_byte_t uuid\[16\]" $out/withannotations.pb.h || (echo "error: uuid is not of type pb_byte_t and of size 16 in $out/withannotations.pb.h"; exit 1)
grep -q "FIXED_LENGTH_BYTES, uuid" $out/withannotations.pb.h || (echo "error: uuid is not of fixed lenght bytes in $out/withannotations.pb.h"; exit 1)
grep -q "#define WithAnnotations_size" $out/withannotations.pb.h || (echo "error: the size of WithAnnotations is not known in $out/withannotations.pb.h"; exit 1)
'';
}

View File

@ -0,0 +1,7 @@
syntax = "proto3";
import "nanopb.proto";
message WithAnnotations {
bytes uuid = 1 [(nanopb).max_size = 16, (nanopb).fixed_length = true];
}

View File

@ -0,0 +1,27 @@
{ stdenv, protobuf, nanopb }:
stdenv.mkDerivation {
name = "nanopb-test-message-with-options";
meta.timeout = 60;
src = ./.;
# protoc requires any .proto file to be compiled to reside within it's
# proto_path. By default the current directory is automatically added to the
# proto_path. I tried using --proto_path ${./.} ${./simple.proto} and it did
# not work because they end up in the store at different locations.
installPhase = ":";
buildPhase = ''
mkdir $out
${protobuf}/bin/protoc --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out withoptions.proto
'';
docheck = true;
checkphase = ''
grep -q WithOptions $out/withoptions.pb.c || (echo "error: WithOptions not found in $out/withoptions.pb.c"; exit 1)
grep -q WithOptions $out/withoptions.pb.h || (echo "error: WithOptions not found in $out/withoptions.pb.h"; exit 1)
grep -q "pb_byte_t uuid\[16\]" $out/withoptions.pb.h || (echo "error: uuid is not of type pb_byte_t and of size 16 in $out/withoptions.pb.h"; exit 1)
grep -q "FIXED_LENGTH_BYTES, uuid" $out/withoptions.pb.h || (echo "error: uuid is not of fixed lenght bytes in $out/withoptions.pb.h"; exit 1)
grep -q "#define WithOptions_size" $out/withoptions.pb.h || (echo "error: the size of WithOptions is not known in $out/withoptions.pb.h"; exit 1)
'';
}

View File

@ -0,0 +1 @@
WithOptions.uuid max_size:16 fixed_length:true

View File

@ -0,0 +1,5 @@
syntax = "proto3";
message WithOptions {
bytes uuid = 1;
}

View File

@ -0,0 +1,24 @@
{ stdenv, protobuf, nanopb }:
stdenv.mkDerivation {
name = "nanopb-test-simple-proto2";
meta.timeout = 60;
src = ./.;
# protoc requires any .proto file to be compiled to reside within it's
# proto_path. By default the current directory is automatically added to the
# proto_path. I tried using --proto_path ${./.} ${./simple.proto} and it did
# not work because they end up in the store at different locations.
installPhase = ":";
buildPhase = ''
mkdir $out
${protobuf}/bin/protoc --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out simple.proto
'';
doCheck = true;
checkPhase = ''
grep -q SimpleMessage $out/simple.pb.c || (echo "ERROR: SimpleMessage not found in $out/simple.pb.c"; exit 1)
grep -q SimpleMessage $out/simple.pb.h || (echo "ERROR: SimpleMessage not found in $out/simple.pb.h"; exit 1)
'';
}

View File

@ -0,0 +1,5 @@
syntax = "proto2";
message SimpleMessage {
required int32 lucky_number = 1;
}

View File

@ -0,0 +1,24 @@
{ stdenv, protobuf, nanopb }:
stdenv.mkDerivation {
name = "nanopb-test-simple-proto3";
meta.timeout = 60;
src = ./.;
# protoc requires any .proto file to be compiled to reside within it's
# proto_path. By default the current directory is automatically added to the
# proto_path. I tried using --proto_path ${./.} ${./simple.proto} and it did
# not work because they end up in the store at different locations.
installPhase = ":";
buildPhase = ''
mkdir $out
${protobuf}/bin/protoc --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out simple.proto
'';
doCheck = true;
checkPhase = ''
grep -q SimpleMessage $out/simple.pb.c || (echo "ERROR: SimpleMessage not found in $out/simple.pb.c"; exit 1)
grep -q SimpleMessage $out/simple.pb.h || (echo "ERROR: SimpleMessage not found in $out/simple.pb.h"; exit 1)
'';
}

View File

@ -0,0 +1,5 @@
syntax = "proto3";
message SimpleMessage {
int32 lucky_number = 1;
}