default: diag

TEST = surcharge
TODELETE = $(TEST).export $(TEST)_astout.export $(TEST).comm aster.exe commande $(TEST).list $(TEST).resu_test etude astout

include ../Makefile.inc

$(TEST).comm:
	@echo 'DEBUT(MCTEST_CAPY="hello world")' > $(TEST).tmp
	@echo 'FIN()'  >> $(TEST).tmp
	@mv -f $(TEST).tmp $@

aster.exe: ../compil/aster.exe
	@ln -s $< $@

commande: ../catapy/commande
	@ln -s $< $@

../compil/aster.exe ../catapy/commande:
	(cd $(@D) && $(MAKE) $(@F))

etude: $(TEST).export $(TEST).comm aster.exe commande
	$(as_run) $< > output.1.$@ 2> error.1.$@
	@grep EXIT_CODE output.1.$@ > exit_code.tmp
	@if  [ `grep -c EXIT_CODE=0 exit_code.tmp` -eq 1 ] && \
	     [ `grep -c MCTEST_EXE_OK output.1.$@` -ne 1 ]; then \
	   echo "EXIT_CODE=104" > exit_code.tmp; \
	fi
	@mv -f exit_code.tmp $@

$(TEST).list:
	@echo 'forma01a'  > $(TEST).tmp
	@echo 'adlv100a' >> $(TEST).tmp
	@mv -f $(TEST).tmp $@

$(TEST).resu_test:
	@mkdir $@

astout: $(TEST)_astout.export $(TEST).list $(TEST).resu_test aster.exe commande
	$(as_run) $< > output.1.$@ 2> error.1.$@
	@grep EXIT_CODE output.1.$@ > exit_code.tmp
	@if  [ `grep -c EXIT_CODE=0 exit_code.tmp` -eq 1 ]; then \
	   if   [ `grep -c MCTEST_EXE_OK $(TEST).resu_test/adlv100a.mess` -ne 1 ] || \
	        [ `grep -c MCTEST_EXE_OK $(TEST).resu_test/forma01a.mess` -ne 1 ]; then \
	      echo "EXIT_CODE=104" > exit_code.tmp; \
	   fi; \
	fi
	@mv -f exit_code.tmp $@

unittest: etude astout
	@if  [ `grep -c EXIT_CODE=0 etude`  -ne 1 ] || \
	     [ `grep -c EXIT_CODE=0 astout` -ne 1 ]; then \
	   echo "EXIT_CODE=104" > exit_code.tmp; \
	else \
		cp etude exit_code.tmp; \
	fi
	@mv -f exit_code.tmp $@


