ソースを参照

tests: Improve IDL comparison tests (#2581)

acheron 2 年 前
コミット
8f30f00ec3

+ 1 - 1
tests/idl/Anchor.toml

@@ -7,7 +7,7 @@ generics = "Generics111111111111111111111111111111111111"
 idl = "id11111111111111111111111111111111111111111"
 relations_derivation = "Re1ationsDerivation111111111111111111111111"
 non_existent = { address = "NonExistent11111111111111111111111111111111", idl = "non-existent.json" }
-numbers_123 = { address = "Numbers111111111111111111111111111111111111", idl = "idls/relations_build_exp.json" }
+numbers_123 = { address = "Numbers111111111111111111111111111111111111", idl = "idls/relations_build.json" }
 
 [provider]
 cluster = "localnet"

+ 10 - 5
tests/idl/generate.sh

@@ -1,13 +1,18 @@
 #!/usr/bin/env bash
 
-idls_dir=$PWD/idls
+# `$1` is the directory to generate the IDLs in, defaults to `./idls`
+if [ $# = 1 ]; then
+    dir=$1
+else
+    dir=$PWD/idls
+fi
 
 cd programs/idl
-anchor idl parse --file src/lib.rs -o $idls_dir/idl_parse_exp.json
-anchor idl build -o $idls_dir/idl_build_exp.json
+anchor idl parse --file src/lib.rs -o $dir/parse.json
+anchor idl build -o $dir/build.json
 
 cd ../generics
-anchor idl build -o $idls_dir/generics_build_exp.json
+anchor idl build -o $dir/generics_build.json
 
 cd ../relations-derivation
-anchor idl build -o $idls_dir/relations_build_exp.json
+anchor idl build -o $dir/relations_build.json

+ 0 - 0
tests/idl/idls/idl_build_exp.json → tests/idl/idls/build.json


+ 0 - 0
tests/idl/idls/generics_build_exp.json → tests/idl/idls/generics_build.json


+ 0 - 0
tests/idl/idls/idl_parse_exp.json → tests/idl/idls/parse.json


+ 0 - 0
tests/idl/idls/relations_build_exp.json → tests/idl/idls/relations_build.json


+ 27 - 49
tests/idl/test.sh

@@ -1,57 +1,35 @@
 #!/usr/bin/env bash
-set -x
 set -e
 
 # Run anchor test
 anchor test --skip-lint
 
-idls_dir=idls
 tmp_dir=$(mktemp -d)
 
-cd programs/idl
-anchor idl parse --file src/lib.rs -o $tmp_dir/idl_parse_act.json
-anchor idl build -o $tmp_dir/idl_build_act.json
-
-cd ../generics
-anchor idl build -o $tmp_dir/generics_build_act.json
-
-cd ../relations-derivation
-anchor idl build -o $tmp_dir/relations_build_act.json
-
-cd ../..
-echo "----------------------------------------------------"
-echo "idl parse before > after"
-echo "----------------------------------------------------"
-echo ""
-diff -y --color $idls_dir/idl_parse_exp.json $tmp_dir/idl_parse_act.json
-PARSE_RETCODE=$?
-
-echo ""
-echo ""
-echo "----------------------------------------------------"
-echo "idl build before > after"
-echo "----------------------------------------------------"
-echo ""
-diff -y --color $idls_dir/idl_build_exp.json $tmp_dir/idl_build_act.json
-GEN_RETCODE=$?
-
-echo ""
-echo ""
-echo "----------------------------------------------------"
-echo "idl generics build before > after"
-echo "----------------------------------------------------"
-echo ""
-diff -y --color $idls_dir/generics_build_exp.json $tmp_dir/generics_build_act.json
-GEN_GENERICS_RETCODE=$?
-
-echo ""
-echo ""
-echo "----------------------------------------------------"
-echo "idl relations build before > after"
-echo "----------------------------------------------------"
-echo ""
-diff -y --color $idls_dir/relations_build_exp.json $tmp_dir/relations_build_act.json
-GEN_RELATIONS_RETCODE=$?
-
-# returns 0 when ok, or a positive integer when there are differences
-exit $((PARSE_RETCODE+GEN_RETCODE+GEN_GENERICS_RETCODE+GEN_RELATIONS_RETCODE))
+# Generate IDLs
+./generate.sh $tmp_dir
+
+# Exit status
+ret=0
+
+# Compare IDLs. `$ret` will be non-zero in the case of a mismatch.
+compare() {
+    echo "----------------------------------------------------"
+    echo "IDL $1 before > after changes"
+    echo "----------------------------------------------------"
+    diff -y --color=always --suppress-common-lines idls/$1.json $tmp_dir/$1.json
+    ret=$(($ret+$?))
+
+    if [ "$ret" = "0" ]; then
+        echo "No changes"
+    fi
+
+    echo ""
+}
+
+compare "parse"
+compare "build"
+compare "generics_build"
+compare "relations_build"
+
+exit $ret