Skip to content

Commit 11b457a

Browse files
authored
test: Port with-subdir as flake check (#258)
1 parent 12904ac commit 11b457a

File tree

9 files changed

+168
-182
lines changed

9 files changed

+168
-182
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,3 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515
- run: nixci --build-systems "github:nix-systems/${{ matrix.system }}"
16-
# TODO: Remove this job after https://github.com/srid/haskell-flake/issues/241
17-
linux-test:
18-
runs-on: ubuntu-latest
19-
steps:
20-
- uses: actions/checkout@v4
21-
- uses: DeterminateSystems/nix-installer-action@main
22-
- run: bash ./runtest.sh

flake.nix

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,20 @@
5353
};
5454
};
5555

56-
test-project-module = {
57-
dir = "test/project-module";
56+
test-with-subdir = {
57+
dir = "test/with-subdir";
5858
overrideInputs = {
5959
inherit nixpkgs flake-parts;
6060
"haskell-flake" = ./.;
6161
};
6262
};
6363

64-
# Legacy shell script test
65-
legacy-test = {
66-
dir = "test";
67-
overrideInputs."haskell-flake" = ./.;
68-
# Can't build on Linux until https://github.com/srid/haskell-flake/issues/241
69-
# TODO: Do the above, and get rid of this test.
70-
systems = [ "aarch64-darwin" "x86_64-darwin" ];
64+
test-project-module = {
65+
dir = "test/project-module";
66+
overrideInputs = {
67+
inherit nixpkgs flake-parts;
68+
"haskell-flake" = ./.;
69+
};
7170
};
7271
};
7372
};

rundoc.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/usr/bin/env sh
22

3+
# TODO: Move this dev/flake.nix as flake app
4+
35
if [ -z "$1" ]; then
46
nix run github:srid/emanote -- -L ./doc
57
else
68
# Renders the docs, prints the location of the docs, opens the docs if possible
79
#
8-
# Does not run the link checker. That's done in runtest.sh.
10+
# Does not run the link checker. That's done in nixci checks.
911
nix --option sandbox false \
1012
build ${OVERRIDE_HASKELL_FLAKE} \
1113
-L --show-trace \

runtest.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/common.sh

Lines changed: 0 additions & 33 deletions
This file was deleted.

test/flake.nix

Lines changed: 0 additions & 39 deletions
This file was deleted.

test/with-subdir/flake.nix

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,98 @@
1212
systems = nixpkgs.lib.systems.flakeExposed;
1313
imports = [
1414
inputs.haskell-flake.flakeModule
15+
./haskell-flake-patch.nix
1516
];
16-
perSystem = { self', pkgs, ... }: {
17+
debug = true;
18+
perSystem = { config, self', pkgs, lib, ... }: {
1719
haskellProjects.default = { };
18-
packages.default = self'.packages.haskell-flake-test;
20+
21+
# Test the default project by patching and evaluating the result.
22+
haskellProjectTests =
23+
let
24+
pkgOf = projectName: config.haskellProjects.${projectName}.outputs.finalPackages.haskell-flake-test;
25+
drvHash = drv: drv.drvPath;
26+
deriverHash = drv: drv.cabal2nixDeriver.drvPath;
27+
in
28+
{
29+
# Eval is constant under changes to irrelevant files
30+
touch-cabal-project = { name, ... }: {
31+
patches = [
32+
''
33+
diff --git a/cabal.project b/cabal.project
34+
index 1a862c3..92dd52b 100644
35+
--- a/cabal.project
36+
+++ b/cabal.project
37+
@@ -1,2 +1,4 @@
38+
packages:
39+
- ./haskell-flake-test
40+
\ No newline at end of file
41+
+ ./haskell-flake-test
42+
+-- irrelevant comment
43+
+
44+
''
45+
];
46+
expect =
47+
lib.assertMsg
48+
(lib.all (x: x) [
49+
(drvHash (pkgOf "default") == drvHash (pkgOf name))
50+
(deriverHash (pkgOf "default") == deriverHash (pkgOf name))
51+
])
52+
"touch-cabal-project failed";
53+
};
54+
55+
# A relevant change to Haskell source causes a .drv change (control check)
56+
# But no cabal2nix re-eval
57+
touch-src = { name, ... }: {
58+
patches = [
59+
''
60+
diff --git a/haskell-flake-test/src/Main.hs b/haskell-flake-test/src/Main.hs
61+
index fa10095..293744c 100644
62+
--- a/haskell-flake-test/src/Main.hs
63+
+++ b/haskell-flake-test/src/Main.hs
64+
@@ -3,3 +3,5 @@ module Main where
65+
main :: IO ()
66+
main = do
67+
putStrLn "Hello"
68+
+-- irrelevant comment
69+
+
70+
71+
''
72+
];
73+
expect =
74+
lib.assertMsg
75+
(lib.all (x: x) [
76+
(drvHash (pkgOf "default") != drvHash (pkgOf name))
77+
(deriverHash (pkgOf "default") == deriverHash (pkgOf name))
78+
])
79+
"touch-src failed";
80+
};
81+
82+
# A relevant change to .cabal file causes cabal2nix re-eval
83+
touch-cabal = { name, ... }: {
84+
patches = [
85+
''
86+
diff --git a/haskell-flake-test/haskell-flake-test.cabal b/haskell-flake-test/haskell-flake-test.cabal
87+
index 950a0ff..ef3131b 100644
88+
--- a/haskell-flake-test/haskell-flake-test.cabal
89+
+++ b/haskell-flake-test/haskell-flake-test.cabal
90+
@@ -16,3 +16,5 @@ executable haskell-flake-test
91+
base
92+
hs-source-dirs: src
93+
default-language: Haskell2010
94+
+-- irrelevant comment
95+
+
96+
''
97+
];
98+
expect =
99+
lib.assertMsg
100+
(lib.all (x: x) [
101+
(drvHash (pkgOf "default") != drvHash (pkgOf name))
102+
(deriverHash (pkgOf "default") != deriverHash (pkgOf name))
103+
])
104+
"touch-src failed";
105+
};
106+
};
19107
};
20108
};
21109
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{ self, lib, flake-parts-lib, ... }:
2+
3+
let
4+
inherit (flake-parts-lib)
5+
mkPerSystemOption;
6+
inherit (lib)
7+
mkOption
8+
types;
9+
in
10+
{
11+
options.perSystem = mkPerSystemOption ({ config, self', pkgs, ... }: {
12+
options = {
13+
haskellProjectTests = mkOption {
14+
type = types.attrsOf (types.submoduleWith {
15+
specialArgs = { inherit pkgs self; };
16+
modules = [
17+
{
18+
options = {
19+
from = lib.mkOption {
20+
type = types.str;
21+
default = "default";
22+
};
23+
patches = lib.mkOption {
24+
type = types.listOf (types.either types.path types.str);
25+
description = ''
26+
List of patches to apply to the project root.
27+
28+
Each patch can be a path to the diff file, or inline patch string.
29+
'';
30+
};
31+
expect = lib.mkOption {
32+
type = types.raw;
33+
description = "Test expectation";
34+
};
35+
};
36+
}
37+
];
38+
});
39+
};
40+
};
41+
42+
config = {
43+
haskellProjects = lib.flip lib.mapAttrs config.haskellProjectTests (name: cfg: {
44+
projectRoot = pkgs.applyPatches {
45+
name = "haskellProject-patched-${name}";
46+
src = config.haskellProjects.${cfg.from}.projectRoot;
47+
patches = lib.flip builtins.map cfg.patches (patch:
48+
if types.path.check patch then patch else
49+
pkgs.writeTextFile {
50+
name = "${name}.diff";
51+
text = patch;
52+
}
53+
);
54+
};
55+
});
56+
57+
checks = lib.flip lib.mapAttrs config.haskellProjectTests (name: cfg:
58+
pkgs.runCommandNoCC "haskell-flake-patch-test-${name}"
59+
{
60+
EXPECT = builtins.toJSON cfg.expect;
61+
}
62+
''touch $out''
63+
);
64+
};
65+
});
66+
67+
}

test/with-subdir/test.sh

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)