Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doctest: Ambiguous module name #1231

Open
hololeap opened this issue Oct 31, 2021 · 4 comments
Open

doctest: Ambiguous module name #1231

hololeap opened this issue Oct 31, 2021 · 4 comments

Comments

@hololeap
Copy link
Member

hololeap commented Oct 31, 2021

When compiling dhall-1.40.1 I hit this error when doctest is run:

 * >>> Test phase [cabal test]: dev-lang/dhall-1.40.1
./setup test --show-details=streaming
Running 2 test suites...
Test suite doctest: RUNNING...

/var/tmp/portage/dev-lang/dhall-1.40.1/work/dhall-1.40.1/ghc-src/Dhall/Crypto.hs:16:1: error:
    Ambiguous module name ‘Crypto.Hash’:
      it was found in multiple packages: cryptonite-0.28 hashing-0.1.0.1
   |
16 | import Crypto.Hash             (SHA256)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/var/tmp/portage/dev-lang/dhall-1.40.1/work/dhall-1.40.1/ghc-src/Dhall/Crypto.hs:22:1: error:
    Ambiguous module name ‘Crypto.Hash’:
      it was found in multiple packages: cryptonite-0.28 hashing-0.1.0.1
   |
22 | import qualified Crypto.Hash
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Test suite doctest: FAIL
Test suite logged to: dist/test/dhall-1.40.1-doctest.log

What is strange about this is that hashing is not mentioned anywhere in the package, but it is installed on my system. There are no such issues when the compile phase is run.

@hololeap
Copy link
Member Author

$ cabal unpack dhall-1.40.1
$ cd dhall-1.40.1
$ cabal build
$ cabal test

I just tried this and got the same error, so it's probably a bug with doctest.

@hololeap
Copy link
Member Author

This old doctest bug looks relevant.

hololeap added a commit to hololeap/gentoo-haskell that referenced this issue Oct 31, 2021
Add patches:

`dhall-1.40.1-disable-http-tests.patch`
* Disable tests that depend on connecting to the internet

`dhall-1.40.1-package-imports.patch`
* doctest pulls in the out-of-scope package `hashing` if it is installed
  on the system. A workaround is to use PackageImports to force
  importing from `cryptonite`.
* Bug: gentoo-haskell#1231

`dhall-1.40.1-disable-buggy-tests.patch`
* Disable buggy tests
  * success/unit/asLocation/RemoteChainEnvA.dhall

Package-Manager: Portage-3.0.20, Repoman-3.0.3
Signed-off-by: hololeap <hololeap@users.noreply.github.com>
@hololeap hololeap changed the title doctest pulls in out-of-scope packages doctest: Ambiguous module name Oct 31, 2021
hololeap added a commit to hololeap/gentoo-haskell that referenced this issue Nov 7, 2021
Added patches:

dhall-docs-1.0.7-disable-tasty-tests.patch
* These tests are buggy, relying on missing imports and failing due to
  "golden" tests with out-of-order elements.

dhall-docs-1.0.7-package-imports.patch
* doctest pulls in the out-of-scope package `hashing` if it is installed
  on the system. A workaround is to use PackageImports to force
  importing from `cryptonite`.
* Bug: gentoo-haskell#1231

dhall-docs-1.0.7-remove-hashable-dep.patch
* Bug has been fixed upstream so hashable is no longer needed as a
  dependency.
* chrisdone/lucid#107
* Unused currently since tasty tests are disabled.

Package-Manager: Portage-3.0.20, Repoman-3.0.3
Signed-off-by: hololeap <hololeap@users.noreply.github.com>
hololeap added a commit that referenced this issue Jan 15, 2022
`iproute-1.7.12-package-imports.patch`
* Ambiguous module name ‘System.ByteOrder’ is found in multiple packages:
  byte-order byteorder
* Use PackageImports extension as a workaround
* Bug: #1231

Package-Manager: Portage-3.0.28, Repoman-3.0.3
Signed-off-by: hololeap <hololeap@users.noreply.github.com>
@hololeap
Copy link
Member Author

I discovered a much better solution to this problem: Patch the package to use cabal-doctest instead of using PackageImports.

cabal-doctest has some example packages in their repo. Here is a simple example of how to patch a package for gentoo-haskell:

diff -urN dhall-docs-1.0.8/Setup.hs dhall-docs-1.0.8-r1/Setup.hs
--- dhall-docs-1.0.8/Setup.hs	2001-09-08 19:46:40.000000000 -0600
+++ dhall-docs-1.0.8-r1/Setup.hs	2022-02-10 12:12:45.208325158 -0700
@@ -1,2 +1,6 @@
-import Distribution.Simple
-main = defaultMain
+module Main (main) where
+
+import Distribution.Extra.Doctest ( defaultMainWithDoctests )
+
+main :: IO ()
+main = defaultMainWithDoctests "doctest"
diff -urN dhall-docs-1.0.8/dhall-docs.cabal dhall-docs-1.0.8-r1/dhall-docs.cabal
--- dhall-docs-1.0.8/dhall-docs.cabal	2022-02-10 12:06:27.209021249 -0700
+++ dhall-docs-1.0.8-r1/dhall-docs.cabal	2022-02-10 12:12:29.418354235 -0700
@@ -2,7 +2,7 @@
 Version: 1.0.8
 x-revision: 2
 Cabal-Version: >=1.10
-Build-Type: Simple
+Build-Type: Custom
 License: BSD3
 License-File: LICENSE
 Copyright: 2020 Germán Robayo
@@ -59,6 +59,13 @@
   description: To enable use of data-files while running `stack ghci`
   default: False
 
+
+custom-setup
+  setup-depends:
+      base
+    , Cabal
+    , cabal-doctest
+
 Library
     Hs-Source-Dirs: src
     Build-Depends:
@@ -123,6 +130,8 @@
         base                           ,
         directory,
         filepath                 < 1.5 ,
+        base-compat,
+        cabal-doctest,
         doctest    >= 0.7.0
     Other-Extensions: OverloadedStrings RecordWildCards
     Default-Language: Haskell2010
diff -urN dhall-docs-1.0.8/doctest/Main.hs dhall-docs-1.0.8-r1/doctest/Main.hs
--- dhall-docs-1.0.8/doctest/Main.hs	2001-09-08 19:46:40.000000000 -0600
+++ dhall-docs-1.0.8-r1/doctest/Main.hs	2022-02-10 12:14:39.408114856 -0700
@@ -6,13 +6,24 @@
 import qualified System.Directory
 import qualified System.IO
 import qualified Test.DocTest
+import Build_doctests (pkgs)
 
 main :: IO ()
 main = do
     GHC.IO.Encoding.setLocaleEncoding System.IO.utf8
     pwd    <- System.Directory.getCurrentDirectory
     prefix <- System.Directory.makeAbsolute pwd
-    Test.DocTest.doctest
-        [ "--fast"
-        , prefix </> "src"
-        ]
+
+    let customFlags =
+            [ "-package-env=-"
+            , "-hide-all-packages"
+            , "-no-user-package-db"
+            , "-package-db=" ++ prefix </> "dist/package.conf.inplace"
+            ]
+
+    let origArgs = 
+            [ "--fast"
+            , prefix </> "src"
+            ]
+
+    Test.DocTest.doctest $ customFlags ++ pkgs ++ origArgs

@hololeap hololeap reopened this Mar 16, 2022
@hololeap
Copy link
Member Author

Related: #1270

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant