Check: build passthru.tests when present

This commit is contained in:
Léo Gaspard 2019-06-11 19:44:12 +02:00
parent c021ad573c
commit cb9bc5c419
No known key found for this signature in database
GPG Key ID: 771E7AD1170FE690
3 changed files with 40 additions and 16 deletions

View File

@ -15,7 +15,7 @@ import qualified Shell
import Shelly hiding (FilePath, whenM)
import qualified Text.Regex.Applicative.Text as RE
import Text.Regex.Applicative.Text (RE', (=~))
import Utils (UpdateEnv(..), Version, runtimeDir)
import Utils (UpdateEnv(..), Version, nixBuildOptions, runtimeDir)
default (T.Text)
@ -32,6 +32,21 @@ versionRegex version =
many (RE.sym '.') <*>
many (RE.psym isSpace)
checkTestsBuild :: Text -> Sh Bool
checkTestsBuild attrPath =
let nixBuildCmd =
nixBuildOptions ++
[ "-E"
, "{ config }: (import ./. { inherit config; })." ++
(T.unpack attrPath) ++ ".tests or {}"
]
in
catchany_sh
(do Shell.canFail $ Shelly.run "nix-build" (map T.pack nixBuildCmd)
code <- lastExitCode
return $ code == 0)
(\_ -> return False)
-- | Run a program with provided argument and report whether the output
-- mentions the expected version
checkBinary :: Text -> Version -> FilePath -> Sh BinaryCheck
@ -84,6 +99,12 @@ runChecks expectedVersion program =
where
checks' = map (\c -> c expectedVersion program) checks
checkTestsBuildReport :: Bool -> Text
checkTestsBuildReport False =
"- Warning: a test defined in `passthru.tests` did not pass"
checkTestsBuildReport True =
"- The tests defined in `passthru.tests`, if any, passed"
checkReport :: BinaryCheck -> Text
checkReport (BinaryCheck p False False) =
"- Warning: no invocation of " <> T.pack p <>
@ -112,6 +133,8 @@ result updateEnv resultPath =
if binExists
then findWhen test_f binaryDir
else return []
testsBuild <- checkTestsBuild (packageName updateEnv)
addToReport $ checkTestsBuildReport testsBuild
checks' <-
forM binaries $ \binary ->
runChecks expectedVersion (T.unpack $ toTextIgnore binary)

View File

@ -37,7 +37,7 @@ import System.Exit
import Text.Parsec (parse)
import Text.Parser.Combinators
import Text.Parser.Token
import Utils (UpdateEnv(..), overwriteErrorT, srcOrMain)
import Utils (UpdateEnv(..), nixBuildOptions, overwriteErrorT, srcOrMain)
data Raw
= Raw
@ -184,20 +184,7 @@ getSrcUrls = getSrcAttr "urls"
buildCmd :: Text -> ProcessConfig () () ()
buildCmd attrPath =
silently $
proc
"nix-build"
[ "--option"
, "sandbox"
, "true"
, "--option"
, "restrict-eval"
, "true"
, "--arg"
, "config"
, "{ allowBroken = true; allowUnfree = true; allowAliases = false; }"
, "-A"
, attrPath & T.unpack
]
proc "nix-build" (nixBuildOptions ++ ["-A", attrPath & T.unpack])
log :: Text -> ProcessConfig () () ()
log attrPath = proc "nix" ["log", "-f", ".", attrPath & T.unpack]

View File

@ -15,6 +15,7 @@ module Utils
, runtimeDir
, srcOrMain
, prTitle
, nixBuildOptions
) where
import OurPrelude
@ -133,3 +134,16 @@ tRead = read . T.unpack
srcOrMain :: MonadIO m => (Text -> ExceptT Text m a) -> Text -> ExceptT Text m a
srcOrMain et attrPath = et (attrPath <> ".src") <|> et attrPath
nixBuildOptions :: [String]
nixBuildOptions =
[ "--option"
, "sandbox"
, "true"
, "--option"
, "restrict-eval"
, "true"
, "--arg"
, "config"
, "{ allowBroken = true; allowUnfree = true; allowAliases = false; }"
]