|
| 1 | +#! /usr/bin/env nix-shell |
| 2 | +#! nix-shell --pure |
| 3 | +#! nix-shell --keep NIX_PATH |
| 4 | +#! nix-shell -i runhaskell |
| 5 | +#! nix-shell -p ghc nix rsync cacert |
| 6 | + |
| 7 | +{-# language ScopedTypeVariables #-} |
| 8 | + |
| 9 | +-- This is the test script run by the CI server. |
| 10 | + |
| 11 | +import Control.Monad |
| 12 | +import System.Directory |
| 13 | +import System.Process |
| 14 | +import System.Exit |
| 15 | +import System.FilePath ((</>)) |
| 16 | +import qualified Data.ByteString as ByteString |
| 17 | + |
| 18 | +main = (build >>= copy) *> (findProblems >>= conclude) |
| 19 | + |
| 20 | +-- Builds all of the example outputs in the Nix store and returns the path. |
| 21 | +build :: IO FilePath = |
| 22 | + fmap (head . lines) $ readProcess "nix-build" ["--attr", "outputs", "--no-out-link", "tools/default.nix"] "" |
| 23 | + |
| 24 | +-- Copies the example outputs from the Nix store into the "outputs-test" directory. |
| 25 | +copy (src :: FilePath) = |
| 26 | + callProcess "rsync" ["--copy-links", "--recursive", "--chmod=ugo=rwX", src <> "/", "outputs-test"] |
| 27 | + |
| 28 | +-- The "outputs" and "outputs-test" directories should be identical. This action returns a list of the filenames that differ. |
| 29 | +findProblems :: IO [FilePath] = |
| 30 | + listDirectory "outputs" >>= filterM isProblem |
| 31 | + |
| 32 | +-- Given an output file name, determines whether the file in "outputs" differs from the corresponding file in "outputs-test". |
| 33 | +isProblem (filename :: FilePath) = |
| 34 | + pure (/=) |
| 35 | + <*> ByteString.readFile ("outputs" </> filename) |
| 36 | + <*> ByteString.readFile ("outputs-test" </> filename) |
| 37 | + |
| 38 | +-- If the problem list is non-empty, prints the list of problems and exits with a nonzero status code to indicate failure. |
| 39 | +conclude (problems :: [FilePath]) = |
| 40 | + if null problems then putStrLn "Okay!" |
| 41 | + else die ("Problems: " <> show problems) |
0 commit comments