# Runs every regression check under audit/ against this tree's built artifacts:
# MOLO-* against build/bin/runtime_interop_server, build/example/living-server,
# build/molo (plus tiny harnesses from src/), CVE-* against build/doos/doos.
# Usage:
#   make -C audit test          # sequential, stops at the first FAIL
#   make -C audit -j8 test      # concurrent, one job per check directory (recursive make)
#   make -C audit report        # runs every check, never stops, prefixes output with the check id
#   make -C audit list          # names the check directories this covers
#
# Each check's Makefile delegates to that directory's reproduce script,
# which prints exactly one of PASS, FAIL or SKIP and exits 0 for PASS/SKIP, 1 for FAIL.
# "test" is the hard cap: this file does not invent new checks, it only fans out to
# the fixed, named list below. See README.md.

MOLO_BUILD ?= $(abspath ../build)
DOOS ?= $(MOLO_BUILD)/doos/doos
TMPDIR ?= $(MOLO_BUILD)/audit-tmp
CHECKS := $(sort $(wildcard MOLO-*) $(wildcard CVE-*))
export MOLO_BUILD DOOS TMPDIR

.PHONY: test $(CHECKS) list report audit-tmp

test: $(CHECKS)
	@echo "audit: $(words $(CHECKS)) checks run against $(MOLO_BUILD)"

audit-tmp:
	@mkdir -p "$(TMPDIR)"

$(CHECKS): | audit-tmp
	@$(MAKE) -s -C $@ test MOLO_BUILD=$(MOLO_BUILD) DOOS=$(DOOS)

list:
	@for c in $(CHECKS); do echo $$c; done

report:
	@status=0; for c in $(CHECKS); do \
		$(MAKE) -s -C $$c test MOLO_BUILD=$(MOLO_BUILD) DOOS=$(DOOS) 2>&1 | sed "s/^/$$c: /" || status=1; \
	done; exit $$status
