forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-mocks.sh
executable file
·39 lines (34 loc) · 1.17 KB
/
update-mocks.sh
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
#!/usr/bin/env bash
# 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=$(grep -F -n '/* AUTOGENERATED MOCKS START */' "$FILE" | cut -d: -f1)
END=$(grep -F -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 "${FILE/%.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 ! grep -F -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