Permalink
Browse files

Handle filenames with colons. Fixes #1

Thanks to ukabu for the report and initial patch.
  • Loading branch information...
1 parent d59046e commit 09ad388bb6a42990652b2e760eb204db2755d29a @mynyml committed Dec 25, 2009
Showing with 14 additions and 4 deletions.
  1. +3 −4 lib/nanotest.rb
  2. +1 −0 test/test_helper.rb
  3. +10 −0 test/test_nanotest.rb
View
@@ -3,11 +3,10 @@ module Nanotest
@@failures, @@dots = [], []
- def assert(msg=nil, file=nil, line=nil, &block)
+ def assert(msg=nil, file=nil, line=nil, stack=caller, &block)
unless block.call
- file ||= caller.first.split(':')[0]
- line ||= caller.first.split(':')[1]
- @@failures << "(%s:%0.3d) %s" % [file, line, msg || "assertion failed"]
+ f,l = stack.first.match(/(.*):(\d+)/)[1..2]
+ @@failures << "(%s:%0.3d) %s" % [file || f, line || l, msg || "assertion failed"]
@@dots << 'F'
else
@@dots << '.'
View
@@ -3,6 +3,7 @@
begin
require 'redgreen'
require 'phocus'
+ require 'ruby-debug'
rescue LoadError, RuntimeError
end
View
@@ -76,5 +76,15 @@ def teardown
test "displays results with no assertions" do
assert_empty Nanotest.results.strip
end
+
+ test "handles origin lines that contain colons" do
+ stack = ['o:hai:e:20:blah']
+ Nanotest.assert('', nil, nil, stack) { false }
+ assert_equal "(o:hai:e:020) ", Nanotest.failures.last
+
+ stack = ['o:hai:e:20']
+ Nanotest.assert('', nil, nil, stack) { false }
+ assert_equal "(o:hai:e:020) ", Nanotest.failures.last
+ end
end

0 comments on commit 09ad388

Please sign in to comment.