Ticket #3961 (closed bug: fixed)

Opened 3 years ago

Last modified 3 years ago

-O results in incorrect behavior

Reported by: RichardG Owned by: simonpj
Priority: high Milestone: 7.0.1
Component: Compiler Version: 6.12.1
Keywords: Cc: richardg@…
Operating System: MacOS X Architecture: x86
Type of failure: Incorrect result at runtime Difficulty:
Test Case: Blocked By: #3959
Blocking: Related Tickets:

Description

HUnit 1.2.2.1 ships with a set of unit tests. Incorrect behavior occurs when these tests are compiled into a program using Cabal and GHC 6.12.1 (Haskell Platform 2010.1).

Correct behavior occurs when these tests are:

  • compiled using ghc --make using GHC 6.12.1.
  • run using GHCi 6.12.1.
  • compiled into a program using Cabal and GHC 6.10.4 (Haskell Platform 2009.2).
  • compiled using ghc --make using GHC 6.10.4.
  • run using GHCi 6.10.4.

This behavior appears to involve interactions between the Testable and Assertable classes and instances in Test/HUnit/Base.hs. This affects the correctness of the programs.

Attachments

HUnit-6.10.4.txt Download (22.9 KB) - added by RichardG 3 years ago.
Script of running various tests with GHC 6.10.4
HUnit-6.12.1.txt Download (24.2 KB) - added by RichardG 3 years ago.
Script of running various tests with GHC 6.12.1
SimpleTest.zip Download (14.8 KB) - added by RichardG 3 years ago.
Simplified test case
SimpleTest.txt Download (3.7 KB) - added by RichardG 3 years ago.
Script of simplified test case

Change History

Changed 3 years ago by RichardG

Script of running various tests with GHC 6.10.4

Changed 3 years ago by RichardG

Script of running various tests with GHC 6.12.1

Changed 3 years ago by RichardG

Simplified test case

Changed 3 years ago by RichardG

Script of simplified test case

Changed 3 years ago by RichardG

I've attached a somewhat simplified test case (it's HUnit with a bunch of stuff ripped out). The tests/SimpleTest.hs file has 3 tests in it which compare the expected and actual results of a failed assert. These are:

expectProblem Failure 0 "test" (TestCase $ assertFailure "test"),
expectProblem Failure 0 "test" (test $ assertFailure "test"),
expectProblem Failure 0 "test" ((TestCase . (>>= assert)) $ (assertFailure "test"))

The first test gives the expected result. The second and third tests display the same erroneous behavior that is described in the original report (i.e., it behaves incorrectly only when compiled with GHC 6.12.1 and Cabal).

(The third test in the list is the second test where test has been replaced with, what I assume are, the appropriate functions.)

Changed 3 years ago by RichardG

  • cc richardg@… added
  • failure changed from None/Unknown to Incorrect result at runtime
  • summary changed from HUnit has erroneous behavior when compiled with Cabal to -O results in incorrect behavior on Mac OS X

Further experimentation has shown the behavior differs when the -O flag is used. I.e.,

ghc --make -i.:tests -cpp -DBASE4 tests/HUnitTest98.lhs

has the correct behavior but

ghc --make -i.:tests -cpp -DBASE4 -O tests/HUnitTest98.lhs

does not.

The severity of this issue is compounded by the fact that Cabal uses the -O flag by default.

Changed 3 years ago by RichardG

This was reproduced with the 6.12.2 snapshot (10-Apr-2010 15:57) as compiled with GHC 6.10.4 (Haskell Platform 2009.2).

Changed 3 years ago by RichardG

Ticket #3983 may be related.

Changed 3 years ago by simonpj

I suspect this is related to #3959, which I'm working on.

Simon

Changed 3 years ago by igloo

  • priority changed from normal to high
  • milestone set to 6.12.3

I can reproduce this on amd64/Linux with the 6.12 branch, but not the HEAD.

Changed 3 years ago by igloo

  • owner set to simonpj

Changed 3 years ago by igloo

  • summary changed from -O results in incorrect behavior on Mac OS X to -O results in incorrect behavior

Changed 3 years ago by simonmar

  • milestone changed from 6.12.3 to 6.14.1

This won't be fixed for 6.12.3, but we almost have a fix ready for HEAD.

Changed 3 years ago by igloo

  • blockedby 3959 added

Changed 3 years ago by simonpj

  • status changed from new to infoneeded

I believe this is now fixed by the fix to #3959. Could you see if it works now, please?

Thanks

Simon

Changed 3 years ago by RichardG

Tested with HUnit 1.2.2.3 and GHC 7.0.0.20100924 on Mac OS X 10.6.4 Server. Issue was not reproduced.

Changed 3 years ago by simonpj

  • status changed from infoneeded to closed
  • resolution set to fixed

OK so it looks as if it's fixed. Good. I'm clsoing te ticket.

Simon

Note: See TracTickets for help on using tickets.