CodePadawans / ataru

MIT License
37 stars 3 forks source link

Bug when running against Anima #65

Closed moonglum closed 10 years ago

moonglum commented 10 years ago

Ok, found some tiny bugs when running Ataru against Anima. I think all of them can be solved by tweaking the RegEx :+1: I extracted the smallest possible examples:

Bug 1

1 == 1 # => true

will be converted to:

1 == assert_equal true, 1

Bug 2

a = { hey: 'ho' }
a # => { hey: 'ho' }

will be converted to:

a = { hey: 'ho' }
assert_equal {, a hey: 'ho' }
moonglum commented 10 years ago

Great! The new RegExp @madziaf proposed on HipChat works now. I found one additional problem that needs to be solved, then it all works fine!!!! And actually finds a bug in the README of anima :dancers:

This here:

{ hey: 'ho' } # => { hey: 'ho' }

Will be translated into that:

assert_equal { hey: 'ho' }, { hey: 'ho' }

This looks right at first, but it is actually a bug.

Ataru will report the following:

  1) Error:
#<Class:0x007f8c82988698>#test_bla_0:
SyntaxError: bla.md:4: syntax error, unexpected ':', expecting '}'
assert_equal { hey: 'ho' }, { hey: 'ho' }
                   ^
bla.md:4: syntax error, unexpected ',', expecting end-of-input
assert_equal { hey: 'ho' }, { hey: 'ho' }
                           ^
    /Users/moonglum/Code/ataru/lib/ataru/code_sample.rb:23:in `eval'
    /Users/moonglum/Code/ataru/lib/ataru/code_sample.rb:23:in `run'
    /Users/moonglum/Code/ataru/lib/ataru/test_class_builder.rb:24:in `block (3 levels) in build_test_class'

1 runs, 0 assertions, 0 failures, 1 errors, 0 skips

Hints

  1. The error message is quite confusing. This error is one ugly, ugly part of Ruby.
  2. It has something to do with Ruby's hashes and blocks having a very, very similar syntax.
  3. You do not have to adjust the Regex this time, but the replacement String.

Solution

Only read this if you are stuck and want the solution :wink: The replacement string has to be assert_equal(\2, \1). The parenthesis are needed here, because otherwise the hash will be interpreted as a block and Ruby gets sad. This is an ugly thing in Ruby, but with the parentheses everything is alright.

madziaf commented 10 years ago

Thanks for digging into possible bugs @moonglum ! Seems like ataru is getting into shape it's validation powers:) You know, I know that 'assert_equal' is a method and still I got used to writing it without parenthesis to the point I needed to read your solution. Thanks again:)

madziaf commented 10 years ago

solved with #64

moonglum commented 10 years ago

Confirmed – works now :+1: Great work! And don't forget to report the bug in the README of anima to the author :smile:

@madziaf You're welcome :smile: It's weird how some methods in Ruby don't really seem to be methods and it is weird to write them with parentheses (but also makes it quite beautiful :smile:). Can totally understand that!