# Generally, JUNIT_FILE is set in CI but may be specified to an arbitrary file location to emulate CI locally
ifdef JUNIT_FILE
	go_test = OP_TESTLOG_DISABLE_COLOR=true OP_E2E_DISABLE_PARALLEL=false gotestsum --format=standard-verbose --junitfile=$(JUNIT_FILE) --
  # Note: -parallel must be set to match the number of cores in the resource class
	go_test_flags = -timeout=20m -parallel=8
else
	go_test = go test
	go_test_flags = -v
endif

test: pre-test test-ws
.PHONY: test

test-external-%: pre-test
	make -C ./external_$*/
	$(go_test) $(go_test_flags) --externalL2 ./external_$*/

test-ws: pre-test
	$(go_test) $(go_test_flags) ./...
.PHONY: test-ws

test-http: pre-test
	OP_E2E_USE_HTTP=true $(go_test) $(go_test_flags) ./...
.PHONY: test-ws

cannon-prestate:
	make -C .. cannon-prestate
.PHONY: cannon-prestate

# We depend on the absolute pre-state generated by cannon to deploy the dispute game contracts.
devnet-allocs: pre-test-cannon
	make -C .. devnet-allocs
.PHONY: devnet-allocs

pre-test: pre-test-cannon pre-test-allocs
.PHONY: pre-test

pre-test-cannon:
	@if [ ! -e ../op-program/bin ]; then \
		make cannon-prestate; \
	fi
.PHONY: pre-test-cannon

pre-test-allocs:
	@if [ ! -e ../.devnet ]; then \
		make devnet-allocs; \
	fi
.PHONY: pre-test-allocs

clean:
	rm -r ../.devnet
	rm -r ../op-program/bin
.PHONY: clean

lint:
	golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" ./...
.PHONY: lint
