mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 00:54:20 +01:00
update-mocks: move mock generation into tools/, fix and generalize.
update-mocks was broken, since it assumed the daemon/ directory. We now use "make" directly to build the test file and harvest errors, and are more robust if it simply doesn't compile (ie. fails, but no linker errors). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
7e13e9e457
commit
8a829ba9cb
14
Makefile
14
Makefile
@@ -281,19 +281,7 @@ clean: wire-clean
|
|||||||
find . -name '*gcno' -delete
|
find . -name '*gcno' -delete
|
||||||
|
|
||||||
update-mocks/%: %
|
update-mocks/%: %
|
||||||
@set -e; BASE=/tmp/mocktmp.$$$$.`echo $* | tr / _`; trap "rm -f $$BASE.*" EXIT; \
|
@tools/update-mocks.sh "$*"
|
||||||
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 \
|
|
||||||
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/%: %
|
unittest/%: %
|
||||||
$(VALGRIND) $(VALGRIND_TEST_ARGS) $*
|
$(VALGRIND) $(VALGRIND_TEST_ARGS) $*
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ if [ $# -eq 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
for SYMBOL; do
|
for SYMBOL; do
|
||||||
WHERE=$(grep -nH "^[a-z0-9_ ]* [*]*$SYMBOL(" daemon/*.h)
|
WHERE=$(grep -nH "^[a-z0-9_ ]* [*]*$SYMBOL(" */*.h )
|
||||||
if [ x"$WHERE" != x ]; then
|
if [ x"$WHERE" != x ]; then
|
||||||
STUB='\n{ fprintf(stderr, "'$SYMBOL' called!\\n"); abort(); }'
|
STUB='\n{ fprintf(stderr, "'$SYMBOL' called!\\n"); abort(); }'
|
||||||
else
|
else
|
||||||
39
tools/update-mocks.sh
Executable file
39
tools/update-mocks.sh
Executable file
@@ -0,0 +1,39 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# Script to rewrite the autogenerated mocks in a unit test between
|
||||||
|
# /* AUTOGENERATED MOCKS START */ and /* AUTOGENERATED MOCKS END */
|
||||||
|
# based on link failures.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
FILE="$1"
|
||||||
|
|
||||||
|
BASE=/tmp/mocktmp.$$.`echo $@ | tr / _`
|
||||||
|
trap "mv $BASE.old $FILE; rm -f $BASE.*" EXIT
|
||||||
|
|
||||||
|
START=`fgrep -n '/* AUTOGENERATED MOCKS START */' $FILE | cut -d: -f1`
|
||||||
|
END=`fgrep -n '/* AUTOGENERATED MOCKS END */' $FILE | cut -d: -f1`
|
||||||
|
|
||||||
|
if [ -n "$START" ]; then
|
||||||
|
mv $FILE $BASE.old
|
||||||
|
echo $FILE:
|
||||||
|
head -n $START $BASE.old > $FILE
|
||||||
|
tail -n +$END $BASE.old >> $FILE
|
||||||
|
# Try to make binary.
|
||||||
|
if ! make `echo $FILE | sed 's/.c$//'` 2> $BASE.err >/dev/null; then
|
||||||
|
tools/mockup.sh < $BASE.err >> $BASE.stubs
|
||||||
|
# If there are no link errors, maybe compile fail for other reason?
|
||||||
|
if ! fgrep -q 'Generated stub for' $BASE.stubs; then
|
||||||
|
cat $BASE.err
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sed -n 's,.*Generated stub for \(.*\) .*,\t\1,p' < $BASE.stubs
|
||||||
|
head -n $START $BASE.old > $FILE
|
||||||
|
cat $BASE.stubs >> $FILE
|
||||||
|
tail -n +$END $BASE.old >> $FILE
|
||||||
|
else
|
||||||
|
echo "...build succeeded without stubs"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# All good.
|
||||||
|
rm -f $BASE.*
|
||||||
|
trap "" EXIT
|
||||||
Reference in New Issue
Block a user