forked from coral-xyz/anchor
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Improve IDL comparison tests (coral-xyz#2581)
- Loading branch information
1 parent
df3e959
commit 8f30f00
Showing
7 changed files
with
38 additions
and
55 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
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,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 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,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 |