From a440aa71d067a7cbd79fded69abf1bfddd1d9881 Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Wed, 29 May 2019 12:14:24 +0200 Subject: [PATCH] Move idl test files to `test/idl` just run `make` therein to find out if the `idlc` has changed semantics. Also includes some clean-up on `default.nix`. --- README.md | 2 +- default.nix | 49 ++++++++++++++++++++----------------- test/Makefile | 6 +++-- test/compare-wat.sh | 4 +-- test/idl/Makefile | 12 +++++++++ test/idl/ok/px.idlc.ok | 16 ++++++++++++ test/idl/ok/test.idlc.ok | 40 ++++++++++++++++++++++++++++++ {idl => test/idl}/px.didl | 0 {idl => test/idl}/test.didl | 0 test/run.sh | 13 ++++++++-- 10 files changed, 113 insertions(+), 29 deletions(-) create mode 100644 test/idl/Makefile create mode 100644 test/idl/ok/px.idlc.ok create mode 100644 test/idl/ok/test.idlc.ok rename {idl => test/idl}/px.didl (100%) rename {idl => test/idl}/test.didl (100%) diff --git a/README.md b/README.md index 82c5faec1c8..e5477c84fa8 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A simple language for writing Dfinity actors. To install the `asc` binary into your nix environment, use ``` -$ nix-env -i -f . -A native +$ nix-env -i -f . -A asc ``` ## Development using Nix diff --git a/default.nix b/default.nix index f1257bdee5f..ee1204e05bf 100644 --- a/default.nix +++ b/default.nix @@ -65,15 +65,16 @@ let "test/" "test/.*Makefile.*" "test/quick.mk" - "test/(fail|run|run-dfinity|repl|ld)/" - "test/(fail|run|run-dfinity|repl|ld)/lib/" - "test/(fail|run|run-dfinity|repl|ld)/lib/dir/" - "test/(fail|run|run-dfinity|repl|ld)/.*.as" - "test/(fail|run|run-dfinity|repl|ld)/.*.sh" - "test/(fail|run|run-dfinity|repl|ld)/[^/]*.wat" - "test/(fail|run|run-dfinity|repl|ld)/[^/]*.c" - "test/(fail|run|run-dfinity|repl|ld)/ok/" - "test/(fail|run|run-dfinity|repl|ld)/ok/.*.ok" + "test/(fail|run|run-dfinity|repl|ld|idl)/" + "test/(fail|run|run-dfinity|repl|ld|idl)/lib/" + "test/(fail|run|run-dfinity|repl|ld|idl)/lib/dir/" + "test/(fail|run|run-dfinity|repl|ld|idl)/.*.as" + "test/(fail|run|run-dfinity|repl|ld|idl)/.*.sh" + "test/(fail|run|run-dfinity|repl|ld|idl)/.*.didl" + "test/(fail|run|run-dfinity|repl|ld|idl)/[^/]*.wat" + "test/(fail|run|run-dfinity|repl|ld|idl)/[^/]*.c" + "test/(fail|run|run-dfinity|repl|ld|idl)/ok/" + "test/(fail|run|run-dfinity|repl|ld|idl)/ok/.*.ok" "test/.*.sh" ]; samples_files = [ @@ -168,7 +169,7 @@ rec { ''; }; - native = nixpkgs.symlinkJoin { + asc = nixpkgs.symlinkJoin { name = "asc"; paths = [ asc-bin rts ]; buildInputs = [ nixpkgs.makeWrapper ]; @@ -178,8 +179,8 @@ rec { ''; }; - native_test = stdenv.mkDerivation { - name = "native.test"; + tests = stdenv.mkDerivation { + name = "tests"; src = sourceByRegex ./. ( test_files ++ @@ -187,7 +188,8 @@ rec { ); buildInputs = - [ native + [ asc + idlc ocaml_wasm nixpkgs.wabt nixpkgs.bash @@ -202,6 +204,7 @@ rec { ${llvmEnv} export ASC=asc export AS_LD=as-ld + export IDLC=idlc asc --version make -C samples all '' + @@ -223,11 +226,12 @@ rec { oldAttrs.buildPhase; installPhase = oldAttrs.installPhase + '' - mv src/ $out/src + # The coverage report needs access to sources, including _build/parser.ml + cp -r . $out/src ''; }); - native-coverage = nixpkgs.symlinkJoin { + asc-coverage = nixpkgs.symlinkJoin { name = "asc-covergage"; paths = [ asc-bin-coverage rts ]; buildInputs = [ nixpkgs.makeWrapper ]; @@ -246,7 +250,7 @@ rec { ); buildInputs = - [ native-coverage + [ asc-coverage nixpkgs.wabt nixpkgs.bash nixpkgs.perl @@ -260,7 +264,7 @@ rec { ${llvmEnv} export ASC=asc export AS_LD=as-ld - ln -vs ${native-coverage}/src src + ln -vs ${asc-coverage}/src src make -C test coverage ''; @@ -405,7 +409,7 @@ rec { ); buildInputs = [ - native + asc ]; doCheck = true; @@ -424,10 +428,10 @@ rec { all-systems-go = nixpkgs.releaseTools.aggregate { name = "all-systems-go"; constituents = [ - native + asc js idlc - native_test + tests coverage-report rts stdlib-reference @@ -447,10 +451,11 @@ rec { # https://github.com/NixOS/nix/issues/955 # - buildInputs = nixpkgs.lib.lists.unique (builtins.filter (i: i != native) ( + buildInputs = nixpkgs.lib.lists.unique (builtins.filter (i: i != asc && i != idlc) ( asc-bin.buildInputs ++ rts.buildInputs ++ - native_test.buildInputs ++ + idlc.buildInputs ++ + tests.buildInputs ++ users-guide.buildInputs ++ [ nixpkgs.ncurses nixpkgs.ocamlPackages.merlin ] )); diff --git a/test/Makefile b/test/Makefile index 00e071270a6..b269a546ef2 100644 --- a/test/Makefile +++ b/test/Makefile @@ -4,6 +4,7 @@ all: $(MAKE) -C run-dfinity $(MAKE) -C repl $(MAKE) -C ld + $(MAKE) -C idl MAKE_PAR := $(MAKE) --no-print-directory --load-average -j $(shell getconf _NPROCESSORS_ONLN) --keep-going @@ -12,6 +13,7 @@ quick: $(MAKE_PAR) -C run quick $(MAKE_PAR) -C repl quick $(MAKE_PAR) -C ld quick + $(MAKE_PAR) -C idl quick parallel: quick $(MAKE_PAR) -C run-dfinity quick @@ -29,14 +31,13 @@ coverage: bisect-ppx-report -I ../src/_build/ -html coverage/ _coverage/bisect*.out rm -rf _coverage - - accept: $(MAKE) -C fail accept $(MAKE) -C run accept $(MAKE) -C run-dfinity accept $(MAKE) -C repl accept $(MAKE) -C ld accept + $(MAKE) -C idl accept clean: $(MAKE) -C fail clean @@ -44,5 +45,6 @@ clean: $(MAKE) -C run-dfinity clean $(MAKE) -C repl clean $(MAKE) -C ld clean + $(MAKE) -C idl clean .PHONY: coverage diff --git a/test/compare-wat.sh b/test/compare-wat.sh index 27e7c8b8a5d..70965888d0c 100755 --- a/test/compare-wat.sh +++ b/test/compare-wat.sh @@ -28,7 +28,7 @@ function build_ref_to { if [ -z "$1" ] then echo "Building $2 asc from working copy.." - chronic nix-build -E '((import ./..) {}).native' \ + chronic nix-build -E '((import ./..) {}).asc' \ --option binary-caches '' \ -o $2-asc/ else @@ -42,7 +42,7 @@ function build_ref_to { let nixpkg = import (../nix/nixpkgs.nix).nixpkgs {}; in let checkout = (builtins.fetchGit {url = path; ref = ref; rev = rev; name = "old-asc";}).outPath; in builtins.trace checkout ( - ((import checkout) {}).native)' \ + ((import checkout) {}).asc)' \ --option binary-caches '' \ -o $2-asc/ fi diff --git a/test/idl/Makefile b/test/idl/Makefile new file mode 100644 index 00000000000..9c06507358f --- /dev/null +++ b/test/idl/Makefile @@ -0,0 +1,12 @@ +RUNFLAGS = + +all: + ../run.sh $(RUNFLAGS) *.didl + +accept: + ../run.sh $(RUNFLAGS) -a *.didl + +clean: + rm -rf _out + +include ../*.mk diff --git a/test/idl/ok/px.idlc.ok b/test/idl/ok/px.idlc.ok new file mode 100644 index 00000000000..bbc8019ccf4 --- /dev/null +++ b/test/idl/ok/px.idlc.ok @@ -0,0 +1,16 @@ +const RegionId = IDL.nat +const UserId = IDL.nat +const TruckTypeId = IDL.nat +const ProducerId = IDL.nat +const UserInfo = + IDL.Obj({'id': UserId, 'public_key': IDL.text, 'user_name': IDL.text, + 'description': IDL.text, 'region': RegionId, + 'produceId': IDL.Opt(ProducerId)}) +const EntId = + IDL.Obj({'user': UserId, 'truckType': TruckTypeId, 'region': RegionId}) +const OpEntId = IDL.Opt(EntId) +const IdErr = IDL.Obj({'idErr': OpEntId}) +const Inventory = IDL.Obj({'produce_id': IDL.nat, 'quantity': IDL.nat}) +const ProduceExchange = new IDL.ActorInterface({ + getInventory: + IDL.message(IDL.Obj({'producer_id': IDL.nat}), IDL.Obj({'0': Inventory}))}) diff --git a/test/idl/ok/test.idlc.ok b/test/idl/ok/test.idlc.ok new file mode 100644 index 00000000000..0bbd4a5bfaa --- /dev/null +++ b/test/idl/ok/test.idlc.ok @@ -0,0 +1,40 @@ +const my_type = IDL.nat +const B = my_type +const C = E +const E = IDL.Opt(C) +const node = IDL.Obj({'head': IDL.nat, 'tail': list}) +const list = IDL.Opt(node) +const enum = + IDL.Variant({'red': IDL.null, 'blue': IDL.null, 'green': IDL.null}) +const message = IDL.Obj({'name': IDL.text, '25': C, '26': IDL.reserved}) +const test = + IDL.Obj({'0': IDL.nat, '1': IDL.nat, '2': IDL.nat, '99': IDL.nat, + '100': IDL.nat, 'named_field': IDL.nat, '108546619': IDL.nat, + '108546620': IDL.nat, '108546621': IDL.nat}) +const nest_record = + IDL.Obj({'0': IDL.nat, '1': IDL.nat, '2': IDL.nat, + '3': IDL.Obj({'0': IDL.nat, '1': IDL.nat, '2': IDL.nat}), '4': IDL.nat, + '5': IDL.nat, '6': IDL.nat}) +const tree = + IDL.Variant({'leaf': IDL.int, + 'branch': IDL.Obj({'left': tree, 'val': IDL.int, 'right': tree})}) +const s = IDL.ActorInterface({f: t}) +const t = IDL.message(IDL.Obj({'server': s}), IDL.Obj({})) +const broker = + IDL.ActorInterface({ + find: + IDL.message(IDL.Obj({'name': IDL.text}), + IDL.Obj({ + '0': + IDL.ActorInterface({up: IDL.message(IDL.Obj({}), IDL.Obj({})), + current: IDL.message(IDL.Obj({}), IDL.Obj({'0': IDL.nat}))}) + })) + }) +const stream = + IDL.Opt( + IDL.Obj({'head': IDL.nat, + 'next': IDL.message(IDL.Obj({}), IDL.Obj({'0': stream}))})) + +const user = new IDL.ActorInterface({ + addUser: IDL.message(IDL.Obj({'0': IDL.nat}), IDL.Obj({'0': my_type})), + userName: IDL.message(IDL.Obj({'0': IDL.nat}), IDL.Obj({'0': stream}))}) diff --git a/idl/px.didl b/test/idl/px.didl similarity index 100% rename from idl/px.didl rename to test/idl/px.didl diff --git a/idl/test.didl b/test/idl/test.didl similarity index 100% rename from idl/test.didl rename to test/idl/test.didl diff --git a/test/run.sh b/test/run.sh index 9157165b64e..54057dccd3b 100755 --- a/test/run.sh +++ b/test/run.sh @@ -21,6 +21,7 @@ DFINITY=no EXTRA_ASC_FLAGS= ASC=${ASC:-$(realpath $(dirname $0)/../src/asc)} AS_LD=${AS_LD:-$(realpath $(dirname $0)/../src/as-ld)} +IDLC=${IDLC:-$(realpath $(dirname $0)/../idl/idlc)} export AS_LD WASM=${WASM:-wasm} DVM_WRAPPER=$(realpath $(dirname $0)/dvm.sh) @@ -80,8 +81,10 @@ do then base=$(basename $file .sh) elif [ ${file: -4} == ".wat" ] then base=$(basename $file .wat) + elif [ ${file: -5} == ".didl" ] + then base=$(basename $file .didl) else - echo "Unknown file extension in $file, expected .as, .sh or .wat"; exit 1 + echo "Unknown file extension in $file, expected .as, .sh, .wat or .didl"; exit 1 failures=yes continue fi @@ -191,7 +194,8 @@ do $ECHO -n " [out]" ./$(basename $file) > $out/$base.stdout 2> $out/$base.stderr diff_files="$diff_files $base.stdout $base.stderr" - else + elif [ ${file: -4} == ".wat" ] + then # The file is a .wat file, so we are expected to test linking $ECHO -n " [as-ld]" rm -f $out/$base.{base,lib,linked}.{wasm,wat,o} @@ -206,6 +210,11 @@ do diff_files="$diff_files $base.linked.wat $base.linked.wat.stderr" fi + else + # The file is a .didl file, so we are expected to test the idl + $ECHO -n " [idlc]" + $IDLC $base.didl > $out/$base.idlc 2>&1 + diff_files="$diff_files $base.idlc" fi $ECHO ""