Skip to content

Commit

Permalink
Tests should work now.
Browse files Browse the repository at this point in the history
  • Loading branch information
my-name-is-lad committed Jul 11, 2024
1 parent 1128748 commit 6183084
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 14 deletions.
21 changes: 16 additions & 5 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
}:
let
masterPkgs = import sources.nixpkgs { inherit system; };
yq = import ./nix/yq.nix { pkgs = masterPkgs; };
diffYaml = import ./nix/diff-yaml.nix { pkgs = masterPkgs; };

hsPkgs = pkgs.haskell-nix.stackProject {
src = nix-filter {
Expand Down Expand Up @@ -97,6 +99,18 @@ let
};

WindowsCompaRESTBin = hsPkgs.projectCross.mingwW64.hsPkgs.compaREST.components.exes.compaREST;

# We use the static version so that we don't have to rebuild everything on CI.
# The only binaries build on CI are static.
test = hsPkgs.projectCross.musl64.hsPkgs.compaREST.components.tests.compaREST-tests.overrideAttrs (final: old: {
buildInputs = old.buildInputs ++ [ diffYaml yq ];
nativeBuildInputs = old.nativeBuildInputs ++ (with masterPkgs; [ makeWrapper ]);

postInstall = ''
wrapProgram $out/bin/compaREST-tests \
--prefix PATH : ${masterPkgs.lib.makeBinPath [ diffYaml yq ]}
'';
});
in
{
inherit
Expand All @@ -106,9 +120,6 @@ in
compaRESTBin
hsPkgs
macOSCompaRESTBundle
WindowsCompaRESTBin;

# We use the static version so that we don't have to rebuild everything on CI.
# The only binaries build on CI are static.
test = hsPkgs.projectCross.musl64.hsPkgs.compaREST.components.tests.compaREST-tests;
WindowsCompaRESTBin
test;
}
7 changes: 6 additions & 1 deletion nix/ci.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{ sources ? import ./sources.nix
, pkgs ? import sources.nixpkgs { }
}:

let
yq = import ./yq.nix { inherit pkgs; };
diff-yaml = import ./diff-yaml.nix { inherit pkgs; };
in
pkgs.mkShell {
packages = [ pkgs.haskellPackages.fourmolu ];
packages = [ pkgs.haskellPackages.fourmolu diff-yaml yq ];
}
20 changes: 20 additions & 0 deletions nix/diff-yaml.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ pkgs ? import <nixpkgs> {} }:

let
inherit (pkgs) stdenv;
yq = import ./yq.nix { inherit pkgs; };
in
stdenv.mkDerivation {
name = "diff-yaml";

src = ../scripts/diff-yaml;

buildInputs = [ pkgs.bash yq ];

phases = [ "installPhase" ];

installPhase = ''
mkdir -p $out/bin
cp $src $out/bin/diff-yaml
'';
}
12 changes: 6 additions & 6 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"homepage": "https://input-output-hk.github.io/haskell.nix",
"owner": "input-output-hk",
"repo": "haskell.nix",
"rev": "c1382b31f1ba8440acf409babf78f3139f415318",
"sha256": "1bf2d0wq7l1v2gbds4is9diqm9821dgc9pgqs9vnx8d1zw4mq10f",
"rev": "4413d8325d6359a6be774ef07d9a310ab96c4d25",
"sha256": "0il11752dv2pn47i3kynjfgikfwn2rm4naray89xm8dlgafk90mj",
"type": "tarball",
"url": "https://github.com/input-output-hk/haskell.nix/archive/c1382b31f1ba8440acf409babf78f3139f415318.tar.gz",
"url": "https://github.com/input-output-hk/haskell.nix/archive/4413d8325d6359a6be774ef07d9a310ab96c4d25.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"niv": {
Expand Down Expand Up @@ -41,10 +41,10 @@
"homepage": "",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "619de33c2d7bdcf6f03fc1f5d4d9d33df3ae7261",
"sha256": "1pybxai356n7phqn85iicydl67x5qqbb7ssncddlxcpy1qbxih06",
"rev": "3c89ee1b7bc3121a8f7d2303163e45320bb75eba",
"sha256": "1jx033mxi3pcz0whplzni2d7dra95r3pn3vgdrjlrbj26x19j49z",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/619de33c2d7bdcf6f03fc1f5d4d9d33df3ae7261.tar.gz",
"url": "https://github.com/NixOS/nixpkgs/archive/3c89ee1b7bc3121a8f7d2303163e45320bb75eba.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
2 changes: 2 additions & 0 deletions nix/yq.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{ pkgs ? import <nixpkgs> {} }:

# Make yq work inside whatever `stack test` launches.
# Nuke this when https://github.com/kislyuk/yq/pull/193 is merged
# and nixpkgs includes that fix.

let
yq-patch = pkgs.writeText "yq-tty-fix.patch" ''
Expand Down
35 changes: 35 additions & 0 deletions scripts/diff-yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -e

# Normalise YAML files passed as inputs, then run diff on them.

check_util() {
local util=$1

if [ -z $util ]; then
echo "Error: $util not found in PATH"
exit 1
fi
}

DIFF=`which diff`
check_util $DIFF

YQ=`which yq`
check_util $YQ

# Only normalise YAML files.
# Print anything else as is.
normalise() {
local file=$1
local contents=($YQ -y -S '.' $file)

# if $contents contains actual YAML data, print it
if [[ $? == 0 ]]; then
echo $contents
else
cat $file
fi
}

$DIFF -u <(normalise $1) <(normalise $2)
4 changes: 3 additions & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ extra-deps:
allow-newer: true

nix:
packages: [pkg-config zlib]
# packages: [pkg-config yq zlib]
shell-file: ./nix/shell.nix
pure: false
2 changes: 1 addition & 1 deletion test/Spec/Golden/Extra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ goldenInputsTree ::
s ->
(t -> IO BSL.ByteString) ->
IO TestTree
goldenInputsTree name filepath golden inp f = do
goldenInputsTree name filepath golden inp f =
runTestInputTree golden f <$> getGoldenInputs name filepath inp

runTestInputTree ::
Expand Down

0 comments on commit 6183084

Please sign in to comment.