gpt4 book ai didi

unit-testing - 使用 Haskell Stack 运行 detailed-0.9 测试套件时为 "module cannot be found locally"

转载 作者:行者123 更新时间:2023-11-28 20:48:56 25 4
gpt4 key购买 nike

我有一个 Haskell 项目和一个使用 detailed-0.9 的测试套件。我可以使用 cabal 正确运行测试,但是使用 stack 我会出错。 exitcode-stdio-1.0 测试套件似乎工作正常。

MWE

下面是一个最小的工作示例,包含两种测试套件类型。完整的存储库可用 here .

stack-test-detailed.cabal

name: stack-test-detailed
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.20

test-suite exitcode
type: exitcode-stdio-1.0
main-is: Exitcode.hs
other-modules: MyModule
build-depends: base >=4.10
hs-source-dirs: src testsuite
default-language: Haskell2010

test-suite detailed
type: detailed-0.9
test-module: Detailed
other-modules: MyModule
build-depends: base >=4.10, Cabal >=1.20
hs-source-dirs: src testsuite
default-language: Haskell2010

src/MyModule.hs

module MyModule where

myFunction :: Int
myFunction = 1

testsuite/Exitcode.hs

import MyModule (myFunction)
import System.Exit (exitSuccess, exitFailure)

main :: IO ()
main =
if myFunction == 1
then exitSuccess
else exitFailure

testsuite/Detailed.hs

module Detailed where

import MyModule (myFunction)
import Distribution.TestSuite

tests :: IO [Test]
tests = return
[ Test $ TestInstance
{ run = return $ Finished $ if myFunction == 1 then Pass else Fail "not equal 1"
, name = "my test"
, Distribution.TestSuite.tags = []
, options = []
, setOption = \opt val -> Left "options not supported"
}
]

堆栈.yaml

resolver: lts-11.22

输出

cabal

一切正常:

$ cabal test exitcode
Preprocessing test suite 'exitcode' for stack-test-detailed-0.1.0.0..
Building test suite 'exitcode' for stack-test-detailed-0.1.0.0..
Running 1 test suites...
Test suite exitcode: RUNNING...
Test suite exitcode: PASS
Test suite logged to: dist/test/stack-test-detailed-0.1.0.0-exitcode.log
1 of 1 test suites (1 of 1 test cases) passed.
$ cabal test detailed
Preprocessing test suite 'detailed' for stack-test-detailed-0.1.0.0..
Building test suite 'detailed' for stack-test-detailed-0.1.0.0..
[1 of 1] Compiling Main ( dist/build/detailedStub/detailedStub-tmp/detailedStub.hs, dist/build/detailedStub/detailedStub-tmp/Main.o )
Linking dist/build/detailedStub/detailedStub ...
Running 1 test suites...
Test suite detailed: RUNNING...
Test suite detailed: PASS
Test suite logged to: dist/test/stack-test-detailed-0.1.0.0-detailed.log
1 of 1 test suites (1 of 1 test cases) passed.

堆栈

退出代码测试有效:

$ stack test :exitcode
stack-test-detailed-0.1.0.0: build (test)
Preprocessing test suite 'exitcode' for stack-test-detailed-0.1.0.0..
Building test suite 'exitcode' for stack-test-detailed-0.1.0.0..
stack-test-detailed-0.1.0.0: test (suite: exitcode)


stack-test-detailed-0.1.0.0: Test suite exitcode passed
Completed 2 action(s).

详细测试编译失败:

$ stack test :detailed
stack-test-detailed-0.1.0.0: build (test)
Preprocessing test suite 'detailed' for stack-test-detailed-0.1.0.0..
Building test suite 'detailed' for stack-test-detailed-0.1.0.0..

<no location info>: error:
module ‘MyModule’ cannot be found locally

Progress 1/2

-- While building custom Setup.hs for package stack-test-detailed-0.1.0.0 using:
/Users/john/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_2.0.1.0_ghc-8.2.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-2.0.1.0 build test:detailed --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always"
Process exited with code: ExitFailure 1

环顾四周,我发现 detailed-0.9 有点不酷,人们似乎很快就放弃了它。但它是properly documented并且确实适用于 cabal,所以我不明白为什么 stack 会失败。

最佳答案

更新

似乎这实际上是 Stack 的一个错误,已经被报告过 here并固定 here (尽管最新版本中还没有修复)。

关于unit-testing - 使用 Haskell Stack 运行 detailed-0.9 测试套件时为 "module cannot be found locally",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54827529/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com