Skip to content

Commit

Permalink
add manual native test for bump
Browse files Browse the repository at this point in the history
  • Loading branch information
tek committed Jun 13, 2024
1 parent 1948100 commit 2674458
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Unreleased

* Add a reusable workflow for managed bounds updates.
* Parse Nix json output messages to diagnose problems; add overrides for installed packages that fail with a bounds
error printed by Cabal.

# 0.7.0: Hix Unbound: Majors Apart

Expand Down
1 change: 1 addition & 0 deletions packages/hix/hix.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ test-suite hix-test
Hix.Test.Managed.BuildOutputTest
Hix.Test.Managed.Bump.CandidatesTest
Hix.Test.Managed.Bump.MutationTest
Hix.Test.Managed.BumpNativeTest
Hix.Test.Managed.DiffTest
Hix.Test.Managed.LowerAuto.MutationOptimizeTest
Hix.Test.Managed.LowerAuto.MutationStabilizeTest
Expand Down
135 changes: 135 additions & 0 deletions packages/hix/test/Hix/Test/Managed/BumpNativeTest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
module Hix.Test.Managed.BumpNativeTest where

import Control.Monad.Trans.Reader (ask)
import qualified Data.Text.IO as Text
import Exon (exon)
import Hedgehog (evalEither)
import Path (Abs, Dir, File, Path, Rel, parent, reldir, relfile, toFilePath, (</>))
import Path.IO (createDirIfMissing, getCurrentDir)

import qualified Hix.Data.Monad
import Hix.Data.Monad (AppResources (AppResources), M (M))
import Hix.Data.Options (ProjectOptions (query), projectOptions)
import Hix.Error (pathText)
import Hix.Managed.Bump.Optimize (bumpOptimizeMain)
import Hix.Managed.Cabal.Data.Config (GhcDb (GhcDbSystem))
import qualified Hix.Managed.Data.EnvConfig
import Hix.Managed.Data.EnvConfig (EnvConfig (EnvConfig))
import Hix.Managed.Data.ManagedPackageProto (ManagedPackageProto, managedPackages)
import Hix.Managed.Data.Packages (Packages)
import qualified Hix.Managed.Data.ProjectContext
import qualified Hix.Managed.Data.ProjectContextProto
import Hix.Managed.Data.ProjectContextProto (ProjectContextProto (ProjectContextProto))
import qualified Hix.Managed.Data.ProjectResult
import Hix.Managed.Data.ProjectStateProto (ProjectStateProto (ProjectStateProto))
import qualified Hix.Managed.Data.StateFileConfig
import Hix.Managed.Data.StateFileConfig (StateFileConfig (StateFileConfig))
import qualified Hix.Managed.Handlers.Build.Prod as Build
import Hix.Managed.ProjectContext (updateProject)
import qualified Hix.Managed.ProjectContextProto as ProjectContextProto
import Hix.Test.Hedgehog (eqLines)
import Hix.Test.Utils (UnitTest, runMTest)

packages :: Packages ManagedPackageProto
packages =
managedPackages [
(("root", "1.0"), ["tasty <1.5", "criterion <1.7"])
]

flake :: Path Abs Dir -> Text
flake hixRoot =
[exon|{
description = "hix test project";
inputs.hix.url = "path:#{pathText hixRoot}";
outputs = {self, hix, ...}: hix.lib.flake ({config, lib, ...}: {
managed = {
enable = true;
latest.compiler = "ghc98";
};
compat.enable = false;
ghcVersions = [];
packages = {
root = {
src = ./.;
library = {
enable = true;
dependencies = ["tasty" "criterion"];
};
};
};
envs.latest.localPackage = api: api.minimal;
});
}|]

libMod :: Text
libMod =
[exon|module Root where
-- import Test.Tasty (blarkh)
string :: String
string = "hello"
|]

addFile :: Path Abs Dir -> Path Rel File -> Text -> M ()
addFile root path content = do
createDirIfMissing True (parent file)
liftIO (Text.writeFile (toFilePath file) content)
where
file = root </> path

setupProject :: M (Path Abs Dir)
setupProject = do
AppResources {tmp} <- M ask
cwd <- getCurrentDir
let projectRoot = tmp </> [reldir|project|]
let hixRoot = parent (parent cwd)
createDirIfMissing True projectRoot
addFile projectRoot [relfile|flake.nix|] (flake hixRoot)
addFile projectRoot [relfile|lib/Root.hs|] libMod
pure projectRoot

targetStateFile :: Text
targetStateFile =
[exon|{
resolving = false;
}
|]

bumpNativeTest :: M Text
bumpNativeTest = do
root <- setupProject
let
stateFileConf = StateFileConfig {
file = [relfile|ops/managed.nix|],
projectRoot = Just root
}
envsConfig = [("latest", EnvConfig {targets = ["root"], ghc = GhcDbSystem Nothing})]
buildConfig = def
handlers <- Build.handlersProd stateFileConf envsConfig Nothing buildConfig def False
let
opts = (projectOptions ["latest"]) {query = ["tasty"]}

proto0 =
ProjectContextProto {
packages,
state = ProjectStateProto [] [] mempty mempty False,
envs = envsConfig,
buildOutputsPrefix = Nothing
}

stateFile = root </> [relfile|ops/managed.nix|]

run context process = do
result <- process handlers context
updateProject handlers context.build result
stateFileContent <- liftIO (Text.readFile (toFilePath stateFile))
pure (result.state, stateFileContent)

context0 <- ProjectContextProto.validate opts proto0
(_, stateFileContent) <- run context0 bumpOptimizeMain
pure stateFileContent

test_bumpNative :: UnitTest
test_bumpNative = do
stateFileContent <- evalEither =<< liftIO do
runMTest True bumpNativeTest
eqLines targetStateFile stateFileContent

0 comments on commit 2674458

Please sign in to comment.