
Suppose I'm playing with HUnit for nearly the first time. I might write a test program like this, to see what a test failure looks like in practice: import Test.HUnit import Test.HUnit.Tools main = runVerboseTests $ TestList [ TestCase $ assertBool "should fail" False , TestCase $ assertEqual "should also fail" "foo" "bar"] # runghc test.hs Testing 0 ### Failure in: 0 should fail Testing 1 ### Failure in: 1 should also fail expected: "foo" but got: "bar" Cases: 2 Tried: 2 Errors: 0 Failures: 2 (Counts {cases = 2, tried = 2, errors = 0, failures = 2},0) Good, that works. Then I drop it into a Makefile that already knows how to build haskell programs: # make test ghc -odir build -hidir build -O2 --make test [1 of 1] Compiling Main ( test.hs, build/Main.o ) Linking test ... ./test Testing 0 Testing 1 ### Failure in: 1 should also fail expected: "foo" but got: "bar" Cases: 2 Tried: 2 Errors: 0 Failures: 1 Wait, what?! One of my test cases is impossibly, passing. So, the problem seems to be that ghc -O2 somehow optimises the static assertBool _ True away, in what seems to be a bad way. Remove the -O2 and the test fails as expected. Presumably, although I have not verified, less static boolean values would not trigger the optimisation. Is this a ghc or HUnit bug? (Versions: 6.12.1, 1.2.2.1) -- see shy jo