make "cabal test" work

This commit is contained in:
Daniel Barlow 2024-10-27 20:19:58 +00:00
parent ad919999bc
commit ed94fa57bc
3 changed files with 33 additions and 0 deletions

View File

@ -2,6 +2,11 @@ let
pkgs = import <nixpkgs> { };
haskellEnv = pkgs.haskellPackages.developPackage {
root = ./.;
modifier = drv:
pkgs.haskell.lib.addBuildTools drv (with pkgs.haskellPackages;
[
cabal-install
]);
};
in haskellEnv.overrideAttrs(o: {
buildInputs = o.buildInputs ++

View File

@ -75,3 +75,16 @@ executable souplesse
-- Base language which the package is written in.
default-language: GHC2021
-- mostly copied from
-- https://functional.works-hub.com/learn/basic-unit-testing-in-haskell-using-hunit-and-cabal-29e47
test-suite tests
type: exitcode-stdio-1.0
main-is: UnitTest.hs
hs-source-dirs:
tests
build-depends:
base >=4.7 && <5
, HUnit
default-language: GHC2021

15
tests/UnitTest.hs Normal file
View File

@ -0,0 +1,15 @@
module Main where
-- import BasicSum
import Test.HUnit
import qualified System.Exit as Exit
test1 :: Test
test1 = TestCase (assertEqual "should return 3" 3 (1 + 2))
tests :: Test
tests = TestList [TestLabel "test1" test1]
main :: IO ()
main = do
result <- runTestTT tests
if failures result > 0 then Exit.exitFailure else Exit.exitSuccess