Skip to content

Commit

Permalink
Merge pull request #61 from NicolasT/fix-readme-test
Browse files Browse the repository at this point in the history
landlock: improve `README.lhs` test
  • Loading branch information
NicolasT authored Apr 1, 2024
2 parents 2952337 + e1f0c39 commit 926005c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 7 additions & 3 deletions landlock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,18 @@ main = withFakeRoot $ \root -> do
readFile ("/etc" </> "hosts")

where
lookupAccessFsFlags version = case lookup version accessFsFlags of
-- In a production implementation, we'd lookup the "best matching" flag
-- set, not require an exact match.
lookupAccessFsFlags version = case lookupMax version accessFsFlags of
Nothing -> fail "Unsupported ABI version"
Just flags -> return flags

assertPermissionDenied act = handleJust permissionDenied return $ do
_ <- act
fail "Expected permission error"
permissionDenied e = if isPermissionError e then Just () else Nothing

lookupMax key = fmap snd
. listToMaybe
. reverse
. sort
. filter (\(k, _) -> key >= k)
```
6 changes: 6 additions & 0 deletions landlock/test/ReadmeUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module ReadmeUtils
handleJust,
-- Control.Monad
unless,
-- Data.List
sort,
-- Data.Maybe
listToMaybe,
-- System.Directory
removeFile,
-- System.FilePath
Expand All @@ -22,6 +26,8 @@ where

import Control.Exception.Base (handleJust)
import Control.Monad (unless)
import Data.List (sort)
import Data.Maybe (listToMaybe)
import System.Directory (createDirectory, removeFile)
import System.FilePath ((</>))
import System.IO (IOMode (..), hPutStrLn, withFile)
Expand Down

0 comments on commit 926005c

Please sign in to comment.