Skip to content

Commit a42d842

Browse files
committed
ghcid auto-reload for tests
This change extends multi-home units to work with tests as well. We first make vira tests a proper spec (not executable), and then add that to --enable-multi-repl so that the tests re-compile when the library sources change. This option is define in one place, ./cabal-repl. We could potentially nixify this using srid/haskell-flake#449 Also, the tests no longer build in Nix for vira, as they require network. Instead the Github workflow runs them through cabal.
1 parent 2672f82 commit a42d842

File tree

12 files changed

+36
-35
lines changed

12 files changed

+36
-35
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
run: nix run . -- --help
2323
- name: Run Tests
2424
run: |
25-
nix --option system "${{ matrix.system }}" run .#vira-tests
25+
nix --option system "${{ matrix.system }}" develop -c cabal test all
2626
- name: Push to Attic
2727
run: |
2828
attic login chutney https://cache.nixos.asia ${{ secrets.ATTIC_LOGIN_TOKEN }}

cabal-repl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# For use with GHC home units
4+
# https://x.com/sridca/status/1901283945779544362
5+
6+
exec cabal repl --enable-multi-repl "$@" \
7+
vira tail warp-tls-simple htmx-lucid-contrib

cabal.project

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
packages:
22
packages/vira
3-
packages/htmx-lucid-contrib
4-
packages/warp-tls-simple
53
packages/tail
4+
packages/warp-tls-simple
5+
packages/htmx-lucid-contrib

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ run:
1515
# Run cabal tests (hspec)
1616
[group('2. haskell')]
1717
test:
18-
ghcid --warnings -c "cabal repl vira:exe:vira-tests --flags=ghcid" --test "main"
18+
ghcid --warnings -T Main.main -c "./cabal-repl vira:test:vira-tests"
1919

2020
# Delete and recreate vira.db
2121
[group('1. vira')]

nix/modules/flake-parts/haskell.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
imports = [
44
inputs.haskell-flake.flakeModule
55
];
6+
debug = true;
67
perSystem = { self', lib, config, pkgs, ... }: {
78
# Our only Haskell project. You can have multiple projects, but this template
89
# has only one.
@@ -33,6 +34,7 @@
3334
# Add your package overrides here
3435
settings = {
3536
vira = {
37+
check = false; # Running outside of Nix.
3638
generateOptparseApplicativeCompletions = [ "vira" ];
3739
extraBuildDepends = [
3840
pkgs.git
@@ -93,8 +95,6 @@
9395
};
9496
};
9597

96-
apps.vira-tests = config.haskellProjects.default.outputs.apps.vira-tests;
97-
9898
checks = config.haskellProjects.default.outputs.checks;
9999
};
100100
}

nix/modules/flake-parts/vira-dev.nix

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@
44
imports = [
55
inputs.process-compose-flake.flakeModule
66
];
7-
perSystem = { self', lib, config, pkgs, ... }: {
7+
perSystem = { lib, config, pkgs, ... }: {
88
process-compose."vira-dev" = {
99
settings = {
1010
processes = let host = "0.0.0.0"; port = "5005"; in {
1111
haskell = {
1212
command =
13-
let
14-
# https://x.com/sridca/status/1901283945779544362
15-
multiReplLibs = "vira:exe:vira vira tail warp-tls-simple htmx-lucid-contrib";
16-
in
1713
pkgs.writeShellScriptBin "haskell-dev" ''
1814
set -x
1915
cd ./packages/vira
2016
# Vira now auto-generates TLS certificates as needed
21-
ghcid -T Main.main -c 'cabal repl --enable-multi-repl ${multiReplLibs}' \
17+
ghcid -T Main.main -c '${root}/cabal-repl vira:exe:vira' \
2218
--setup ":set args --host ${host} --base-path ''${BASE_PATH:-/} --state-dir ../../state"
2319
'';
2420
depends_on.tailwind.condition = "process_started";

packages/vira/package.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ executables:
9292
dependencies:
9393
- vira
9494

95+
tests:
9596
vira-tests:
96-
main: Test.hs
97+
main: Spec.hs
9798
source-dirs: test
9899
dependencies:
99-
- vira
100+
- vira

packages/vira/src/Vira/Lib/Git.hs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import Data.Text qualified as T
1515
import Servant (FromHttpApiData, ToHttpApiData)
1616
import System.Process
1717
import System.Which (staticWhich)
18-
import Test.Hspec
1918

2019
{- | Path to the `git` executable
2120
@@ -77,11 +76,3 @@ cloneAtCommit url branch commit =
7776
[ proc git ["clone", "--branch", toString branch, "--single-branch", "--depth", "1", toString url, "."]
7877
, proc git ["checkout", toString commit]
7978
]
80-
81-
spec :: Spec
82-
spec = do
83-
describe "Git" $ do
84-
it "remoteBranches" $ do
85-
let archivedRepo = "https://github.com/srid/leptos-nix-template" -- Archived; won't change
86-
branches <- remoteBranches archivedRepo
87-
Map.lookup "main" branches `shouldBe` Just "68506f5bf0a5883e737c0f8b7bab4c651a0d5fc0"

packages/vira/test/Spec.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}

packages/vira/test/Test.hs

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

0 commit comments

Comments
 (0)