diff --git a/Makefile b/Makefile index fd946b950..14d0fc2e4 100644 --- a/Makefile +++ b/Makefile @@ -350,6 +350,21 @@ clean: daemon-clean wire-clean include daemon/Makefile +update-mocks/%: % + @set -e; BASE=/tmp/mocktmp.$$$$.`echo $* | tr / _`; trap "rm -f $$BASE.*" EXIT; \ + START=`fgrep -n '/* AUTOGENERATED MOCKS START */' $< | cut -d: -f1`;\ + END=`fgrep -n '/* AUTOGENERATED MOCKS END */' $< | cut -d: -f1`; \ + if [ -n "$$START" ]; then \ + echo $<: ; \ + head -n $$START $< > $$BASE.new; \ + (cat $$BASE.new; tail -n +$$END $<) > $$BASE.test.c; \ + if ! $(CC) $(CFLAGS) $$BASE.test.c -o $$BASE.out $(HELPER_OBJS) $(CCAN_OBJS) $(LDLIBS) 2>$$BASE.err; then \ + daemon/test/scripts/mockup.sh < $$BASE.err >> $$BASE.new; \ + sed -n 's,.*Generated stub for \(.*\) .*,\t\1,p' < $$BASE.new; \ + fi; \ + tail -n +$$END $< >> $$BASE.new; mv $$BASE.new $<; \ + fi + unittest/%: % $(VALGRIND) $(VALGRIND_TEST_ARGS) $* diff --git a/daemon/test/Makefile b/daemon/test/Makefile index 58d00067c..e5e8e9cf9 100644 --- a/daemon/test/Makefile +++ b/daemon/test/Makefile @@ -61,22 +61,7 @@ DAEMON_TEST_SRC := $(wildcard daemon/test/run-*.c) DAEMON_TEST_OBJS := $(DAEMON_TEST_SRC:.c=.o) DAEMON_TEST_PROGRAMS := $(DAEMON_TEST_OBJS:.o=) -update-mocks-daemon/test/%: daemon/test/% - @set -e; trap "rm -f mocktmp.$*.*" EXIT; \ - START=`fgrep -n '/* AUTOGENERATED MOCKS START */' $< | cut -d: -f1`;\ - END=`fgrep -n '/* AUTOGENERATED MOCKS END */' $< | cut -d: -f1`; \ - if [ -n "$$START" ]; then \ - echo $<: ; \ - head -n $$START $< > mocktmp.$*.new; \ - (cat mocktmp.$*.new; tail -n +$$END $<) > mocktmp.$*.test.c; \ - if ! $(CC) $(CFLAGS) mocktmp.$*.test.c -o mocktmp.$*.out $(HELPER_OBJS) $(CCAN_OBJS) $(LDLIBS) 2>mocktmp.$*.err; then \ - daemon/test/scripts/mockup.sh < mocktmp.$*.err >> mocktmp.$*.new; \ - sed -n 's,.*Generated stub for \(.*\) .*,\t\1,p' < mocktmp.$*.new; \ - fi; \ - tail -n +$$END $< >> mocktmp.$*.new; mv mocktmp.$*.new $<; \ - fi - -update-mocks: $(DAEMON_TEST_SRC:%=update-mocks-%) +update-mocks: $(DAEMON_TEST_SRC:%=update-mocks/%) $(DAEMON_TEST_PROGRAMS): $(CCAN_OBJS) $(BITCOIN_OBJS) $(CORE_OBJS) libsecp256k1.a utils.o diff --git a/daemon/test/scripts/mockup.sh b/daemon/test/scripts/mockup.sh index 815e4b8ad..1c88f3042 100755 --- a/daemon/test/scripts/mockup.sh +++ b/daemon/test/scripts/mockup.sh @@ -35,5 +35,5 @@ for SYMBOL; do END=$(tail -n +$LINE < $FILE | grep -n ';$'); NUM=${END%%:*} - tail -n +$LINE < $FILE | head -n $NUM | sed 's/^extern *//' | sed 's/PRINTF_FMT([^)]*)//' | sed 's/,/ UNNEEDED,/g' | sed 's/\([a-z0-9A-Z*_]* [a-z0-9A-Z*_]*\));/\1 UNNEEDED);/' | sed "s/;\$/$STUB/" + tail -n +$LINE < $FILE | head -n $NUM | sed 's/^extern *//' | sed 's/PRINTF_FMT([^)]*)//' | sed 's/,/ UNNEEDED,/g' | sed 's/\([a-z0-9A-Z*_]* [a-z0-9A-Z*_]*\));/\1 UNNEEDED);/' | sed "s/;\$/$STUB/" | sed 's/\s*$//' done