Skip to content

Commit 0e2f89f

Browse files
committed
Added test for type of fixpoint directory tree expressions
Also updated Haddocks of Dhall.DirectoryTree.
1 parent 6ad53cf commit 0e2f89f

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

dhall/src/Dhall/DirectoryTree.hs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{-# LANGUAGE BangPatterns #-}
21
{-# LANGUAGE DataKinds #-}
32
{-# LANGUAGE DeriveGeneric #-}
43
{-# LANGUAGE DerivingVia #-}
@@ -18,6 +17,9 @@ module Dhall.DirectoryTree
1817
( -- * Filesystem
1918
toDirectoryTree
2019
, FilesystemError(..)
20+
21+
-- * Exported for testing only
22+
, directoryTreeType
2123
) where
2224

2325
import Control.Applicative (empty)
@@ -257,10 +259,12 @@ toDirectoryTree allowSeparators path expression = case expression of
257259
where
258260
unexpectedExpression = expression
259261

262+
-- | The type of a fixpoint directory tree expression.
260263
directoryTreeType :: Expector (Expr Src Void)
261264
directoryTreeType = Pi Nothing "result" (Const Type)
262265
<$> (Pi Nothing "make" <$> makeType <*> pure (App List (Var (V "result" 0))))
263266

267+
-- | The type of make part of a fixpoint directory tree expression.
264268
makeType :: Expector (Expr Src Void)
265269
makeType = Record . Map.fromList <$> sequenceA
266270
[ makeConstructor "directory" (Decode.auto :: Decoder DirectoryEntry)
@@ -292,8 +296,8 @@ instance FromDhall FilesystemEntry where
292296
expr -> Decode.typeError (expected (Decode.autoWith normalizer :: Decoder FilesystemEntry)) expr
293297
}
294298

295-
-- | A generic filesystem entry. This type holds the metadata that apply to all entries.
296-
-- It is parametric over the content of such an entry.
299+
-- | A generic filesystem entry. This type holds the metadata that apply to all
300+
-- entries. It is parametric over the content of such an entry.
297301
data Entry a = Entry
298302
{ entryName :: String
299303
, entryContent :: a
@@ -434,7 +438,8 @@ applyMetadata entry fp = do
434438
unless (mode' == mode) $
435439
Posix.setFileMode fp $ modeToFileMode mode'
436440

437-
-- | Calculate the new `Mode` from the current mode and the changes specified by the user.
441+
-- | Calculate the new `Mode` from the current mode and the changes specified by
442+
-- the user.
438443
updateModeWith :: Mode Identity -> Mode Maybe -> Mode Identity
439444
updateModeWith x y = Mode
440445
{ modeUser = combine modeUser modeUser
@@ -444,7 +449,8 @@ updateModeWith x y = Mode
444449
where
445450
combine f g = maybe (f x) (Identity . updateAccessWith (runIdentity $ f x)) (g y)
446451

447-
-- | Calculate the new `Access` from the current permissions and the changes specified by the user.
452+
-- | Calculate the new `Access` from the current permissions and the changes
453+
-- specified by the user.
448454
updateAccessWith :: Access Identity -> Access Maybe -> Access Identity
449455
updateAccessWith x y = Access
450456
{ accessExecute = combine accessExecute accessExecute
@@ -454,7 +460,8 @@ updateAccessWith x y = Access
454460
where
455461
combine f g = maybe (f x) Identity (g y)
456462

457-
-- | Convert a filesystem mode given as a bitmask (`FileMode`) to an ADT (`Mode`).
463+
-- | Convert a filesystem mode given as a bitmask (`FileMode`) to an ADT
464+
-- (`Mode`).
458465
fileModeToMode :: FileMode -> Mode Identity
459466
fileModeToMode mode = Mode
460467
{ modeUser = Identity $ Access
@@ -474,7 +481,8 @@ fileModeToMode mode = Mode
474481
}
475482
}
476483

477-
-- | Convert a filesystem mode given as an ADT (`Mode`) to a bitmask (`FileMode`).
484+
-- | Convert a filesystem mode given as an ADT (`Mode`) to a bitmask
485+
-- (`FileMode`).
478486
modeToFileMode :: Mode Identity -> FileMode
479487
modeToFileMode mode = foldr Posix.unionFileModes Posix.nullFileMode $
480488
[ Posix.ownerExecuteMode | runIdentity $ accessExecute (runIdentity $ modeUser mode) ] <>

dhall/tests/Dhall/Test/DirectoryTree.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Dhall.Test.DirectoryTree (tests) where
22

33
import Control.Monad
44
import Data.Either (partitionEithers)
5+
import Data.Either.Validation
56
import Lens.Family (set)
67
import System.FilePath ((</>))
78
import Test.Tasty
@@ -18,12 +19,23 @@ import qualified System.PosixCompat.Files as Files
1819
tests :: TestTree
1920
tests = testGroup "to-directory-tree"
2021
[ testGroup "fixpointed"
21-
[ fixpointedEmpty
22+
[ fixpointedType
23+
, fixpointedEmpty
2224
, fixpointedSimple
2325
, fixpointedMetadata
2426
]
2527
]
2628

29+
fixpointedType :: TestTree
30+
fixpointedType = testCase "Type is as expected" $ do
31+
let file = "./tests/to-directory-tree/type.dhall"
32+
text <- Data.Text.IO.readFile file
33+
ref <- Dhall.inputExpr text
34+
expected' <- case Dhall.DirectoryTree.directoryTreeType of
35+
Failure e -> assertFailure $ show e
36+
Success expr -> return expr
37+
assertBool "Type mismatch" $ expected' `Dhall.Core.judgmentallyEqual` ref
38+
2739
fixpointedEmpty :: TestTree
2840
fixpointedEmpty = testCase "empty" $ do
2941
let outDir = "./tests/to-directory-tree/fixpoint-empty.out"

0 commit comments

Comments
 (0)