2020-05-19 12:09:25 +03:00
|
|
|
|
|
|
|
module Derivation where
|
|
|
|
|
2021-02-03 13:44:58 +03:00
|
|
|
import Test.Tasty ( TestTree
|
|
|
|
, testGroup
|
|
|
|
)
|
|
|
|
import Test.Tasty.Golden ( goldenVsFile )
|
2020-05-19 12:09:25 +03:00
|
|
|
|
2021-02-03 13:44:58 +03:00
|
|
|
import System.Nix.Derivation ( parseDerivation
|
|
|
|
, buildDerivation
|
|
|
|
)
|
2020-05-19 12:09:25 +03:00
|
|
|
|
2021-05-30 18:24:52 +03:00
|
|
|
import qualified Data.Attoparsec.Text
|
2020-05-19 12:09:25 +03:00
|
|
|
import qualified Data.Text.IO
|
|
|
|
import qualified Data.Text.Lazy
|
|
|
|
import qualified Data.Text.Lazy.Builder
|
|
|
|
|
2021-01-14 13:08:42 +03:00
|
|
|
processDerivation :: FilePath -> FilePath -> IO ()
|
2020-05-19 12:09:25 +03:00
|
|
|
processDerivation source dest = do
|
|
|
|
contents <- Data.Text.IO.readFile source
|
2021-05-30 18:24:52 +03:00
|
|
|
either
|
|
|
|
fail
|
|
|
|
(\ drv ->
|
2021-02-03 13:44:58 +03:00
|
|
|
Data.Text.IO.writeFile dest
|
|
|
|
. Data.Text.Lazy.toStrict
|
|
|
|
. Data.Text.Lazy.Builder.toLazyText
|
|
|
|
$ buildDerivation drv
|
2021-05-30 18:24:52 +03:00
|
|
|
)
|
|
|
|
(Data.Attoparsec.Text.parseOnly
|
|
|
|
(parseDerivation "/nix/store")
|
|
|
|
contents
|
|
|
|
)
|
2020-05-19 12:09:25 +03:00
|
|
|
|
|
|
|
test_derivation :: TestTree
|
2021-02-03 13:44:58 +03:00
|
|
|
test_derivation =
|
|
|
|
testGroup "golden" $ fmap mk [0 .. 1]
|
|
|
|
where
|
|
|
|
mk :: Int -> TestTree
|
|
|
|
mk n =
|
|
|
|
goldenVsFile
|
|
|
|
("derivation roundtrip of " <> drv)
|
|
|
|
drv
|
|
|
|
act
|
|
|
|
(processDerivation drv act)
|
|
|
|
where
|
|
|
|
drv = fp <> show n <> ".drv"
|
|
|
|
act = fp <> show n <> ".actual"
|
|
|
|
fp = "tests/samples/example"
|