From ed94fa57bc4f424a1a8b50ac98da2146f9a49b00 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 27 Oct 2024 20:19:58 +0000 Subject: [PATCH] make "cabal test" work --- default.nix | 5 +++++ souplesse.cabal | 13 +++++++++++++ tests/UnitTest.hs | 15 +++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 tests/UnitTest.hs diff --git a/default.nix b/default.nix index 076333f..05ef899 100644 --- a/default.nix +++ b/default.nix @@ -2,6 +2,11 @@ let pkgs = import { }; 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 index 5ca0ed0..f11dbb9 100644 --- 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 new file mode 100644 index 0000000..adb9930 --- /dev/null +++ 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