From 2917995d0a64abeefc61e7f010b1dc312d13aad6 Mon Sep 17 00:00:00 2001 From: Mikolaj Konarski Date: Thu, 15 Jul 2021 16:07:10 +0200 Subject: [PATCH 1/7] Turn on a few extra GHC warnings --- cabal-install/cabal-install.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index a6618def56e..6272e1c888f 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -39,7 +39,7 @@ Flag lukko manual: True common warnings - ghc-options: -Wall -Wcompat -Wnoncanonical-monad-instances + ghc-options: -Wall -Wcompat -Wnoncanonical-monad-instances -Wincomplete-uni-patterns -Wincomplete-record-updates if impl(ghc < 8.8) ghc-options: -Wnoncanonical-monadfail-instances if impl(ghc >=8.10) From 8d4a282fa26c7f504043ed14ad56fbbf7362d8f0 Mon Sep 17 00:00:00 2001 From: Mikolaj Konarski Date: Sat, 24 Jul 2021 13:14:59 +0200 Subject: [PATCH 2/7] Hack around wrong .mix directories for tests #5213 --- Cabal/src/Distribution/Simple/Hpc.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Cabal/src/Distribution/Simple/Hpc.hs b/Cabal/src/Distribution/Simple/Hpc.hs index b678772c1e6..ae4fb7c122a 100644 --- a/Cabal/src/Distribution/Simple/Hpc.hs +++ b/Cabal/src/Distribution/Simple/Hpc.hs @@ -68,7 +68,15 @@ mixDir :: FilePath -- ^ \"dist/\" prefix -> Way -> FilePath -- ^ Component name -> FilePath -- ^ Directory containing test suite's .mix files -mixDir distPref way name = hpcDir distPref way "mix" name +mixDir distPref way name = hpcDir distPrefBuild way "mix" name + where + -- This is a hack for HPC over test suites, needed to match the directory + -- where HPC stores .mix files when the main library of the same package + -- is being processed, perhaps in a previous cabal run (#5213). + distPrefElements = splitDirectories distPref + distPrefBuild = case drop (length distPrefElements - 2) distPrefElements of + "t" : _ -> joinPath $ take (length distPrefElements - 2) distPrefElements + _ -> distPref tixDir :: FilePath -- ^ \"dist/\" prefix -> Way From e3f2dd456bdfae29d2c62b2a3da8da22bf4a7f5a Mon Sep 17 00:00:00 2001 From: Mikolaj Konarski Date: Sat, 24 Jul 2021 21:29:18 +0200 Subject: [PATCH 3/7] Add the cabal-gh5213 test by RyanGlScott --- .../Regression/T5213/cabal-gh5213.cabal | 29 +++++++++++++++++++ .../PackageTests/Regression/T5213/cabal.out | 20 +++++++++++++ .../Regression/T5213/cabal.project | 4 +++ .../Regression/T5213/cabal.test.hs | 2 ++ .../T5213/src/CabalGH5213Exposed.hs | 6 ++++ .../Regression/T5213/src/CabalGH5213Other.hs | 4 +++ .../Regression/T5213/tests/Main.hs | 6 ++++ 7 files changed, 71 insertions(+) create mode 100644 cabal-testsuite/PackageTests/Regression/T5213/cabal-gh5213.cabal create mode 100644 cabal-testsuite/PackageTests/Regression/T5213/cabal.out create mode 100644 cabal-testsuite/PackageTests/Regression/T5213/cabal.project create mode 100644 cabal-testsuite/PackageTests/Regression/T5213/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T5213/src/CabalGH5213Exposed.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T5213/src/CabalGH5213Other.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T5213/tests/Main.hs diff --git a/cabal-testsuite/PackageTests/Regression/T5213/cabal-gh5213.cabal b/cabal-testsuite/PackageTests/Regression/T5213/cabal-gh5213.cabal new file mode 100644 index 00000000000..1f27196421e --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5213/cabal-gh5213.cabal @@ -0,0 +1,29 @@ +-- Initial cabal-gh5213.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/ + +name: cabal-gh5213 +version: 0.1 +-- synopsis: +-- description: +license: BSD3 +author: Ryan Scott +maintainer: ryan.gl.scott@gmail.com +-- copyright: +category: Testing +build-type: Simple +cabal-version: >=1.10 + +library + exposed-modules: CabalGH5213Exposed + other-modules: CabalGH5213Other + -- other-extensions: + build-depends: base >= 4 && < 5 + hs-source-dirs: src + default-language: Haskell2010 + +test-suite tests + main-is: Main.hs + type: exitcode-stdio-1.0 + build-depends: base, cabal-gh5213 + hs-source-dirs: tests + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/Regression/T5213/cabal.out b/cabal-testsuite/PackageTests/Regression/T5213/cabal.out new file mode 100644 index 00000000000..2605a5c60eb --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5213/cabal.out @@ -0,0 +1,20 @@ +# cabal new-test +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - cabal-gh5213-0.1 (lib) (first run) + - cabal-gh5213-0.1 (test:tests) (first run) +Configuring library for cabal-gh5213-0.1.. +Preprocessing library for cabal-gh5213-0.1.. +Building library for cabal-gh5213-0.1.. +Configuring test suite 'tests' for cabal-gh5213-0.1.. +Warning: The package has an extraneous version range for a dependency on an internal library: cabal-gh5213 >=0 && ==0.1. This version range includes the current package but isn't needed as the current package's library will always be used. +Preprocessing test suite 'tests' for cabal-gh5213-0.1.. +Building test suite 'tests' for cabal-gh5213-0.1.. +Running 1 test suites... +Test suite tests: RUNNING... +Test suite tests: PASS +Test suite logged to: /cabal.dist/work/./dist/build//ghc-/cabal-gh5213-0.1/t/tests/test/cabal-gh5213-0.1-tests.log +Test coverage report written to /cabal.dist/work/./dist/build//ghc-/cabal-gh5213-0.1/t/tests/hpc/vanilla/html/tests/hpc_index.html +1 of 1 test suites (1 of 1 test cases) passed. +Package coverage report written to /cabal.dist/work/./dist/build//ghc-/cabal-gh5213-0.1/t/tests/hpc/vanilla/html/cabal-gh5213-0.1/hpc_index.html diff --git a/cabal-testsuite/PackageTests/Regression/T5213/cabal.project b/cabal-testsuite/PackageTests/Regression/T5213/cabal.project new file mode 100644 index 00000000000..e1c33e00303 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5213/cabal.project @@ -0,0 +1,4 @@ +packages: . + +package cabal-gh5213 + library-coverage: true diff --git a/cabal-testsuite/PackageTests/Regression/T5213/cabal.test.hs b/cabal-testsuite/PackageTests/Regression/T5213/cabal.test.hs new file mode 100644 index 00000000000..cbb92ca7473 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5213/cabal.test.hs @@ -0,0 +1,2 @@ +import Test.Cabal.Prelude +main = cabalTest $ cabal "new-test" [] \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/Regression/T5213/src/CabalGH5213Exposed.hs b/cabal-testsuite/PackageTests/Regression/T5213/src/CabalGH5213Exposed.hs new file mode 100644 index 00000000000..becd65eff8b --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5213/src/CabalGH5213Exposed.hs @@ -0,0 +1,6 @@ +module CabalGH5213Exposed where + +import CabalGH5213Other + +foo :: Int +foo = bar diff --git a/cabal-testsuite/PackageTests/Regression/T5213/src/CabalGH5213Other.hs b/cabal-testsuite/PackageTests/Regression/T5213/src/CabalGH5213Other.hs new file mode 100644 index 00000000000..b1194f103cb --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5213/src/CabalGH5213Other.hs @@ -0,0 +1,4 @@ +module CabalGH5213Other where + +bar :: Int +bar = 42 diff --git a/cabal-testsuite/PackageTests/Regression/T5213/tests/Main.hs b/cabal-testsuite/PackageTests/Regression/T5213/tests/Main.hs new file mode 100644 index 00000000000..ee2b00a4d8a --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5213/tests/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import CabalGH5213Exposed + +main :: IO () +main = print foo From 13d5ecdfde2d952f73545ba56401c5f86899c118 Mon Sep 17 00:00:00 2001 From: Mikolaj Konarski Date: Sat, 24 Jul 2021 23:39:43 +0200 Subject: [PATCH 4/7] Add changelog --- changelog.d/pr-7493 | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 changelog.d/pr-7493 diff --git a/changelog.d/pr-7493 b/changelog.d/pr-7493 new file mode 100644 index 00000000000..00f3033c1c2 --- /dev/null +++ b/changelog.d/pr-7493 @@ -0,0 +1,10 @@ +synopsis: Fix `cabal test --enable-library-coverage` for other-modules +packages: Cabal +prs: #7493 +issues: #5213 +description: { + +- Fix `cabal test --enable-library-coverage` for libraries with nonempty other-modules field. +- Due to a hack, this breaks coverage whenever the used Haskell compiler is called 't' (for a non-hacky fix we should rework HPC directories, possibly enabling multilib in the process, see #6440 and #6397). + +} From 596e89bbf38e425408e7aafe7293a28977db9930 Mon Sep 17 00:00:00 2001 From: Mikolaj Konarski Date: Mon, 26 Jul 2021 23:23:07 +0200 Subject: [PATCH 5/7] Extend the comment about the hack --- Cabal/src/Distribution/Simple/Hpc.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Cabal/src/Distribution/Simple/Hpc.hs b/Cabal/src/Distribution/Simple/Hpc.hs index ae4fb7c122a..0a9fe964831 100644 --- a/Cabal/src/Distribution/Simple/Hpc.hs +++ b/Cabal/src/Distribution/Simple/Hpc.hs @@ -71,8 +71,13 @@ mixDir :: FilePath -- ^ \"dist/\" prefix mixDir distPref way name = hpcDir distPrefBuild way "mix" name where -- This is a hack for HPC over test suites, needed to match the directory - -- where HPC stores .mix files when the main library of the same package - -- is being processed, perhaps in a previous cabal run (#5213). + -- where HPC saves and reads .mix files when the main library of the same + -- package is being processed, perhaps in a previous cabal run (#5213). + -- E.g., @distPref@ may be + -- @./dist-newstyle/build/x86_64-linux/ghc-9.0.1/cabal-gh5213-0.1/t/tests@ + -- but the path where library mix files reside has two less components + -- at the end (@t/tests@) and this reduced path needs to be passed to + -- both @hpc@ and @ghc@. distPrefElements = splitDirectories distPref distPrefBuild = case drop (length distPrefElements - 2) distPrefElements of "t" : _ -> joinPath $ take (length distPrefElements - 2) distPrefElements From 54f218567b1ca0db8909f104ab29922fc48f58bd Mon Sep 17 00:00:00 2001 From: Mikolaj Konarski Date: Wed, 28 Jul 2021 12:47:38 +0200 Subject: [PATCH 6/7] Add a test for #5213 with coverage instead of library-coverage and with `optimization: False`. --- .../T5213ExeCoverage/cabal-gh5213.cabal | 29 +++++++++++++++++++ .../Regression/T5213ExeCoverage/cabal.out | 20 +++++++++++++ .../Regression/T5213ExeCoverage/cabal.project | 5 ++++ .../Regression/T5213ExeCoverage/cabal.test.hs | 2 ++ .../src/CabalGH5213Exposed.hs | 6 ++++ .../T5213ExeCoverage/src/CabalGH5213Other.hs | 4 +++ .../Regression/T5213ExeCoverage/tests/Main.hs | 6 ++++ 7 files changed, 72 insertions(+) create mode 100644 cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal-gh5213.cabal create mode 100644 cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.out create mode 100644 cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.project create mode 100644 cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/src/CabalGH5213Exposed.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/src/CabalGH5213Other.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/tests/Main.hs diff --git a/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal-gh5213.cabal b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal-gh5213.cabal new file mode 100644 index 00000000000..1f27196421e --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal-gh5213.cabal @@ -0,0 +1,29 @@ +-- Initial cabal-gh5213.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/ + +name: cabal-gh5213 +version: 0.1 +-- synopsis: +-- description: +license: BSD3 +author: Ryan Scott +maintainer: ryan.gl.scott@gmail.com +-- copyright: +category: Testing +build-type: Simple +cabal-version: >=1.10 + +library + exposed-modules: CabalGH5213Exposed + other-modules: CabalGH5213Other + -- other-extensions: + build-depends: base >= 4 && < 5 + hs-source-dirs: src + default-language: Haskell2010 + +test-suite tests + main-is: Main.hs + type: exitcode-stdio-1.0 + build-depends: base, cabal-gh5213 + hs-source-dirs: tests + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.out b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.out new file mode 100644 index 00000000000..2605a5c60eb --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.out @@ -0,0 +1,20 @@ +# cabal new-test +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - cabal-gh5213-0.1 (lib) (first run) + - cabal-gh5213-0.1 (test:tests) (first run) +Configuring library for cabal-gh5213-0.1.. +Preprocessing library for cabal-gh5213-0.1.. +Building library for cabal-gh5213-0.1.. +Configuring test suite 'tests' for cabal-gh5213-0.1.. +Warning: The package has an extraneous version range for a dependency on an internal library: cabal-gh5213 >=0 && ==0.1. This version range includes the current package but isn't needed as the current package's library will always be used. +Preprocessing test suite 'tests' for cabal-gh5213-0.1.. +Building test suite 'tests' for cabal-gh5213-0.1.. +Running 1 test suites... +Test suite tests: RUNNING... +Test suite tests: PASS +Test suite logged to: /cabal.dist/work/./dist/build//ghc-/cabal-gh5213-0.1/t/tests/test/cabal-gh5213-0.1-tests.log +Test coverage report written to /cabal.dist/work/./dist/build//ghc-/cabal-gh5213-0.1/t/tests/hpc/vanilla/html/tests/hpc_index.html +1 of 1 test suites (1 of 1 test cases) passed. +Package coverage report written to /cabal.dist/work/./dist/build//ghc-/cabal-gh5213-0.1/t/tests/hpc/vanilla/html/cabal-gh5213-0.1/hpc_index.html diff --git a/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.project b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.project new file mode 100644 index 00000000000..ee157cb0f02 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.project @@ -0,0 +1,5 @@ +packages: . + +package cabal-gh5213 + coverage: True + optimization: False \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.test.hs b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.test.hs new file mode 100644 index 00000000000..cbb92ca7473 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.test.hs @@ -0,0 +1,2 @@ +import Test.Cabal.Prelude +main = cabalTest $ cabal "new-test" [] \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/src/CabalGH5213Exposed.hs b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/src/CabalGH5213Exposed.hs new file mode 100644 index 00000000000..becd65eff8b --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/src/CabalGH5213Exposed.hs @@ -0,0 +1,6 @@ +module CabalGH5213Exposed where + +import CabalGH5213Other + +foo :: Int +foo = bar diff --git a/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/src/CabalGH5213Other.hs b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/src/CabalGH5213Other.hs new file mode 100644 index 00000000000..b1194f103cb --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/src/CabalGH5213Other.hs @@ -0,0 +1,4 @@ +module CabalGH5213Other where + +bar :: Int +bar = 42 diff --git a/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/tests/Main.hs b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/tests/Main.hs new file mode 100644 index 00000000000..ee2b00a4d8a --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/tests/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import CabalGH5213Exposed + +main :: IO () +main = print foo From ee0ce41f702664c7a8ddb16da6858d2dd489c52e Mon Sep 17 00:00:00 2001 From: Mikolaj Konarski Date: Wed, 28 Jul 2021 17:34:48 +0200 Subject: [PATCH 7/7] Extend the .mix path hack to -O0 and -O2 --- Cabal/src/Distribution/Simple/Hpc.hs | 15 ++++++++++++--- .../Regression/T5213ExeCoverage/cabal.out | 6 +++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Cabal/src/Distribution/Simple/Hpc.hs b/Cabal/src/Distribution/Simple/Hpc.hs index 0a9fe964831..4e292509d78 100644 --- a/Cabal/src/Distribution/Simple/Hpc.hs +++ b/Cabal/src/Distribution/Simple/Hpc.hs @@ -77,10 +77,19 @@ mixDir distPref way name = hpcDir distPrefBuild way "mix" name -- @./dist-newstyle/build/x86_64-linux/ghc-9.0.1/cabal-gh5213-0.1/t/tests@ -- but the path where library mix files reside has two less components -- at the end (@t/tests@) and this reduced path needs to be passed to - -- both @hpc@ and @ghc@. + -- both @hpc@ and @ghc@. For non-default optimization levels, the path + -- suffix is one element longer and the extra path element needs + -- to be preserved. distPrefElements = splitDirectories distPref - distPrefBuild = case drop (length distPrefElements - 2) distPrefElements of - "t" : _ -> joinPath $ take (length distPrefElements - 2) distPrefElements + distPrefBuild = case drop (length distPrefElements - 3) distPrefElements of + ["t", _, "noopt"] -> + joinPath $ take (length distPrefElements - 3) distPrefElements + ++ ["noopt"] + ["t", _, "opt"] -> + joinPath $ take (length distPrefElements - 3) distPrefElements + ++ ["opt"] + [_, "t", _] -> + joinPath $ take (length distPrefElements - 2) distPrefElements _ -> distPref tixDir :: FilePath -- ^ \"dist/\" prefix diff --git a/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.out b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.out index 2605a5c60eb..30f8a730dc9 100644 --- a/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.out +++ b/cabal-testsuite/PackageTests/Regression/T5213ExeCoverage/cabal.out @@ -14,7 +14,7 @@ Building test suite 'tests' for cabal-gh5213-0.1.. Running 1 test suites... Test suite tests: RUNNING... Test suite tests: PASS -Test suite logged to: /cabal.dist/work/./dist/build//ghc-/cabal-gh5213-0.1/t/tests/test/cabal-gh5213-0.1-tests.log -Test coverage report written to /cabal.dist/work/./dist/build//ghc-/cabal-gh5213-0.1/t/tests/hpc/vanilla/html/tests/hpc_index.html +Test suite logged to: /cabal.dist/work/./dist/build//ghc-/cabal-gh5213-0.1/t/tests/noopt/test/cabal-gh5213-0.1-tests.log +Test coverage report written to /cabal.dist/work/./dist/build//ghc-/cabal-gh5213-0.1/t/tests/noopt/hpc/vanilla/html/tests/hpc_index.html 1 of 1 test suites (1 of 1 test cases) passed. -Package coverage report written to /cabal.dist/work/./dist/build//ghc-/cabal-gh5213-0.1/t/tests/hpc/vanilla/html/cabal-gh5213-0.1/hpc_index.html +Package coverage report written to /cabal.dist/work/./dist/build//ghc-/cabal-gh5213-0.1/t/tests/noopt/hpc/vanilla/html/cabal-gh5213-0.1/hpc_index.html