hnix/tests/Main.hs

56 lines
2.3 KiB
Haskell
Raw Normal View History

2014-08-03 14:17:43 +02:00
module Main where
2018-04-05 00:32:21 +02:00
import Control.Monad
import Data.List (isInfixOf)
2015-12-21 06:55:53 +01:00
import qualified EvalTests
2018-02-09 15:32:53 +01:00
import qualified NixLanguageTests
import qualified ParserTests
import qualified PrettyTests
import System.Environment
import System.Exit
import System.Posix.Files
import System.Process
import Test.Tasty
import Test.Tasty.HUnit
2016-01-23 22:46:30 +01:00
cabalCorrectlyGenerated :: Assertion
cabalCorrectlyGenerated = do
output <- readCreateProcess (shell "hpack") ""
when ("modified manually" `isInfixOf` output) $
errorWithoutStackTrace
"Edit package.yaml and re-generate hnix.cabal by running \"hpack\""
ensureLangTestsPresent :: Assertion
ensureLangTestsPresent = do
exist <- fileExist "data/nix/tests/local.mk"
2018-04-05 01:33:43 +02:00
unless exist $
errorWithoutStackTrace $ unlines
[ "Directory data/nix does not have any files."
, "Did you forget to run"
++ " \"git submodule update --init --recursive\"?"
2018-04-05 01:33:43 +02:00
]
ensureNixpkgsCanParse :: Assertion
ensureNixpkgsCanParse = do
-- jww (2018-04-10): Use hnix to parse default.nix and pull this data from there!
path <- readCreateProcess (shell "nix-instantiate --eval --expr '\"${let hostPkgs = import <nixpkgs> {}; in hostPkgs.fetchFromGitHub { owner = \"NixOS\"; repo = \"nixpkgs-channels\"; rev = \"ee28e35ba37ab285fc29e4a09f26235ffe4123e2\"; sha256 = \"0a6xrqjj2ihkz1bizhy5r843n38xgimzw5s2mfc42kk2rgc95gw5\"; }}\"'") ""
(exit, _, errs) <- readCreateProcessWithExitCode (shell $ "find " ++ init path ++ " -name '*.nix' | ./dist/build/hnix/hnix --ignore-errors --parse-only -f - > /dev/null") ""
unless (exit == ExitSuccess) $ errorWithoutStackTrace errs
main :: IO ()
main = do
nixLanguageTests <- NixLanguageTests.genTests
langTestsEnv <- lookupEnv "LANGUAGE_TESTS"
nixpkgsTestsEnv <- lookupEnv "NIXPKGS_TESTS"
let runLangTests = langTestsEnv == Just "yes"
let runNixpkgsTests = nixpkgsTestsEnv == Just "yes"
defaultMain $ testGroup "hnix" $
[ testCase "hnix.cabal correctly generated" cabalCorrectlyGenerated ] ++
2018-02-09 15:32:53 +01:00
[ ParserTests.tests
, EvalTests.tests
, PrettyTests.tests
] ++
[ testCase "Nix languarge tests present" ensureLangTestsPresent | runLangTests ] ++
[ nixLanguageTests | runLangTests ] ++
[ testCase "Nixpkgs parses without errors" ensureNixpkgsCanParse | runNixpkgsTests ]