Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate stubs that tell you when they are called. Helpful when componentizing for test.
# gccmock - generate exploding link stubs from linker error messages
#
# Usage: gcc [files] 2>&1 ruby gccmock.rb > [filename].c
LINK_SYMBOL = /.*"_([_a-z0-9]*)",/
puts "#include <assert.h>\n"
puts "#define EXPLODE(name) void name() { assert(!\"unexpected call\"); }"
puts ARGF.grep(LINK_SYMBOL) { |string| "EXPLODE(#{$1})" } \
.uniq \
.sort \
.join($/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment