forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
1 parent
7e13e9e
commit 8a829ba
Showing
3 changed files
with
41 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |