cabalでのtest実行
ライブラリのテストを実行しようとしたらそのままではテストが実行できませんでした。
Servant-Server
をgit clone
して、cabal test
したら依存関係ライブラリがないと指摘されます。
(root)bar:servant-server foo$ cabal test Re-configuring with test suites enabled. If this fails, please run configure manually. Resolving dependencies... Warning: solver failed to find a solution: Could not resolve dependencies: rejecting: servant-server-0.10:!test (constraint from config file, command line flag, or user target requires opposite flag selection) trying: servant-server-0.10:*test unknown package: filemanip (dependency of servant-server-0.10:*test) Dependency tree exhaustively searched. Trying configure anyway. Configuring servant-server-0.10... setup: Encountered missing dependencies: QuickCheck -any, directory -any, doctest -any, filemanip -any, hspec ==2.*, hspec-wai ==0.8.*, parsec -any, should-not-typecheck ==2.1.*, temporary -any, wai-extra -any
servant-server.cabal
を確認すると下記のように記述されています。
test-suite spec type: exitcode-stdio-1.0 ghc-options: -Wall default-language: Haskell2010 hs-source-dirs: test main-is: Spec.hs other-modules: Servant.ArbitraryMonadServerSpec Servant.Server.ErrorSpec Servant.Server.Internal.ContextSpec Servant.Server.Internal.RoutingApplicationSpec Servant.Server.RouterSpec Servant.Server.StreamingSpec Servant.Server.UsingContextSpec Servant.Server.UsingContextSpec.TestCombinators Servant.ServerSpec Servant.Utils.StaticFilesSpec build-depends: base == 4.* , base-compat , aeson , base64-bytestring , bytestring , directory , exceptions , hspec == 2.* , hspec-wai >= 0.8 && <0.9 , http-types , mtl , network >= 2.6 , parsec , QuickCheck , resourcet , safe , servant , servant-server , should-not-typecheck == 2.1.* , string-conversions , temporary , text , transformers , transformers-compat , wai , wai-extra , warp
テスト関係のライブラリを取り込むには、--enable-test
の他に--only-dependencies
が必要です。
下記が参考になりました。
cabal - installing test dependencies
(root)bar:servant-server foo$ cabal install --only-dependencies --enable-test Resolving dependencies... Notice: installing into a sandbox located at /Users/foo/work03/webapp/servant03/src_servant/servant/servant-server/.cabal-sandbox Downloading call-stack-0.1.0... Downloading code-page-0.1.3... Configuring ghc-paths-0.1.0.9... Configuring temporary-1.2.0.4... Configuring tf-random-0.5... Configuring code-page-0.1.3... Downloading filemanip-0.3.6.3... Downloading hspec-discover-2.4.3... Downloading setenv-0.1.1.3... Downloading syb-0.7... Building temporary-1.2.0.4... Building tf-random-0.5... Building code-page-0.1.3... Installed code-page-0.1.3 Configuring call-stack-0.1.0... Building call-stack-0.1.0... Building ghc-paths-0.1.0.9... Configuring filemanip-0.3.6.3... Installed temporary-1.2.0.4 Configuring setenv-0.1.1.3... Installed ghc-paths-0.1.0.9 Building filemanip-0.3.6.3... Building setenv-0.1.1.3... Configuring hspec-discover-2.4.3... Installed call-stack-0.1.0 Downloading HUnit-1.6.0.0... Building hspec-discover-2.4.3... Configuring syb-0.7... Installed setenv-0.1.1.3 Building syb-0.7... Configuring HUnit-1.6.0.0... Installed tf-random-0.5 Building HUnit-1.6.0.0... Configuring QuickCheck-2.9.2... Installed filemanip-0.3.6.3 Installed hspec-discover-2.4.3 Building QuickCheck-2.9.2... Installed HUnit-1.6.0.0 Downloading hspec-expectations-0.8.2... Downloading should-not-typecheck-2.1.0... Configuring hspec-expectations-0.8.2... Installed syb-0.7 Downloading doctest-0.11.2... Configuring should-not-typecheck-2.1.0... Configuring doctest-0.11.2... Building hspec-expectations-0.8.2... Building should-not-typecheck-2.1.0... Building doctest-0.11.2... Installed should-not-typecheck-2.1.0 Installed hspec-expectations-0.8.2 Installed doctest-0.11.2 Installed QuickCheck-2.9.2 Downloading quickcheck-io-0.1.4... Configuring quickcheck-io-0.1.4... Building quickcheck-io-0.1.4... Installed quickcheck-io-0.1.4 Downloading hspec-core-2.4.3... Configuring hspec-core-2.4.3... Building hspec-core-2.4.3... Installed hspec-core-2.4.3 Downloading hspec-2.4.3... Downloading hspec-wai-0.8.0... Configuring hspec-2.4.3... Configuring hspec-wai-0.8.0... Building hspec-2.4.3... Building hspec-wai-0.8.0... Installed hspec-2.4.3 Installed hspec-wai-0.8.0 Updating documentation index /Users/foo/work03/webapp/servant03/src_servant/servant/servant-server/.cabal-sandbox/share/doc/x86_64-osx-ghc-8.0.1/index.html
これでcabal test
でテストが実行されます。
(root)bar:servant-server foo$ cabal test Package has never been configured. Configuring with default flags. If this fails, please run configure manually. Resolving dependencies... [1 of 1] Compiling Main ( dist/setup/setup.hs, dist/setup/Main.o ) Linking ./dist/setup/setup ... Configuring servant-server-0.10... Preprocessing library servant-server-0.10... [ 1 of 11] Compiling Servant.Server.Internal.ServantErr ( src/Servant/Server/Internal/ServantErr.hs, dist/build/Servant/Server/Internal/ServantErr.o ) [ 2 of 11] Compiling Servant.Server.Internal.Handler ( src/Servant/Server/Internal/Handler.hs, dist/build/Servant/Server/Internal/Handler.o ) [ 3 of 11] Compiling Servant.Server.Internal.RoutingApplication ( src/Servant/Server/Internal/RoutingApplication.hs, dist/build/Servant/Server/Internal/RoutingApplication.o ) [ 4 of 11] Compiling Servant.Server.Internal.Router ( src/Servant/Server/Internal/Router.hs, dist/build/Servant/Server/Internal/Router.o ) [ 5 of 11] Compiling Servant.Server.Internal.Context ( src/Servant/Server/Internal/Context.hs, dist/build/Servant/Server/Internal/Context.o ) [ 6 of 11] Compiling Servant.Server.Internal.BasicAuth ( src/Servant/Server/Internal/BasicAuth.hs, dist/build/Servant/Server/Internal/BasicAuth.o ) [ 7 of 11] Compiling Servant.Server.Internal ( src/Servant/Server/Internal.hs, dist/build/Servant/Server/Internal.o ) [ 8 of 11] Compiling Servant.Server ( src/Servant/Server.hs, dist/build/Servant/Server.o ) [ 9 of 11] Compiling Servant.Utils.StaticFiles ( src/Servant/Utils/StaticFiles.hs, dist/build/Servant/Utils/StaticFiles.o ) [10 of 11] Compiling Servant ( src/Servant.hs, dist/build/Servant.o ) [11 of 11] Compiling Servant.Server.Experimental.Auth ( src/Servant/Server/Experimental/Auth.hs, dist/build/Servant/Server/Experimental/Auth.o ) [ 1 of 11] Compiling Servant.Server.Internal.ServantErr ( src/Servant/Server/Internal/ServantErr.hs, dist/build/Servant/Server/Internal/ServantErr.p_o ) [ 2 of 11] Compiling Servant.Server.Internal.Handler ( src/Servant/Server/Internal/Handler.hs, dist/build/Servant/Server/Internal/Handler.p_o ) [ 3 of 11] Compiling Servant.Server.Internal.RoutingApplication ( src/Servant/Server/Internal/RoutingApplication.hs, dist/build/Servant/Server/Internal/RoutingApplication.p_o ) [ 4 of 11] Compiling Servant.Server.Internal.Router ( src/Servant/Server/Internal/Router.hs, dist/build/Servant/Server/Internal/Router.p_o ) [ 5 of 11] Compiling Servant.Server.Internal.Context ( src/Servant/Server/Internal/Context.hs, dist/build/Servant/Server/Internal/Context.p_o ) [ 6 of 11] Compiling Servant.Server.Internal.BasicAuth ( src/Servant/Server/Internal/BasicAuth.hs, dist/build/Servant/Server/Internal/BasicAuth.p_o ) [ 7 of 11] Compiling Servant.Server.Internal ( src/Servant/Server/Internal.hs, dist/build/Servant/Server/Internal.p_o ) [ 8 of 11] Compiling Servant.Server ( src/Servant/Server.hs, dist/build/Servant/Server.p_o ) [ 9 of 11] Compiling Servant.Utils.StaticFiles ( src/Servant/Utils/StaticFiles.hs, dist/build/Servant/Utils/StaticFiles.p_o ) [10 of 11] Compiling Servant ( src/Servant.hs, dist/build/Servant.p_o ) [11 of 11] Compiling Servant.Server.Experimental.Auth ( src/Servant/Server/Experimental/Auth.hs, dist/build/Servant/Server/Experimental/Auth.p_o ) Preprocessing test suite 'spec' for servant-server-0.10... [ 1 of 11] Compiling Servant.Server.UsingContextSpec.TestCombinators ( test/Servant/Server/UsingContextSpec/TestCombinators.hs, dist/build/spec/spec-tmp/Servant/Server/UsingContextSpec/TestCombinators.o ) [ 2 of 11] Compiling Servant.ServerSpec ( test/Servant/ServerSpec.hs, dist/build/spec/spec-tmp/Servant/ServerSpec.o ) [ 3 of 11] Compiling Servant.Utils.StaticFilesSpec ( test/Servant/Utils/StaticFilesSpec.hs, dist/build/spec/spec-tmp/Servant/Utils/StaticFilesSpec.o ) [ 4 of 11] Compiling Servant.Server.UsingContextSpec ( test/Servant/Server/UsingContextSpec.hs, dist/build/spec/spec-tmp/Servant/Server/UsingContextSpec.o ) [ 5 of 11] Compiling Servant.Server.StreamingSpec ( test/Servant/Server/StreamingSpec.hs, dist/build/spec/spec-tmp/Servant/Server/StreamingSpec.o ) [ 6 of 11] Compiling Servant.Server.RouterSpec ( test/Servant/Server/RouterSpec.hs, dist/build/spec/spec-tmp/Servant/Server/RouterSpec.o ) [ 7 of 11] Compiling Servant.Server.Internal.RoutingApplicationSpec ( test/Servant/Server/Internal/RoutingApplicationSpec.hs, dist/build/spec/spec-tmp/Servant/Server/Internal/RoutingApplicationSpec.o ) [ 8 of 11] Compiling Servant.Server.Internal.ContextSpec ( test/Servant/Server/Internal/ContextSpec.hs, dist/build/spec/spec-tmp/Servant/Server/Internal/ContextSpec.o ) test/Servant/Server/Internal/ContextSpec.hs:25:15: warning: [-Wdeferred-type-errors] • No instance for (HasContextEntry '[] Bool) arising from a use of ‘getContextEntry’ • In the expression: getContextEntry cxt :: Bool In an equation for ‘x’: x = getContextEntry cxt :: Bool In the second argument of ‘($)’, namely ‘do { let cxt = 'a' :. EmptyContext x = ...; shouldNotTypecheck x }’ test/Servant/Server/Internal/ContextSpec.hs:57:15: warning: [-Wdeferred-type-errors] • No instance for (HasContextEntry '[] (NamedContext "sub" '[Int])) arising from a use of ‘descendIntoNamedContext’ • In the expression: descendIntoNamedContext (Proxy :: Proxy "sub") cxt :: Context '[Int] In an equation for ‘x’: x = descendIntoNamedContext (Proxy :: Proxy "sub") cxt :: Context '[Int] In the second argument of ‘($)’, namely ‘do { let x = ...; shouldNotTypecheck (show x) }’ test/Servant/Server/Internal/ContextSpec.hs:61:15: warning: [-Wdeferred-type-errors] • No instance for (HasContextEntry '[] (NamedContext "foo" '[Char])) arising from a use of ‘descendIntoNamedContext’ • In the expression: descendIntoNamedContext (Proxy :: Proxy "foo") cxt :: Context '[Char] In an equation for ‘x’: x = descendIntoNamedContext (Proxy :: Proxy "foo") cxt :: Context '[Char] In the second argument of ‘($)’, namely ‘do { let x = ...; shouldNotTypecheck (show x) }’ [ 9 of 11] Compiling Servant.Server.ErrorSpec ( test/Servant/Server/ErrorSpec.hs, dist/build/spec/spec-tmp/Servant/Server/ErrorSpec.o ) [10 of 11] Compiling Servant.ArbitraryMonadServerSpec ( test/Servant/ArbitraryMonadServerSpec.hs, dist/build/spec/spec-tmp/Servant/ArbitraryMonadServerSpec.o ) [11 of 11] Compiling Main ( test/Spec.hs, dist/build/spec/spec-tmp/Main.o ) Linking dist/build/spec/spec ... Preprocessing test suite 'doctests' for servant-server-0.10... [1 of 2] Compiling Build_doctests ( dist/build/autogen/Build_doctests.hs, dist/build/doctests/doctests-tmp/Build_doctests.o ) [2 of 2] Compiling Main ( dist/build/doctests/doctests-tmp/test/doctests.hs, dist/build/doctests/doctests-tmp/Main.o ) Linking dist/build/doctests/doctests ... Running 2 test suites... Test suite spec: RUNNING... Test suite spec: PASS Test suite logged to: dist/test/servant-server-0.10-spec.log Test suite doctests: RUNNING... Test suite doctests: PASS Test suite logged to: dist/test/servant-server-0.10-doctests.log 2 of 2 test suites (2 of 2 test cases) passed. (root)bar:servant-server foo$
結果はログdist/test/servant-server-0.10-doctests.log
に出力されます。