# nostr - the shared protocol codecs and primitives.
#
# Everything here is used by more than one target: the morly relay (native) and
# the musiquay web app (wasm). Shared code therefore stays wasm-safe - no os,
# no net, no syscalls (pkg/ws is the exception and is native-only; its files
# carry a `//:build !wasm` line).

MOXIE    ?= $(CURDIR)/../moxie/moxie
# An inherited MOXIEROOT is ignored on purpose: `?=` cannot tell an exported
# stale root from an intended one, and a stale root silently compiles a
# different tree's src/ and pkg/. Pass it on the command line to build against
# another tree: make MOXIEROOT=/path/to/moxie ...
ifeq ($(origin MOXIEROOT),environment)
MOXIEROOT := $(CURDIR)/../moxie
endif
MOXIEROOT ?= $(CURDIR)/../moxie

CAPTURES ?= -allow-closure-captures

# Every package under pkg/ carrying a *_test.mx, through the compiler's harness.
# `moxie test` takes one package at a time.
test-unit:
	@set -e ; for d in $$( find pkg -name '*_test.mx' | xargs -n1 dirname | sort -u ) ; do \
		echo "=== unit: $$d" ; \
		MOXIEROOT=$(MOXIEROOT) $(MOXIE) test $(CAPTURES) ./$$d || exit 1 ; \
	done

test: test-unit

.PHONY: test-unit test
