代码之家  ›  专栏  ›  技术社区  ›  John J. Camilleri

使用Haskell堆栈运行detailed-0.9测试套件时,“在本地找不到模块”

  •  0
  • John J. Camilleri  · 技术社区  · 7 年前

    我有一个Haskell项目,带有一个测试套件,使用 detailed-0.9 cabal stack exitcode-stdio-1.0 测试套件似乎工作得很好。

    MWE公司

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

    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公司/我的模块.hs

    module MyModule where
    
    myFunction :: Int
    myFunction = 1
    

    测试套件/出口代码

    import MyModule (myFunction)
    import System.Exit (exitSuccess, exitFailure)
    
    main :: IO ()
    main =
      if myFunction == 1
      then exitSuccess
      else exitFailure
    

    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"
        }
      ]
    

    resolver: lts-11.22
    

    输出

    $ 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
    

    详细-0.9 有点不酷,人们似乎马上就放弃了。但它是 properly documented 而且确实与 阴谋集团 会失败的。

    0 回复  |  直到 7 年前
        1
  •  0
  •   John J. Camilleri    7 年前

    更新

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