Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Forked from michaelfeathers/gccmock.rb
Created May 5, 2011 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tenderlove/957751 to your computer and use it in GitHub Desktop.
Save tenderlove/957751 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.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