aboutsummaryrefslogtreecommitdiff
path: root/oldtests/Makefile
blob: c8a30bd25365f8b2a66152e89162769a92c3dbc0 (plain)
  1. SHELL=/bin/bash
  2. TESTDIR ?= *
  3. PATT ?= .
  4. TESTS=$(shell ls $(TESTDIR)/*.markdown | grep $(PATT))
  5. DIFFS=$(patsubst %.markdown,%.diff,$(TESTS))
  6. PROG ?= ../stmd
  7. FILTER ?= perl -pe 's/ /␣/g'
  8. TIDYCMD ?= tidy -asxhtml -utf8 --show-body-only yes --show-warnings no -quiet
  9. DETAILS ?= 1
  10. # Check to see if echo supports -e option to allow backslash escapes
  11. ifeq ($(shell echo -e),-e)
  12. ECHO=echo
  13. else
  14. ECHO=echo -e
  15. endif
  16. all: $(DIFFS)
  17. PASS=0;TESTS=0; \
  18. for f in $(DIFFS); do \
  19. let TESTS=TESTS+1; \
  20. [ -s $$f ] || let PASS=PASS+1; \
  21. done; \
  22. $(ECHO) "\033[1m$$PASS of $$TESTS tests passed.\033[0m"; \
  23. if [ $$TESTS -eq $$PASS ]; then exit 0; else exit 1; fi
  24. %.actual.html: %.markdown
  25. ifeq ($(TIDY),1)
  26. -cat $< | $(PROG) | $(TIDYCMD) > $@
  27. else
  28. -cat $< | $(PROG) > $@
  29. endif
  30. %.expected.html: %.html
  31. ifeq ($(TIDY),1)
  32. -$(TIDYCMD) $< > $@
  33. else
  34. cp $< $@
  35. endif
  36. %.diff: %.expected.html %.actual.html
  37. diff --unified=1 <(cat $(word 1,$^) | $(FILTER)) <(cat $(word 2,$^) | $(FILTER)) > $@ ; \
  38. if [ -s $@ ]; then \
  39. $(ECHO) "\033[1;31m✘ $(patsubst %.diff,%,$@)\033[0m"; \
  40. if [ $(DETAILS) == "1" ]; then \
  41. $(ECHO) "\033[0;36m" ; cat $@; $(ECHO) "\033[0m"; \
  42. fi \
  43. else \
  44. $(ECHO) "\033[1;32m✓ $(patsubst %.diff,%,$@)\033[0m"; \
  45. fi
  46. .PHONY: all clean
  47. clean:
  48. -@rm */*.{diff,actual.html,expected.html}