Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

Commit

Permalink
Add a selftest for Packages
Browse files Browse the repository at this point in the history
  • Loading branch information
snowleopard committed Oct 30, 2016
1 parent 223d161 commit e2871fc
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions src/Rules/Selftest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import Development.Shake
import Test.QuickCheck

import Base
import Builder
import Expression
import Oracles.ModuleFiles
import Settings
import Settings.Builders.Ar
import UserSettings
import Way

instance Arbitrary Way where
arbitrary = wayFromUnits <$> arbitrary
Expand All @@ -25,11 +25,12 @@ selftestRules :: Rules ()
selftestRules =
"selftest" ~> do
testBuilder
testWay
testChunksOfSize
testLookupAll
testMatchVersionedFilePath
testModuleName
testLookupAll
testPackages
testWay

testBuilder :: Action ()
testBuilder = do
Expand All @@ -39,11 +40,6 @@ testBuilder = do
trackedArgument (Make undefined) prefix == False &&
trackedArgument (Make undefined) ("-j" ++ show (n :: Int)) == False

testWay :: Action ()
testWay = do
putBuild $ "==== Read Way, Show Way"
test $ \(x :: Way) -> read (show x) == x

testChunksOfSize :: Action ()
testChunksOfSize = do
putBuild $ "==== chunksOfSize"
Expand All @@ -53,6 +49,20 @@ testChunksOfSize = do
let res = chunksOfSize n xs
in concat res == xs && all (\r -> length r == 1 || length (concat r) <= n) res

testLookupAll :: Action ()
testLookupAll = do
putBuild $ "==== lookupAll"
test $ lookupAll ["b" , "c" ] [("a", 1), ("c", 3), ("d", 4)]
== [Nothing, Just (3 :: Int)]
test $ forAll dicts $ \dict -> forAll extras $ \extra ->
let items = sort $ map fst dict ++ extra
in lookupAll items (sort dict) == map (flip lookup dict) items
where
dicts :: Gen [(Int, Int)]
dicts = nubBy ((==) `on` fst) <$> vector 20
extras :: Gen [Int]
extras = vector 20

testMatchVersionedFilePath :: Action ()
testMatchVersionedFilePath = do
putBuild $ "==== matchVersionedFilePath"
Expand Down Expand Up @@ -82,16 +92,15 @@ testModuleName = do
where
names = intercalate "." <$> listOf1 (listOf1 $ elements "abcABC123_'")

testLookupAll :: Action ()
testLookupAll = do
putBuild $ "==== lookupAll"
test $ lookupAll ["b" , "c" ] [("a", 1), ("c", 3), ("d", 4)]
== [Nothing, Just (3 :: Int)]
test $ forAll dicts $ \dict -> forAll extras $ \extra ->
let items = sort $ map fst dict ++ extra
in lookupAll items (sort dict) == map (flip lookup dict) items
where
dicts :: Gen [(Int, Int)]
dicts = nubBy ((==) `on` fst) <$> vector 20
extras :: Gen [Int]
extras = vector 20
testPackages :: Action ()
testPackages = do
putBuild $ "==== Packages, interpretInContext"
forM_ [Stage0 ..] $ \stage -> do
pkgs <- stagePackages stage
test $ pkgs == nubOrd pkgs

testWay :: Action ()
testWay = do
putBuild $ "==== Read Way, Show Way"
test $ \(x :: Way) -> read (show x) == x

1 comment on commit e2871fc

@snowleopard
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #197.

Please sign in to comment.