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