質問

だから私はHTFを使っていくつかの狩人スタイルの主張を実行しようとしています

% cat tests/TestDemo.hs
{-# OPTIONS_GHC -Wall -F -pgmF htfpp #-}
module Main where
import Test.Framework
import Test.HUnit.Base ((@?=))
import System.Environment (getArgs)

-- just run some tests
main :: IO ()
main = getArgs >>= flip runTestWithArgs Main.allHTFTests

-- all these tests should fail
test_fail_int1 :: Assertion
test_fail_int1 = (0::Int) @?= (1::Int)

test_fail_bool1 :: Assertion
test_fail_bool1 = True @?= False

test_fail_string1 :: Assertion
test_fail_string1 = "0" @?= "1"

test_fail_int2 :: Assertion
test_fail_int2 = [0::Int] @?= [1::Int]

test_fail_string2 :: Assertion
test_fail_string2 = "true" @?= "false"

test_fail_bool2 :: Assertion
test_fail_bool2 = [True] @?= [False]

そして、私が使用するとき ghc --make, 、それは正しく機能しているようです。

% ghc --make tests/TestDemo.hs
[1 of 1] Compiling Main             ( tests/TestDemo.hs, tests/TestDemo.o )
Linking tests/TestDemo ...
% tests/TestDemoA
...
* Tests:    6
* Passed:   0
* Failures: 6
* Errors:   0

Failures:
  * Main:fail_int1 (tests/TestDemo.hs:9)
  * Main:fail_bool1 (tests/TestDemo.hs:12)
  * Main:fail_string1 (tests/TestDemo.hs:15)
  * Main:fail_int2 (tests/TestDemo.hs:19)
  * Main:fail_string2 (tests/TestDemo.hs:22)
  * Main:fail_bool2 (tests/TestDemo.hs:25)

しかし、私がCabalを使用してそれを構築するとき、失敗するはずのすべてのテストが失敗するわけではありません。

% cat Demo.cabal
...
executable test-demo
  build-depends: base >= 4, HUnit, HTF
  main-is: TestDemo.hs
  hs-source-dirs: tests
% cabal configure
Resolving dependencies...
Configuring Demo-0.0.0...
% cabal build
Preprocessing executables for Demo-0.0.0...
Building Demo-0.0.0...
[1 of 1] Compiling Main             ( tests/TestDemo.hs, dist/build/test-demo/test-demo-tmp/Main.o )
Linking dist/build/test-demo/test-demo ...
% dist/build/test-demo/test-demo
...
* Tests:    6
* Passed:   3
* Failures: 3
* Errors:   0

Failures:
  * Main:fail_int2 (tests/TestDemo.hs:23)
  * Main:fail_string2 (tests/TestDemo.hs:26)
  * Main:fail_bool2 (tests/TestDemo.hs:29)

何が悪いのか、どうすれば修正できますか?

役に立ちましたか?

解決

これは、GHCの特定のバージョンのバグであり、場合によってはIOの例外をスローするオプティマイザーを削除することに関連しています。最適化が有効になっている場合、Hunitコードでは非常に一般的です。およびカバルセット -O1 デフォルトでは、バグを有効にします。

GHC 7へのアップグレードはそれを修正します(ライブラリがそれに追いつくまで実際には推奨されません。つまり、GHC 7に対してHaskellプラットフォームリリースが行われます)。

あなたも置くことができます -O0 テスト実行可能ファイルに関連する.cabalファイルStanzaのコンパイラオプション。これは、プロジェクトをGHC 7に移動する準備ができるまで、テストコードのために行ったことです。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top