From b2a53e06f43162d4b23f7d16740d6e55275c1c1b Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 17 Apr 2014 21:02:16 -0400 Subject: [PATCH] Bump the version and switch to tasty (from test-framework). Clean up the makefile a little. --- haeredes.cabal | 18 ++++++-------- makefile | 58 ++++++++++++++++++++++++++++----------------- src/DNS.hs | 60 +++++++++++++++++++++++++++-------------------- test/TestSuite.hs | 18 +++++--------- 4 files changed, 83 insertions(+), 71 deletions(-) diff --git a/haeredes.cabal b/haeredes.cabal index e171258..9961eed 100644 --- a/haeredes.cabal +++ b/haeredes.cabal @@ -1,5 +1,5 @@ name: haeredes -version: 0.3.0 +version: 0.4.0 cabal-version: >= 1.8 author: Michael Orlitzky maintainer: Michael Orlitzky @@ -88,11 +88,9 @@ executable haeredes MissingH == 1.2.*, parallel-io == 0.3.*, -- Test deps - HUnit == 1.2.*, - QuickCheck == 2.*, - test-framework == 0.8.*, - test-framework-hunit == 0.3.*, - test-framework-quickcheck2 == 0.3.* + tasty == 0.8.*, + tasty-hunit == 0.8.*, + tasty-quickcheck == 0.8.* main-is: Main.hs @@ -135,11 +133,9 @@ test-suite testsuite MissingH == 1.2.*, parallel-io == 0.3.*, -- Test deps - HUnit == 1.2.*, - QuickCheck == 2.*, - test-framework == 0.8.*, - test-framework-hunit == 0.3.*, - test-framework-quickcheck2 == 0.3.* + tasty == 0.8.*, + tasty-hunit == 0.8.*, + tasty-quickcheck == 0.8.* -- It's not entirely clear to me why I have to reproduce all of this. ghc-options: diff --git a/makefile b/makefile index 35241be..b64a42d 100644 --- a/makefile +++ b/makefile @@ -1,35 +1,47 @@ -BIN = dist/build/haeredes/haeredes -TESTSUITE_BIN = dist/build/testsuite/testsuite -DOCTESTS_BIN = dist/build/doctests/doctests +PN = haeredes +BIN = dist/build/$(PN)/$(PN) +SRCS = $(shell find src/ -type f -name '*.hs') -.PHONY : dist doc test +.PHONY : dist hlint -$(BIN): src/*.hs - runghc Setup.hs clean +$(BIN): $(PN).cabal $(SRCS) runghc Setup.hs configure --user runghc Setup.hs build -$(TESTSUITE_BIN): src/*.hs test/TestSuite.hs - runghc Setup.hs configure --user --enable-tests +doc: $(PN).cabal $(SRCS) + runghc Setup.hs hscolour --all + runghc Setup.hs haddock --all \ + --hyperlink-source \ + --haddock-options="--ignore-all-exports" + + +# +# Tests +# +TESTSUITE_BIN = dist/build/testsuite/testsuite +DOCTESTS_BIN = dist/build/doctests/doctests +TEST_SRCS := $(shell find test/ -type f -name '*.hs') + +$(TESTSUITE_BIN): $(PN).cabal $(SRCS) $(TEST_SRCS) + runghc Setup.hs configure --user --enable-tests --prefix=/ runghc Setup.hs build -$(DOCTESTS_BIN): src/*.hs test/Doctests.hs + +$(DOCTESTS_BIN): $(PN).cabal $(SRCS) $(TEST_SRCS) runghc Setup.hs configure --user --enable-tests runghc Setup.hs build -clean: - runghc Setup.hs clean - rm -f src/*.hi - rm -f src/*.o - test: $(BIN) $(TESTSUITE_BIN) $(DOCTESTS_BIN) runghc Setup.hs test -doc: - runghc Setup.hs hscolour --executables - runghc Setup.hs haddock --internal \ - --executables \ - --hyperlink-source + +# +# Misc +# + +dist: + runghc Setup.hs configure + TAR_OPTIONS="--format=ustar" runghc Setup.hs sdist hlint: hlint --ignore="Use camelCase" \ @@ -37,6 +49,8 @@ hlint: --color \ src -dist: - runghc Setup.hs configure - runghc Setup.hs sdist +clean: + runghc Setup.hs clean + find ./ -name '*.prof' -delete + find ./ -name '*.o' -delete + find ./ -name '*.hi' -delete diff --git a/src/DNS.hs b/src/DNS.hs index 34a8bd1..497bf31 100644 --- a/src/DNS.hs +++ b/src/DNS.hs @@ -29,10 +29,9 @@ import Network.DNS ( lookupNSAuth, makeResolvSeed, withResolver ) -import Test.Framework (Test, testGroup) -import Test.Framework.Providers.HUnit (testCase) -import Test.Framework.Providers.QuickCheck2 (testProperty) -import Test.HUnit (assertEqual) +import Test.Tasty ( TestTree, testGroup ) +import Test.Tasty.HUnit ( (@?=), testCase ) +import Test.Tasty.QuickCheck ( testProperty ) import Text.Read (readMaybe) type LookupResult = (Domain, Either DNSError [Domain]) @@ -129,6 +128,7 @@ normalize = normalize_case . normalize_root -- | Normalize the given name by appending a trailing dot (the DNS -- root) if necessary. +-- normalize_root :: Domain -> Domain normalize_root d | BS.null d = BS.pack "." @@ -139,52 +139,60 @@ normalize_root d -- | Normalize the given name by lowercasing it. +-- normalize_case :: Domain -> Domain normalize_case = BS.map toLower -test_normalize_case :: Test + +-- * Tests + +test_normalize_case :: TestTree test_normalize_case = - testCase desc $ - assertEqual desc expected actual + testCase desc $ actual @?= expected where desc = "normalize_case lowercases DNS names" expected = BS.pack "example.com" actual = normalize_case $ BS.pack "ExAmPlE.COM" -prop_normalize_case_idempotent :: String -> Bool -prop_normalize_case_idempotent s = - (normalize_case . normalize_case) bs == normalize_case bs +prop_normalize_case_idempotent :: TestTree +prop_normalize_case_idempotent = + testProperty desc $ prop where - bs = BS.pack s + desc = "normalize_case is idempotent" + + prop :: String -> Bool + prop s = (normalize_case . normalize_case) bs == normalize_case bs + where + bs = BS.pack s -test_normalize_root_adds_dot :: Test +test_normalize_root_adds_dot :: TestTree test_normalize_root_adds_dot = - testCase desc $ - assertEqual desc expected actual + testCase desc $ actual @?= expected where desc = "normalize_root adds a trailing dot" expected = BS.pack "example.com." actual = normalize_root $ BS.pack "example.com" -prop_normalize_root_idempotent :: String -> Bool -prop_normalize_root_idempotent s = - (normalize_root . normalize_root) bs == normalize_root bs +prop_normalize_root_idempotent :: TestTree +prop_normalize_root_idempotent = + testProperty desc prop where - bs = BS.pack s + desc = "normalize_root is idempotent" + + prop :: String -> Bool + prop s = (normalize_root . normalize_root) bs == normalize_root bs + where + bs = BS.pack s -dns_tests :: Test +dns_tests :: TestTree dns_tests = testGroup "DNS Tests" [ test_normalize_case, test_normalize_root_adds_dot ] -dns_properties :: Test +dns_properties :: TestTree dns_properties = testGroup "DNS Properties" [ - testProperty - "normalize_case is idempotent" - prop_normalize_case_idempotent, - testProperty - "normalize_root is idempotent" - prop_normalize_root_idempotent ] + prop_normalize_case_idempotent, + prop_normalize_root_idempotent ] diff --git a/test/TestSuite.hs b/test/TestSuite.hs index 7c553d2..91e044c 100644 --- a/test/TestSuite.hs +++ b/test/TestSuite.hs @@ -1,18 +1,12 @@ module Main where -import Data.Monoid (mempty) -import Test.Framework ( - Test, - defaultMainWithOpts ) -import Test.Framework.Runners.Options ( RunnerOptions ) +import Test.Tasty ( TestTree, defaultMain, testGroup ) -import DNS (dns_properties, dns_tests) +import DNS ( dns_properties, dns_tests ) -main :: IO () -main = do - let empty_options = mempty :: RunnerOptions - defaultMainWithOpts tests empty_options +tests :: TestTree +tests = testGroup "All tests" [ dns_properties, dns_tests ] -tests :: [Test] -tests = [ dns_properties, dns_tests ] +main :: IO () +main = defaultMain tests -- 2.43.2