# Build
# -----

# Verifies that everything builds.
build_all:
	cargo build --examples


# Unit tests
# ~~~~~~~~~~

# Runs all unit tests in the crate.
unit_tests:
	cargo nextest run --no-fail-fast --status-level=fail

# Generates a simple coverage report and writes it to disk as an HTML file.
coverage:
	cargo llvm-cov --html


# Integration tests
# ~~~~~~~~~~~~~~~~~

# Generates all tinantas, krdantas, and dhatus supported by the program and writes them to disk.
create_test_files:
	cargo run --release --example snapshot_tests create --output-dir test-files

# Runs a full evaluation over all forms generated by vidyut-prakriya. `hash` is
# the SHA-256 hash of the test file. We use `hash` to verify test file
# integrity and ensure that our test cases are stable.
#
# NOTE: test files might contain invalid forms. Our goal with this test is
# simply to confirm that the system hasn't changed in unexpected ways.
test_all: test_tinantas test_krdantas test_dhatus

test_tinantas:
	cargo run --release --example snapshot_tests validate \
		--test-type tinantas \
		-f test-files/tinantas-basic.msgpack \
		-h "1ca53f0f7612728943699d20b5e42d80ca340ed330102cdede1e2e3b8af9e973" \
		-f test-files/tinantas-nic.msgpack \
		-h "a8b186ff62fe20a08e147537614bbb3220fbfd8d2fce356514e5e595d1e579fb" \
		-f test-files/tinantas-san.msgpack \
		-h "6a5180111ba24c8a6cbdb9257990438c816515b5102193449857ab20bd07164e" \
		-f test-files/tinantas-yan.msgpack \
		-h "0ba293917913f2aed9423ea3125071c56426ca2fc9e06a2632f27297de4b0139" \
		-f test-files/tinantas-yan-luk.msgpack \
		-h "871c631461aa2ab1ded884de5bdf12464879f5da46c660c3076c333a3a90fd7f" \
		-f test-files/tinantas-san-nic.msgpack \
		-h "66b82321c244f4369422b06c2db9254d61a680eceeb6e9c0e8b8ac24a274b3c8" \
		-f test-files/tinantas-nic-san.msgpack \
		-h "c84fc7a9cfce47561b5075f974f5fae4a2820549336c344a97978f719c01e409"

test_krdantas:
	cargo run --release --example snapshot_tests validate \
		--test-type krdantas \
		-f test-files/krdantas-basic.msgpack \
		-h "07aa1d71eef9f7c557de5ffa07dafcfe2b1836fc09779421794055bd4143af90" \
		-f test-files/krdantas-nic.msgpack \
		-h "bdbadc06d3d94831c3eb1d8190286e289c10c3c55239b7c740bbea86e64a7062" \
		-f test-files/krdantas-san.msgpack \
		-h "7f7195e09f1e92e1af194c9fd01f08adf20d209d8e2dacd313e49de444f28eaf" \
		-f test-files/krdantas-yan.msgpack \
		-h "18f85a147517c8481d6355175aae5e6f0d144c4d1a029f2b2a9f49276d562b67" \
		-f test-files/krdantas-yan-luk.msgpack \
		-h "8bb265c99bd29ead515aef14e031c4fb9230b3abb8f2f2dc1387e48a8525a83a" \
		-f test-files/krdantas-san-nic.msgpack \
		-h "2db472ab2afeca38c40be55e8fe261441130b70fe0165696071cbe2ef9332a12" \
		-f test-files/krdantas-nic-san.msgpack \
		-h "ddefad731e0393fdf9896fe42a5187b7a060082e9043096f8969f463c888da4f"

test_dhatus:
	cargo run --release --example snapshot_tests validate \
		--test-type dhatus \
		-f test-files/dhatus.msgpack \
		-h "b76f6643625ca659b4fb7e7dd8534d9204237ec20c512943a4d87441ec938dae"


test_subantas:
	cargo run --bin test_subantas -- \
		--test-cases test-files/subantas.csv

check_rule_coverage:
	./scripts/check_rule_coverage.py > report.log 


# Performance
# ~~~~~~~~~~~

# Profiles the program's execution time on OSX. This command will probably not
# work on other operating systems.
profile-time-osx:
	cargo instruments -t time --release --example bench


# Other
# ~~~~~

# Generates project docs and opens them in your default browser.
docs:
	cargo doc --no-deps --open


# Web builds
# ----------

# Builds WASM module and JS wrapper (pkg/vidyut_prakriya.js).
#
# This is a release build. Creating it will be slower but smaller and (perhaps)
# more performant.
wasm_release:
	wasm-pack build --target web --release -- --features serde

# Builds WASM module and JS wrapper (pkg/vidyut_prakriya.js).
#
# This is a dev build. Creating it will be faster, but size and performance
# will not be optimized.
wasm_dev:
	wasm-pack build --target web -- --features serde

# Builds a simple web debugger.
debugger:
	./scripts/run-debugger.sh
