tests: move trash files to their own trash/ directory
[rainbows.git] / t / GNUmakefile
blob8613baa13502230324c28a20afb7e151e97791a0
1 # we can run tests in parallel with GNU make
3 all::
5 ruby = ruby
6 rainbows_lib := $(shell cd ../lib && pwd)
7 -include ../local.mk
8 ifeq ($(RUBY_VERSION),)
9 RUBY_VERSION := $(shell $(ruby) -e 'puts RUBY_VERSION')
10 endif
12 ifeq ($(RUBYLIB),)
13 RUBYLIB := $(rainbows_lib)
14 else
15 RUBYLIB := $(rainbows_lib):$(RUBYLIB)
16 endif
17 export RUBYLIB
19 T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
21 all:: $(T)
23 # can't rely on "set -o pipefail" since we don't require bash or ksh93 :<
24 t_code = trash/$@-$(RUBY_VERSION).code
25 t_log = trash/$@-$(RUBY_VERSION).log
26 t_run = $(TRACER) $(SHELL) $(TEST_OPTS) $@
28 # prefix stdout messages with ':', and stderr messages with '!'
29 t_wrap = ( ( ( $(RM) $(t_code); \
30 $(t_run); \
31 echo $$? > $(t_code) ) \
32 | sed 's/^/$(pfx):/' 1>&3 ) 2>&1 \
33 | sed 's/^/$(pfx)!/' 1>&2 ) 3>&1
35 ifndef V
36 quiet_pre = @echo '* $@';
37 quiet_post = > $(t_log) 2>&1; exit $$(cat $(t_code))
38 pfx =
39 else
40 ifeq ($(V),2)
41 TEST_OPTS += -x
42 endif
43 quiet_pre = @echo '* $@';
44 quiet_post = 2>&1 | tee $(t_log); exit $$(cat $(t_code))
45 pfx = $@
46 endif
48 # TRACER='strace -f -o $@.strace -s 100000'
49 run_test = $(quiet_pre) ( $(t_wrap) ) $(quiet_post)
51 test-bin-$(RUBY_VERSION)/rainbows: ruby_bin = $(shell which $(ruby))
52 test-bin-$(RUBY_VERSION)/rainbows: ../bin/rainbows
53 mkdir -p $(@D)
54 install -m 755 $^ $@+
55 $(ruby) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $@+
56 cmp $@+ $@ 2>/dev/null || mv $@+ $@
57 $(RM) $@+
59 req_random_blob := t3100-revactor-tee-input
60 random_blob:
61 dd if=/dev/urandom bs=1M count=10 of=$@+
62 mv $@+ $@
64 $(addsuffix .sh,$(req_random_blob)): random_blob
66 $(T): trash/.gitignore
67 $(T): export ruby := $(ruby)
68 $(T): export PATH := $(CURDIR)/test-bin-$(RUBY_VERSION):$(PATH)
69 $(T): test-bin-$(RUBY_VERSION)/rainbows
70 $(run_test)
72 trash/.gitignore:
73 mkdir -p $(@D)
74 echo '*' > $@
76 clean:
77 $(RM) -r trash/*.log trash/*.code test-bin-$(RUBY_VERSION)
79 .PHONY: $(T) clean