jocarreira / hamcrest

Automatically exported from code.google.com/p/hamcrest
0 stars 0 forks source link

JavaLangMatcherAssertTest fails incorrectly #49

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
JavaLangMatcherAssertTest (rev. 305) fails both tests.

testFailingAssertion should include an extra negation:
    if (!thrown) {
        fail();
    }

testPassingAssertion should use a matcher that will return true:
    assert that ("Foo", startsWith("F")) // not startsWith("Far")

Original issue reported on code.google.com by joe.kear...@gtempaccount.com on 15 Oct 2008 at 7:57

Attachments:

GoogleCodeExporter commented 8 years ago
Does anyone use this feature? I can fix it, but I can't test it since I can't 
figure out the relevant flags for the Mac 
compiler, and noone's picked up this bug for ages.

How about we just remove it?

Original comment by smgfree...@gmail.com on 15 Oct 2008 at 9:19

GoogleCodeExporter commented 8 years ago
I believe you'll need to enable assertions on the test JVM. This doesn't appear 
to
happen when I run the tests under Ant anyway.

Original comment by joe.kear...@gtempaccount.com on 15 Oct 2008 at 9:20

GoogleCodeExporter commented 8 years ago
My reading of the doc suggests that assert isn't supported on OS/X java, and it 
doesn't respond to the standard 
compiler flags. On the other hand, maybe it's just late.

If we can't find a way to test it or someone that's interested, I suggest we 
drop the feature. 

Original comment by smgfree...@gmail.com on 15 Oct 2008 at 10:06

GoogleCodeExporter commented 8 years ago
I think it'd be a shame to drop just because one of the platforms doesn't 
support
assertions.

Perhaps the thing to do is to re-cast this to work in if- and while-statements,
rather than assertions. The two are pretty much equivalent, except in name. 
Consider
    if (that(cheese, is(smelly()))) { ... }
Rolls of the tongue rather more easily than
    if (is(smelly()).matches(cheese)) { ... }

Clearly this needs a new name, but the ability to use a matcher inline would be 
nice,
in both assertions and conditionals.

By the way, I really like the assert (assertionsEnabled = true) side effects 
trick in
the updated test case.

Original comment by joe.kear...@gtempaccount.com on 16 Oct 2008 at 10:20

GoogleCodeExporter commented 8 years ago
Test is fixed.  It did not have to call assert at all

Original comment by nat.pr...@gmail.com on 16 Oct 2008 at 12:06

GoogleCodeExporter commented 8 years ago

Original comment by smgfree...@gmail.com on 22 Nov 2008 at 12:15