Skip to content

Commit

Permalink
Move idl test files to test/idl
Browse files Browse the repository at this point in the history
just run `make` therein to find out if the `idlc` has changed semantics.

Also includes some clean-up on `default.nix`.
  • Loading branch information
nomeata authored and mergify-bot committed May 29, 2019
1 parent 4bf41d2 commit e3b71da
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 27 additions & 22 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -168,7 +169,7 @@ rec {
'';
};

native = nixpkgs.symlinkJoin {
asc = nixpkgs.symlinkJoin {
name = "asc";
paths = [ asc-bin rts ];
buildInputs = [ nixpkgs.makeWrapper ];
Expand All @@ -178,16 +179,17 @@ rec {
'';
};

native_test = stdenv.mkDerivation {
name = "native.test";
tests = stdenv.mkDerivation {
name = "tests";

src = sourceByRegex ./. (
test_files ++
samples_files
);

buildInputs =
[ native
[ asc
idlc
ocaml_wasm
nixpkgs.wabt
nixpkgs.bash
Expand All @@ -202,6 +204,7 @@ rec {
${llvmEnv}
export ASC=asc
export AS_LD=as-ld
export IDLC=idlc
asc --version
make -C samples all
'' +
Expand 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 ];
Expand All @@ -246,7 +250,7 @@ rec {
);

buildInputs =
[ native-coverage
[ asc-coverage
nixpkgs.wabt
nixpkgs.bash
nixpkgs.perl
Expand All @@ -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
'';

Expand Down Expand Up @@ -405,7 +409,7 @@ rec {
);

buildInputs = [
native
asc
];

doCheck = true;
Expand All @@ -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
Expand All @@ -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 ]
));
Expand Down
6 changes: 4 additions & 2 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -29,20 +31,20 @@ 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
$(MAKE) -C run clean
$(MAKE) -C run-dfinity clean
$(MAKE) -C repl clean
$(MAKE) -C ld clean
$(MAKE) -C idl clean

.PHONY: coverage
4 changes: 2 additions & 2 deletions test/compare-wat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/idl/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
RUNFLAGS =

all:
../run.sh $(RUNFLAGS) *.didl

accept:
../run.sh $(RUNFLAGS) -a *.didl

clean:
rm -rf _out

include ../*.mk
16 changes: 16 additions & 0 deletions test/idl/ok/px.idlc.ok
Original file line number Diff line number Diff line change
@@ -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}))})
40 changes: 40 additions & 0 deletions test/idl/ok/test.idlc.ok
Original file line number Diff line number Diff line change
@@ -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}))})
File renamed without changes.
File renamed without changes.
13 changes: 11 additions & 2 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -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 ""

Expand Down

0 comments on commit e3b71da

Please sign in to comment.