Haskell - コードの整理とプロジェクトのビルド - QuickCheckを使ったプロパティテスト - package.yaml, dependencies
入門Haskellプログラミング (Will Kurt(著)、株式会社クイープ(監修、翻訳)、翔泳社)の UNIT6(コードの整理とプロジェクトのビルド)、LESSON 36(QuickCHeckを使ったプロパティテスト)、36.3(QuickCheckによるプロパティテスト)、 クイックチェック 36-4の解答を求めてみる。
軽量マークアップ言語
palindrome-testing/package.yaml
name: palindrome-testing
version: 0.1.0.0
github: "githubuser/palindrome-testing"
license: BSD-3-Clause
author: "Author name here"
maintainer: "example@example.com"
copyright: "2025 Author name here"
extra-source-files:
- README.md
- CHANGELOG.md
# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web
# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Please see the README on GitHub at <https://github.com/githubuser/palindrome-testing#readme>
dependencies:
- base >= 4.7 && < 5
- QuickCheck
ghc-options:
- -Wall
- -Wcompat
- -Widentities
- -Wincomplete-record-updates
- -Wincomplete-uni-patterns
- -Wmissing-export-lists
- -Wmissing-home-modules
- -Wpartial-fields
- -Wredundant-constraints
library:
source-dirs: src
executables:
palindrome-testing-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- palindrome-testing
tests:
palindrome-testing-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- palindrome-testing
palindrome-testing/palindrome-testing.cabal
cabal-version: 2.2
-- This file has been generated from package.yaml by hpack version 0.37.0.
--
-- see: https://github.com/sol/hpack
name: palindrome-testing
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/githubuser/palindrome-testing#readme>
homepage: https://github.com/githubuser/palindrome-testing#readme
bug-reports: https://github.com/githubuser/palindrome-testing/issues
author: Author name here
maintainer: example@example.com
copyright: 2025 Author name here
license: BSD-3-Clause
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
CHANGELOG.md
source-repository head
type: git
location: https://github.com/githubuser/palindrome-testing
library
exposed-modules:
Lib
other-modules:
Paths_palindrome_testing
autogen-modules:
Paths_palindrome_testing
hs-source-dirs:
src
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints
build-depends:
QuickCheck
, base >=4.7 && <5
default-language: Haskell2010
executable palindrome-testing-exe
main-is: Main.hs
other-modules:
Paths_palindrome_testing
autogen-modules:
Paths_palindrome_testing
hs-source-dirs:
app
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
build-depends:
QuickCheck
, base >=4.7 && <5
, palindrome-testing
default-language: Haskell2010
test-suite palindrome-testing-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Paths_palindrome_testing
autogen-modules:
Paths_palindrome_testing
hs-source-dirs:
test
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
build-depends:
QuickCheck
, base >=4.7 && <5
, palindrome-testing
default-language: Haskell2010
コード
palindrome-testing/test/Spec.hs
import Test.QuickCheck
import Lib(isPalindrome)
prop_reverseInvarient :: String -> Bool
prop_reverseInvarient text = isPalindrome text == isPalindrome (reverse text)
main :: IO ()
main = do
quickCheck prop_reverseInvarient
putStrLn "done!"
入出力結果(Terminal, Zsh)
% stack test
palindrome-testing-0.1.0.0: unregistering (local file changes: package.yaml
palindrome-testing.cabal)
palindrome-testing> configure (lib + exe + test)
Configuring palindrome-testing-0.1.0.0...
palindrome-testing> build (lib + exe + test) with ghc-9.8.4
Preprocessing library for palindrome-testing-0.1.0.0..
Building library for palindrome-testing-0.1.0.0..
[2 of 2] Compiling Paths_palindrome_testing [.stack-work/dist/aarch64-osx/ghc-9.8.4/build/autogen/cabal_macros.h changed]
Preprocessing executable 'palindrome-testing-exe' for palindrome-testing-0.1.0.0..
Building executable 'palindrome-testing-exe' for palindrome-testing-0.1.0.0..
[2 of 2] Compiling Paths_palindrome_testing [.stack-work/dist/aarch64-osx/ghc-9.8.4/build/palindrome-testing-exe/autogen/cabal_macros.h changed]
[3 of 3] Linking .stack-work/dist/aarch64-osx/ghc-9.8.4/build/palindrome-testing-exe/palindrome-testing-exe [Objects changed]
ld: warning: -U option is redundant when using -undefined dynamic_lookup
Preprocessing test suite 'palindrome-testing-test' for palindrome-testing-0.1.0.0..
Building test suite 'palindrome-testing-test' for palindrome-testing-0.1.0.0..
[3 of 3] Linking .stack-work/dist/aarch64-osx/ghc-9.8.4/build/palindrome-testing-test/palindrome-testing-test [Library changed]
ld: warning: -U option is redundant when using -undefined dynamic_lookup
palindrome-testing> copy/register
Installing library in /Users/.../palindrome-testing/.stack-work/install/aarch64-osx/e7436b3217cf53d6b9beeebd2bdc5dd8dcab6f8595b8bde259631442ce745f25/9.8.4/lib/aarch64-osx-ghc-9.8.4/palindrome-testing-0.1.0.0-9Jf3RZxeUAEBn9PVq0Iunw
Installing executable palindrome-testing-exe in /Users/.../palindrome-testing/.stack-work/install/aarch64-osx/e7436b3217cf53d6b9beeebd2bdc5dd8dcab6f8595b8bde259631442ce745f25/9.8.4/bin
Registering library for palindrome-testing-0.1.0.0..
palindrome-testing> test (suite: palindrome-testing-test)
+++ OK, passed 100 tests.
done!
palindrome-testing> Test suite palindrome-testing-test passed
Completed 2 action(s).
%