Pregunta

Así que estoy tratando de utilizar HTF para ejecutar algunas afirmaciones de estilo HUnit

% 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]

Y cuando uso ghc --make, parece que funciona correctamente.

% 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)

Pero cuando uso cabal de construirlo, no todas las pruebas que deben fallar, fallará.

% 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)

¿Qué va mal y cómo puedo solucionarlo?

¿Fue útil?

Solución

Este es un error en ciertas versiones de GHC, relacionados con el optimizador de la eliminación de lanzar excepciones IO en algunos casos. Es muy común con código HUnit, si están activadas las optimizaciones. Y conjuntos Cabal -O1 por defecto, lo que permite que el insecto.

Actualización a GHC 7 fija (Sin realmente recomendadas hasta que las bibliotecas han puesto al día con ella, es decir, una versión de la plataforma Haskell está hecho para GHC 7).

También puede poner -O0 en las opciones del compilador en la estrofa archivo .cabal relacionada con el ejecutable de prueba. Esto es lo que he hecho para mi código de prueba, hasta que esté listo para mi proyecto de GHC 7.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top