Skip to content

Commit

Permalink
Move test-related bin functionality out of trustfall_core. (#284)
Browse files Browse the repository at this point in the history
* Move test-related bin functionality out of `trustfall_core`.

* Update all the scripts to target the new binary.
  • Loading branch information
obi1kenobi authored May 16, 2023
1 parent 6a40103 commit 8d6c06e
Show file tree
Hide file tree
Showing 30 changed files with 2,389 additions and 2,327 deletions.
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"trustfall",
"trustfall_core",
"trustfall_testbin",
"trustfall_filetests_macros",
"trustfall_derive",
"trustfall_wasm",
Expand Down
11 changes: 8 additions & 3 deletions scripts/create_execution_error_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Fail on first error, on undefined variables, and on failures in pipelines.
set -euo pipefail

# Get the absolute path of the repo.
REPO="$(git rev-parse --show-toplevel)"

for INPUT_FILE in "$@"; do
echo "> Starting on file $INPUT_FILE"

Expand All @@ -13,7 +16,9 @@ for INPUT_FILE in "$@"; do
IR_FILE="$DIR_NAME/$STUB_NAME.ir.ron"
EXECUTION_ERROR_FILE="$DIR_NAME/$STUB_NAME.exec-error.ron"

cargo run parse "$INPUT_FILE" >"$PARSED_FILE"
cargo run frontend "$PARSED_FILE" >"$IR_FILE"
cargo run trace "$IR_FILE" >"$EXECUTION_ERROR_FILE"
MANIFEST_PATH="$REPO/trustfall_testbin/Cargo.toml"

cargo --manifest-path "$MANIFEST_PATH" run parse "$INPUT_FILE" >"$PARSED_FILE"
cargo --manifest-path "$MANIFEST_PATH" run frontend "$PARSED_FILE" >"$IR_FILE"
cargo --manifest-path "$MANIFEST_PATH" run trace "$IR_FILE" >"$EXECUTION_ERROR_FILE"
done
9 changes: 7 additions & 2 deletions scripts/create_frontend_error_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Fail on first error, on undefined variables, and on failures in pipelines.
set -euo pipefail

# Get the absolute path of the repo.
REPO="$(git rev-parse --show-toplevel)"

for INPUT_FILE in "$@"; do
echo "> Starting on file $INPUT_FILE"

Expand All @@ -12,6 +15,8 @@ for INPUT_FILE in "$@"; do
PARSED_FILE="$DIR_NAME/$STUB_NAME.graphql-parsed.ron"
FRONTEND_ERROR_FILE="$DIR_NAME/$STUB_NAME.frontend-error.ron"

cargo run parse "$INPUT_FILE" >"$PARSED_FILE"
cargo run frontend "$PARSED_FILE" >"$FRONTEND_ERROR_FILE"
MANIFEST_PATH="$REPO/trustfall_testbin/Cargo.toml"

cargo --manifest-path "$MANIFEST_PATH" run parse "$INPUT_FILE" >"$PARSED_FILE"
cargo --manifest-path "$MANIFEST_PATH" run frontend "$PARSED_FILE" >"$FRONTEND_ERROR_FILE"
done
4 changes: 2 additions & 2 deletions scripts/create_graphql_corpus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
set -euo pipefail

# Move relative to the top of the repo, so this script can be run from anywhere.
cd "$(git rev-parse --show-toplevel)/trustfall_core"
cd "$(git rev-parse --show-toplevel)/trustfall_testbin"

target_dir="$1"
schema_name="$2"

cargo_cmd="(cargo run --release corpus_graphql \$0 $2 >\$0.tmp)"
mv_cmd="mv \$0.tmp $target_dir/\$(basename \$0 | cut -d'.' -f1).graphql"

find ./test_data/tests -name '*.graphql.ron' | \
find ../trustfall_core/test_data/tests -name '*.graphql.ron' | \
xargs -n 1 \
sh -c "$cargo_cmd && $mv_cmd"
7 changes: 6 additions & 1 deletion scripts/create_parse_error_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Fail on first error, on undefined variables, and on failures in pipelines.
set -euo pipefail

# Get the absolute path of the repo.
REPO="$(git rev-parse --show-toplevel)"

for INPUT_FILE in "$@"; do
echo "> Starting on file $INPUT_FILE"

Expand All @@ -11,5 +14,7 @@ for INPUT_FILE in "$@"; do

PARSE_ERROR_FILE="$DIR_NAME/$STUB_NAME.parse-error.ron"

cargo run parse "$INPUT_FILE" >"$PARSE_ERROR_FILE"
MANIFEST_PATH="$REPO/trustfall_testbin/Cargo.toml"

cargo --manifest-path "$MANIFEST_PATH" run parse "$INPUT_FILE" >"$PARSE_ERROR_FILE"
done
7 changes: 6 additions & 1 deletion scripts/create_schema_error_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Fail on first error, on undefined variables, and on failures in pipelines.
set -euo pipefail

# Get the absolute path of the repo.
REPO="$(git rev-parse --show-toplevel)"

for INPUT_FILE in "$@"; do
echo "> Starting on file $INPUT_FILE"

Expand All @@ -11,5 +14,7 @@ for INPUT_FILE in "$@"; do

SCHEMA_ERROR_FILE="$DIR_NAME/$STUB_NAME.schema-error.ron"

cargo run schema_error "$INPUT_FILE" >"$SCHEMA_ERROR_FILE"
MANIFEST_PATH="$REPO/trustfall_testbin/Cargo.toml"

cargo --manifest-path "$MANIFEST_PATH" run schema_error "$INPUT_FILE" >"$SCHEMA_ERROR_FILE"
done
13 changes: 9 additions & 4 deletions scripts/create_valid_query_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Fail on first error, on undefined variables, and on failures in pipelines.
set -euo pipefail

# Get the absolute path of the repo.
REPO="$(git rev-parse --show-toplevel)"

for INPUT_FILE in "$@"; do
echo "> Starting on file $INPUT_FILE"

Expand All @@ -14,8 +17,10 @@ for INPUT_FILE in "$@"; do
TRACE_FILE="$DIR_NAME/$STUB_NAME.trace.ron"
OUTPUTS_FILE="$DIR_NAME/$STUB_NAME.output.ron"

cargo run parse "$INPUT_FILE" >"$PARSED_FILE"
cargo run frontend "$PARSED_FILE" >"$IR_FILE"
cargo run outputs "$IR_FILE" >"$OUTPUTS_FILE"
cargo run trace "$IR_FILE" >"$TRACE_FILE"
MANIFEST_PATH="$REPO/trustfall_testbin/Cargo.toml"

cargo --manifest-path "$MANIFEST_PATH" run parse "$INPUT_FILE" >"$PARSED_FILE"
cargo --manifest-path "$MANIFEST_PATH" run frontend "$PARSED_FILE" >"$IR_FILE"
cargo --manifest-path "$MANIFEST_PATH" run outputs "$IR_FILE" >"$OUTPUTS_FILE"
cargo --manifest-path "$MANIFEST_PATH" run trace "$IR_FILE" >"$TRACE_FILE"
done
6 changes: 3 additions & 3 deletions scripts/recreate_all_ir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
set -euo pipefail

# Move relative to the top of the repo, so this script can be run from anywhere.
cd "$(git rev-parse --show-toplevel)/trustfall_core"
cd "$(git rev-parse --show-toplevel)/trustfall_testbin"

find ./test_data/tests/valid_queries -name '*.graphql-parsed.ron' | \
find ../trustfall_core/test_data/tests/valid_queries -name '*.graphql-parsed.ron' | \
xargs -n 1 \
sh -c 'cargo run frontend $0 >"$(dirname $0)/$(basename $0 | cut -d'.' -f1).ir.ron"'

find ./test_data/tests/execution_errors -name '*.graphql-parsed.ron' | \
find ../trustfall_core/test_data/tests/execution_errors -name '*.graphql-parsed.ron' | \
xargs -n 1 \
sh -c 'cargo run frontend $0 >"$(dirname $0)/$(basename $0 | cut -d'.' -f1).ir.ron"'
4 changes: 2 additions & 2 deletions scripts/recreate_all_outputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
set -euo pipefail

# Move relative to the top of the repo, so this script can be run from anywhere.
cd "$(git rev-parse --show-toplevel)/trustfall_core"
cd "$(git rev-parse --show-toplevel)/trustfall_testbin"

find ./test_data/tests/valid_queries -name '*.ir.ron' | \
find ../trustfall_core/test_data/tests/valid_queries -name '*.ir.ron' | \
xargs -n 1 \
sh -c 'cargo run outputs $0 >"$(dirname $0)/$(basename $0 | cut -d'.' -f1).output.ron"'
8 changes: 4 additions & 4 deletions scripts/recreate_all_parsed_graphql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
set -euo pipefail

# Move relative to the top of the repo, so this script can be run from anywhere.
cd "$(git rev-parse --show-toplevel)/trustfall_core"
cd "$(git rev-parse --show-toplevel)/trustfall_testbin"

find ./test_data/tests/frontend_errors -name '*.graphql.ron' | \
find ../trustfall_core/test_data/tests/frontend_errors -name '*.graphql.ron' | \
xargs -n 1 \
sh -c 'cargo run parse $0 >"$(dirname $0)/$(basename $0 | cut -d'.' -f1).graphql-parsed.ron"'

find ./test_data/tests/execution_errors -name '*.graphql.ron' | \
find ../trustfall_core/test_data/tests/execution_errors -name '*.graphql.ron' | \
xargs -n 1 \
sh -c 'cargo run parse $0 >"$(dirname $0)/$(basename $0 | cut -d'.' -f1).graphql-parsed.ron"'

find ./test_data/tests/valid_queries -name '*.graphql.ron' | \
find ../trustfall_core/test_data/tests/valid_queries -name '*.graphql.ron' | \
xargs -n 1 \
sh -c 'cargo run parse $0 >"$(dirname $0)/$(basename $0 | cut -d'.' -f1).graphql-parsed.ron"'
4 changes: 2 additions & 2 deletions scripts/recreate_all_traces.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
set -euo pipefail

# Move relative to the top of the repo, so this script can be run from anywhere.
cd "$(git rev-parse --show-toplevel)/trustfall_core"
cd "$(git rev-parse --show-toplevel)/trustfall_testbin"

find ./test_data/tests/valid_queries -name '*.ir.ron' | \
find ../trustfall_core/test_data/tests/valid_queries -name '*.ir.ron' | \
xargs -n 1 \
sh -c 'cargo run trace $0 >"$(dirname $0)/$(basename $0 | cut -d'.' -f1).trace.ron"'
4 changes: 2 additions & 2 deletions scripts/reserialize_all_test_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
set -euo pipefail

# Move relative to the top of the repo, so this script can be run from anywhere.
cd "$(git rev-parse --show-toplevel)/trustfall_core"
cd "$(git rev-parse --show-toplevel)/trustfall_testbin"

# We ignore .graphql.ron files since those:
# - are relatively simple, and
# - have specific multiline string formatting that makes GraphQL human-readable
# and that we want to preserve.
find ./test_data/tests/ -name '*.ron' | \
find ../trustfall_core/test_data/tests/ -name '*.ron' | \
grep -v '.graphql.ron' | \
xargs -n 1 \
sh -c '(cargo run --release reserialize $0 >$0.tmp) && mv $0.tmp $0'
4 changes: 4 additions & 0 deletions trustfall_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ rustdoc-args = ["--cfg", "docsrs"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = []
__private = []

[lib]
name = "trustfall_core"
path = "src/lib.rs"
Expand Down
Loading

0 comments on commit 8d6c06e

Please sign in to comment.