Skip to content

Commit

Permalink
Add integration test directory and move panic_example there, normalis…
Browse files Browse the repository at this point in the history
…e json output to compare
  • Loading branch information
jberthold committed Nov 13, 2024
1 parent 4caa73b commit 471fd72
Show file tree
Hide file tree
Showing 6 changed files with 12,821 additions and 6 deletions.
28 changes: 26 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,30 @@ generate_ui_tests:
-cd "${RUST_SRC}"; ./ui_compiletest.sh "${RUST_SRC}" "${RUST_DIR}"/tests/ui/upstream "${RUST_DIR}"/tests_ui_sources --pass check --force-rerun 2>&1 > "${RUST_DIR}"/tests_ui_upstream.log
-cd "${RUST_SRC}"; RUST_BIN="${PWD}"/run.sh ./ui_compiletest.sh "${RUST_SRC}" "${RUST_DIR}"/tests/ui/smir "${RUST_DIR}"/tests_ui_sources --pass check --force-rerun 2>&1 > "${RUST_DIR}"/tests_ui_smir.log

TESTDIR=$(CURDIR)/tests/integration/programs

.PHONY: integration-test
integration-test:
@echo "Implement me!"
integration-test: TESTS ?= $(shell find $(TESTDIR) -type f -name "*.rs")
integration-test: SMIR ?= $(CURDIR)/run.sh -Z no-codegen
# override this to tweak how expectations are formatted
integration-test: NORMALIZE ?= jq -S -e -f $(TESTDIR)/../normalise-filter.jq
# override this to re-make golden files
integration-test: DIFF ?= | diff -
integration-test: build
errors=""; \
report() { echo "$$1: $$2"; errors="$$errors\n$$1: $$2"; }; \
for rust in ${TESTS}; do \
target=$${rust%.rs}.smir.json; \
dir=$$(dirname $${rust}); \
echo "$$rust"; \
${SMIR} --out-dir $${dir} $${rust} || report "$$rust" "Conversion failed"; \
[ -f $${target} ] \
&& ${NORMALIZE} $${target} ${DIFF} $${target}.expected \
&& rm $${target} \
|| report "$$rust" "Unexpected json output"; \
done; \
[ -z "$$errors" ] || (echo "===============\nFAILING TESTS:$$errors"; exit 1)


golden:
make integration-test DIFF=">"
3 changes: 0 additions & 3 deletions panic_example.rs

This file was deleted.

1 change: 1 addition & 0 deletions panic_example.rs
1 change: 0 additions & 1 deletion panic_example.smir.json

This file was deleted.

1 change: 1 addition & 0 deletions panic_example.smir.json
18 changes: 18 additions & 0 deletions tests/integration/normalise-filter.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ allocs:
( [ .allocs[] ]
# sort allocs by their ID
| sort_by(.[0])
# TODO this should be removed
| map ( select( .[1] | has("Static") | not ) )
),
functions:
( [ .functions[] ]
# sort functions by their ID (int, first in list)
| sort_by(.[0])
),
items:
( [ .items[] ]
# sort items by symbol name they refer to
| sort_by(.symbol_name)
)
}
3 changes: 3 additions & 0 deletions tests/integration/programs/panic_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
panic!()
}
Loading

0 comments on commit 471fd72

Please sign in to comment.