我已经设置了堆栈项目但是当我运行stack test
时,我没有得到任何输出或错误。但是,如果我直接运行测试文件runhaskell Tests.hs
,我会得到我想要的结果。
c:\storeCredit>stack test
storeCredit-0.1.0.0: test (suite: storeCredit-test)
c:\storeCredit>
这是我的.cabal文件:
name: storeCredit
version: 0.1.0.0
build-type: Simple
library
hs-source-dirs: src
exposed-modules: StoreCredit
build-depends: base >= 4.7 && < 5
, split
, containers
default-language: Haskell2010
test-suite storeCredit-test
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Tests.hs
build-depends: base
, hspec
, split
, directory
, filepath
, containers
, storeCredit
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010
从stack test -v
c:\storeCredit>stack test -v
Version 1.3.2, Git revision 3f675146590da4f3edf768b89355f798229da2a5 x86_64 hpack-0.15.0
2017-08-07 16:15:23.708484: [debug] Checking for project config at: C:\storeCredit\stack.yaml
@(Stack\Config.hs:863:9)
2017-08-07 16:15:23.709485: [debug] Loading project config file stack.yaml
@(Stack\Config.hs:881:13)
2017-08-07 16:15:23.728491: [debug] Trying to decode C:\sr\build-plan-cache\x86_64-windows\lts-9.0.cache
@(Data\Store\VersionTagged.hs:68:5)
2017-08-07 16:15:23.745500: [debug] Success decoding C:\sr\build-plan-cache\x86_64-windows\lts-9.0.cache
@(Data\Store\VersionTagged.hs:72:13)
2017-08-07 16:15:23.762504: [debug] Using standard GHC build
@(Stack\Setup.hs:597:9)
2017-08-07 16:15:23.769506: [debug] Getting global package database location
@(Stack\GhcPkg.hs:55:5)
2017-08-07 16:15:23.773514: [debug] Asking GHC for its version
@(Stack\Setup\Installed.hs:103:13)
2017-08-07 16:15:23.774515: [debug] Getting Cabal package version
@(Stack\GhcPkg.hs:189:5)
2017-08-07 16:15:23.786519: [debug] Run process: C:\Users\Matthias\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc-pkg.EXE --no-user-package-db list --global
@(System\Process\Read.hs:306:3)
2017-08-07 16:15:23.788791: [debug] Run process: C:\Users\Matthias\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc.EXE --numeric-version
@(System\Process\Read.hs:306:3)
2017-08-07 16:15:23.800797: [debug] Run process: C:\Users\Matthias\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc-pkg.EXE --no-user-package-db field --simple-output Cabal version
@(System\Process\Read.hs:306:3)
2017-08-07 16:15:23.839811: [debug] Process finished in [92m48ms[0m: C:\Users\Matthias\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc.EXE --numeric-version
@(System\Process\Read.hs:306:3)
2017-08-07 16:15:23.888835: [debug] Process finished in [92m100ms[0m: C:\Users\Matthias\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc-pkg.EXE --no-user-package-db list --global
@(System\Process\Read.hs:306:3)
2017-08-07 16:15:23.919846: [debug] Process finished in [92m109ms[0m: C:\Users\Matthias\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc-pkg.EXE --no-user-package-db field --simple-output Cabal version
@(System\Process\Read.hs:306:3)
2017-08-07 16:15:23.921846: [debug] Resolving package entries
@(Stack\Setup.hs:252:5)
2017-08-07 16:15:23.924848: [debug] Starting to execute command inside EnvConfig
@(Stack\Runners.hs:163:18)
2017-08-07 16:15:23.925849: [debug] Parsing the cabal files of the local packages
@(Stack\Build\Source.hs:298:5)
2017-08-07 16:15:23.929851: [debug] Parsing the targets
@(Stack\Build\Source.hs:235:5)
2017-08-07 16:15:23.945857: [debug] Start: getPackageFiles C:\storeCredit\storeCredit.cabal
@(Stack\Package.hs:250:21)
2017-08-07 16:15:23.954862: [debug] Finished in 7ms: getPackageFiles C:\storeCredit\storeCredit.cabal
@(Stack\Package.hs:250:21)
2017-08-07 16:15:23.965864: [debug] Finding out which packages are already installed
@(Stack\Build\Installed.hs:68:5)
2017-08-07 16:15:23.969865: [debug] Run process: C:\Users\Matthias\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc-pkg.EXE --global --no-user-package-db dump --expand-pkgroot
@(System\Process\Read.hs:306:3)
2017-08-07 16:15:24.056905: [debug] Process finished in [92m86ms[0m: C:\Users\Matthias\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc-pkg.EXE --global --no-user-package-db dump --expand-pkgroot
@(System\Process\Read.hs:306:3)
2017-08-07 16:15:24.085421: [debug] Ignoring package xhtml due to wanting version 3000.2.2 instead of 3000.2.1
@(Stack\Build\Installed.hs:191:5)
2017-08-07 16:15:24.086923: [debug] Ignoring package haskeline due to wanting version 0.7.4.0 instead of 0.7.3.0
@(Stack\Build\Installed.hs:191:5)
2017-08-07 16:15:24.089927: [debug] Run process: C:\Users\Matthias\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc-pkg.EXE --user --no-user-package-db --package-db C:\sr\snapshots\62cfb14b\pkgdb dump --expand-pkgroot
@(System\Process\Read.hs:306:3)
2017-08-07 16:15:24.175466: [debug] Process finished in [92m84ms[0m: C:\Users\Matthias\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc-pkg.EXE --user --no-user-package-db --package-db C:\sr\snapshots\62cfb14b\pkgdb dump --expand-pkgroot
@(System\Process\Read.hs:306:3)
2017-08-07 16:15:24.187961: [debug] Run process: C:\Users\Matthias\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc-pkg.EXE --user --no-user-package-db --package-db C:\storeCredit\.stack-work\install\6c953ab2\pkgdb dump --expand-pkgroot
@(System\Process\Read.hs:306:3)
2017-08-07 16:15:24.255986: [debug] Process finished in [92m65ms[0m: C:\Users\Matthias\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc-pkg.EXE --user --no-user-package-db --package-db C:\storeCredit\.stack-work\install\6c953ab2\pkgdb dump --expand-pkgroot
@(System\Process\Read.hs:306:3)
2017-08-07 16:15:24.264989: [debug] Constructing the build plan
@(Stack\Build\ConstructPlan.hs:159:5)
2017-08-07 16:15:24.275500: [debug] Checking if we are going to build multiple executables with the same name
@(Stack\Build.hs:196:5)
2017-08-07 16:15:24.287968: [debug] Executing the build plan
@(Stack\Build\Execute.hs:454:5)
2017-08-07 16:15:24.291968: [debug] Getting global package database location
@(Stack\GhcPkg.hs:55:5)
2017-08-07 16:15:24.292968: [debug] Run process: C:\Users\Matthias\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc-pkg.EXE --no-user-package-db list --global
@(System\Process\Read.hs:306:3)
2017-08-07 16:15:24.363995: [debug] Process finished in [92m68ms[0m: C:\Users\Matthias\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc-pkg.EXE --no-user-package-db list --global
@(System\Process\Read.hs:306:3)
2017-08-07 16:15:24.377005: [info] storeCredit-0.1.0.0: test (suite: storeCredit-test)
@(Stack\Build\Execute.hs:826:23)
2017-08-07 16:15:24.380008: [debug] Creating process: C:\storeCredit\.stack-work\dist\ca59d0ab\build\storeCredit-test\storeCredit-test.exe
@(System\Process\Run.hs:139:5)
2017-08-07 16:15:24.407025: [info]
@(Stack\Build\Execute.hs:1449:52)
解决:
问题是在我的Tests.hs文件中,我有一个函数可以获取目录中的文件并将其用作输入和输出进行测试。它包含以下行:
dir <- getDirectoryContents =<< getCurrentDirectory
如果使用与Test.hs文件相同的目录(即\test
)运行,这显然很好。这就是runhaskell Test.hs
有效的原因。但是,stack test
从父文件夹运行到test
,我不得不更改正在读取的路径。
改为:
dir <- getDirectoryContents =<< ((++ "\\test") <$> getCurrentDirectory)
修复了问题