commit ed94fa57bc4f424a1a8b50ac98da2146f9a49b00
parent ad919999bc228a73ce454b82cef44c5c8945b49a
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 27 Oct 2024 20:19:58 +0000
make "cabal test" work
Diffstat:
3 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/default.nix b/default.nix
@@ -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 ++
diff --git a/souplesse.cabal b/souplesse.cabal
@@ -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
diff --git a/tests/UnitTest.hs b/tests/UnitTest.hs
@@ -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