我正在关注您构建项目haq
的教程How to Write a Haskell Program。
每当我尝试运行cabal test
时,我都会收到以下错误代码:
<command line>: cannot satisfy -package-id haq-0.1.0.0-inplace
(use -v for more information)
cabal: Error: some packages failed to install:
haq-0.1.0.0 failed during the building phase. The exception was:
ExitFailure 1
请注意,它无法构建的包本身(至少我认为这个错误意味着什么)。
$ cabal install --enable-tests
Resolving dependencies...
Configuring haq-0.1.0.0...
Building haq-0.1.0.0...
Failed to install haq-0.1.0.0
Build log ( /home/user/.cabal/logs/haq-0.1.0.0.log ):
Configuring haq-0.1.0.0...
Warning: The 'license-file' field refers to the file 'LICENSE' which does not
exist.
Building haq-0.1.0.0...
Preprocessing executable 'haq' for haq-0.1.0.0...
[1 of 1] Compiling Main ( Haq.hs, dist/build/haq/haq-tmp/Main.o )
Linking dist/build/haq/haq ...
Preprocessing test suite 'tests' for haq-0.1.0.0...
<command line>: cannot satisfy -package-id haq-0.1.0.0-inplace
(use -v for more information)
cabal: Error: some packages failed to install:
haq-0.1.0.0 failed during the building phase. The exception was:
ExitFailure 1
.
├── .cabal-sandbox
├── cabal.sandbox.config
├── dist
├── haq.cabal
├── Haq.hs
├── HSpecTests.hs
└── Setup.hs
--
-- Copyright (c) 2006 Don Stewart - http://www.cse.unsw.edu.au/~dons/
-- GPL version 2 or later (see http://www.gnu.org/copyleft/gpl.html)
--
import System.Environment
-- | 'main' runs the main program
main :: IO ()
main = getArgs >>= print . haqify . head
haqify s = "Haq! " ++ s
-- Initial haq.cabal generated by cabal init. For further documentation,
-- see http://haskell.org/cabal/users-guide/
name: haq
version: 0.1.0.0
-- synopsis:
-- description:
-- license:
license-file: LICENSE
author: First Last
maintainer: first.last@gmail.com
-- copyright:
-- category:
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10
executable haq
main-is: Haq.hs
-- other-modules:
-- other-extensions:
build-depends: base >=4.8 && <4.9
-- hs-source-dirs:
default-language: Haskell2010
test-suite tests
ghc-options: -Wall
default-extensions: OverloadedStrings
type: exitcode-stdio-1.0
main-is: HSpecTests.hs
build-depends: base,
haq,
hspec >= 1.8
default-language: Haskell2010
module Main where
import Haq
import Test.Hspec
main :: IO ()
main = hspec $ do
describe "Validate haqify function" $ do
it "haqify is supposed to prefix Haq! to things" $ do
haqify "me" `shouldBe` "Haq! me"
答案 0 :(得分:3)
更新
运行cabal test
时出现错误。
问题是您的测试套件依赖于库haq
,但cabal文件不会声明库组件。它只声明一个可执行文件。
修复:
Haq.hs
重命名为App.hs
。适当更新cabal文件。使用以下内容创建一个新文件'Haq.hs`:
module Haq (haqify) where
haqify :: String -> String
haqify s = "Haqify! " ++ s
将此节添加到cabal文件中:
library
build-depends: base >= 4.8 && < 4.9
exposed-modules: Haq
运行cabal build
或cabal test
原始答案
我修复cabal build
中的缩进问题后,我能够Haq.hs
您的项目:
main
haqify