Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@michaelfeathers
Created May 5, 2011 19:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save michaelfeathers/957739 to your computer and use it in GitHub Desktop.
Save michaelfeathers/957739 to your computer and use it in GitHub Desktop.
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.select { |line| LINK_SYMBOL =~ line } \
.map { |line| LINK_SYMBOL.match(line)[1] } \
.uniq \
.sort \
.map { |name| "EXPLODE(#{name});" } \
.join($/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment