[commit: ghc] wip/nfs-locking: Refactor Selftest, add more tests for matchVersionedFilePath. (8ae1c56)

git at git.haskell.org git at git.haskell.org
Fri Oct 27 00:21:33 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/nfs-locking
Link       : http://ghc.haskell.org/trac/ghc/changeset/8ae1c564d861871d9b587d3525c704e3625a4864/ghc

>---------------------------------------------------------------

commit 8ae1c564d861871d9b587d3525c704e3625a4864
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date:   Tue Feb 16 23:10:12 2016 +0000

    Refactor Selftest, add more tests for matchVersionedFilePath.


>---------------------------------------------------------------

8ae1c564d861871d9b587d3525c704e3625a4864
 src/Rules/Selftest.hs | 54 ++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 36 insertions(+), 18 deletions(-)

diff --git a/src/Rules/Selftest.hs b/src/Rules/Selftest.hs
index 5fafda5..70a4023 100644
--- a/src/Rules/Selftest.hs
+++ b/src/Rules/Selftest.hs
@@ -15,24 +15,42 @@ instance Arbitrary Way where
 instance Arbitrary WayUnit where
     arbitrary = arbitraryBoundedEnum
 
+test :: Testable a => a -> Action ()
+test = liftIO . quickCheck
+
 selftestRules :: Rules ()
 selftestRules =
     "selftest" ~> do
-        test $ \(x :: Way) -> read (show x) == x
-        test $ \n xs ->
-            let res = chunksOfSize n xs
-            in concat res == xs && all (\r -> length r == 1 || length (concat r) <= n) res
-        test $ chunksOfSize 3 ["a","b","c","defg","hi","jk"] == [["a","b","c"],["defg"],["hi"],["jk"]]
-
-        test $ matchVersionedFilePath "foo/bar"  ".a" "foo/bar.a"     == True
-        test $ matchVersionedFilePath "foo/bar"  ".a" "foo\\bar.a"    == True
-        test $ matchVersionedFilePath "foo/bar"  "a"  "foo/bar.a"     == True
-        test $ matchVersionedFilePath "foo/bar"  ""   "foo/bar.a"     == False
-        test $ matchVersionedFilePath "foo/bar"  "a"  "foo/bar-0.1.a" == True
-        test $ matchVersionedFilePath "foo/bar-" "a"  "foo/bar-0.1.a" == True
-        test $ matchVersionedFilePath "foo/bar/" "a"  "foo/bar-0.1.a" == False
-
-        -- TODO: add automated tests for matchVersionedFilePath too
-
-test :: Testable a => a -> Action ()
-test = liftIO . quickCheck
+        testWays
+        testChunksOfSize
+        testMatchVersionedFilePath
+
+testWays :: Action ()
+testWays = do
+    putBuild $ "==== Read Way, Show Way"
+    test $ \(x :: Way) -> read (show x) == x
+
+testChunksOfSize :: Action ()
+testChunksOfSize = do
+    putBuild $ "==== chunksOfSize"
+    test $ chunksOfSize 3 [  "a", "b", "c" ,  "defg" ,  "hi" ,  "jk"  ]
+                       == [ ["a", "b", "c"], ["defg"], ["hi"], ["jk"] ]
+    test $ \n xs ->
+        let res = chunksOfSize n xs
+        in concat res == xs && all (\r -> length r == 1 || length (concat r) <= n) res
+
+testMatchVersionedFilePath :: Action ()
+testMatchVersionedFilePath = do
+    putBuild $ "==== matchVersionedFilePath"
+    test $ matchVersionedFilePath "foo/bar"  ".a" "foo/bar.a"     == True
+    test $ matchVersionedFilePath "foo/bar"  ".a" "foo\\bar.a"    == False
+    test $ matchVersionedFilePath "foo/bar"  "a"  "foo/bar.a"     == True
+    test $ matchVersionedFilePath "foo/bar"  ""   "foo/bar.a"     == False
+    test $ matchVersionedFilePath "foo/bar"  "a"  "foo/bar-0.1.a" == True
+    test $ matchVersionedFilePath "foo/bar-" "a"  "foo/bar-0.1.a" == True
+    test $ matchVersionedFilePath "foo/bar/" "a"  "foo/bar-0.1.a" == False
+
+    test $ \prefix suffix -> forAll versions $ \version ->
+        matchVersionedFilePath prefix suffix (prefix ++ version ++ suffix)
+  where
+    versions = listOf . elements $ '-' : '.' : ['0'..'9']



More information about the ghc-commits mailing list