pwm / nixkell

A simple Nix-Haskell skeleton
MIT License
92 stars 11 forks source link

`cabal test` does not work #15

Closed abhin4v closed 2 years ago

abhin4v commented 2 years ago

cabal test command does not work with a fresh clone of the repo. However, cabal v1-test does work:

abhinav@Abhinavs-MacBook-Pro /tmp> git clone https://github.com/pwm/nixkell.git world && cd world
Cloning into 'world'...
remote: Enumerating objects: 295, done.
remote: Counting objects: 100% (124/124), done.
remote: Compressing objects: 100% (71/71), done.
remote: Total 295 (delta 58), reused 89 (delta 42), pack-reused 171
Receiving objects: 100% (295/295), 2.46 MiB | 6.24 MiB/s, done.
Resolving deltas: 100% (153/153), done.

abhinav@Abhinavs-MacBook-Pro /t/world (master)> ./init.sh
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint:   git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint:   git branch -m <name>
Initialized empty Git repository in /private/tmp/world/.git/
direnv: loading /private/tmp/world/.envrc
direnv: using nix
direnv: ([/usr/local/bin/direnv export fish]) is taking a while to execute. Use CTRL-C to give up.
/nix/store/m9q5xr4adr9jn25p88p1vn9hpijl865r-world-env/bin/logo: line 3: tput: command not found
/nix/store/m9q5xr4adr9jn25p88p1vn9hpijl865r-world-env/bin/logo: line 5: tput: command not found

_   _ _      _        _ _
| \ | (_)_  _| | _____| | |
|  \| | \ \/ / |/ / _ \ | |
| |\  | |>  <|   <  __/ | |
|_| \_|_/_/\_\_|\_\___|_|_|

direnv: eval /private/tmp/world/.direnv/cache-pre335173.56cbe42f166
direnv: renewed cache and derivation link
direnv: export +AR +AS +CC +CONFIG_SHELL +CXX +HOST_PATH +IN_NIX_SHELL +LD +LD_DYLD_PATH +LD_LIBRARY_PATH +MACOSX_DEPLOYMENT_TARGET +NIX_BINTOOLS +NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_apple_darwin +NIX_BUILD_CORES +NIX_BUILD_TOP +NIX_CC +NIX_CC_WRAPPER_TARGET_HOST_x86_64_apple_darwin +NIX_CFLAGS_COMPILE +NIX_COREFOUNDATION_RPATH +NIX_DONT_SET_RPATH +NIX_DONT_SET_RPATH_FOR_BUILD +NIX_ENFORCE_NO_NATIVE +NIX_HARDENING_ENABLE +NIX_IGNORE_LD_THROUGH_GCC +NIX_INDENT_MAKE +NIX_LDFLAGS +NIX_NO_SELF_RPATH +NIX_STORE +NM +PATH_LOCALE +RANLIB +SIZE +SOURCE_DATE_EPOCH +STRINGS +STRIP +TEMP +TEMPDIR +TMP +XDG_DATA_DIRS +__ETC_PROFILE_SOURCED +__darwinAllowLocalNetworking +__impureHostDeps +__propagatedImpureHostDeps +__propagatedSandboxProfile +__sandboxProfile +buildInputs +builder +configureFlags +depsBuildBuild +depsBuildBuildPropagated +depsBuildTarget +depsBuildTargetPropagated +depsHostHost +depsHostHostPropagated +depsTargetTarget +depsTargetTargetPropagated +doCheck +doInstallCheck +gl_cv_func_getcwd_abort_bug +name +nativeBuildInputs +nobuildPhase +out +outputs +patches +phases +propagatedBuildInputs +propagatedNativeBuildInputs +shell +shellHook +stdenv +strictDeps +system ~PATH ~XPC_SERVICE_NAME

abhinav@Abhinavs-MacBook-Pro /t/world (master)> hpack
generated world.cabal

abhinav@Abhinavs-MacBook-Pro /t/world (master)> cabal test
Warning: The package list for 'hackage.haskell.org' does not exist. Run 'cabal
update' to download it.RemoteRepo {remoteRepoName = RepoName
"hackage.haskell.org", remoteRepoURI = http://hackage.haskell.org/,
remoteRepoSecure = Just True, remoteRepoRootKeys =
["fe331502606802feac15e514d9b9ea83fee8b6ffef71335479a2e68d84adc6b0","1ea9ba32c526d1cc91ab5e5bd364ec5e9e8cb67179a471872f6e26f0ae773d42","2c6c3627bd6c982990239487f1abd02e08a02e6cf16edb105a8012d444d870c3","0a5c7ea47cd1b15f01f5f51a33adda7e655bc0f0b0615baa8e271f4c3351e21d","51f0161b906011b52c6613376b1ae937670da69322113a246a09f807c62f6921"],
remoteRepoKeyThreshold = 3, remoteRepoShouldTryHttps = True}
Resolving dependencies...
cabal: Cannot test the package world-0.1.0.0 because none of the components
are available to build: the test suite 'spec' is not available because the
solver did not find a plan that included the test suites. Force the solver to
enable this for all packages by adding the line 'tests: True' to the
'cabal.project.local' file.

abhinav@Abhinavs-MacBook-Pro /t/world (master) [1]> cabal v1-test
Warning: The package list for 'hackage.haskell.org' does not exist. Run 'cabal
update' to download it.RemoteRepo {remoteRepoName = RepoName
"hackage.haskell.org", remoteRepoURI = http://hackage.haskell.org/,
remoteRepoSecure = Just True, remoteRepoRootKeys =
["fe331502606802feac15e514d9b9ea83fee8b6ffef71335479a2e68d84adc6b0","1ea9ba32c526d1cc91ab5e5bd364ec5e9e8cb67179a471872f6e26f0ae773d42","2c6c3627bd6c982990239487f1abd02e08a02e6cf16edb105a8012d444d870c3","0a5c7ea47cd1b15f01f5f51a33adda7e655bc0f0b0615baa8e271f4c3351e21d","51f0161b906011b52c6613376b1ae937670da69322113a246a09f807c62f6921"],
remoteRepoKeyThreshold = 3, remoteRepoShouldTryHttps = True}
Resolving dependencies...
Configuring world-0.1.0.0...
Preprocessing library for world-0.1.0.0..
Building library for world-0.1.0.0..
[1 of 1] Compiling Paths_world      ( dist/build/autogen/Paths_world.hs, dist/build/Paths_world.o, dist/build/Paths_world.dyn_o )
Preprocessing test suite 'spec' for world-0.1.0.0..
Building test suite 'spec' for world-0.1.0.0..
[1 of 2] Compiling Main             ( test/Spec.hs, dist/build/spec/spec-tmp/Main.o )
[2 of 2] Compiling Paths_world      ( dist/build/spec/autogen/Paths_world.hs, dist/build/spec/spec-tmp/Paths_world.o )
Linking dist/build/spec/spec ...
Running 1 test suites...
Test suite spec: RUNNING...
Test suite spec: PASS
Test suite logged to: dist/test/world-0.1.0.0-spec.log
1 of 1 test suites (1 of 1 test cases) passed.

cabal build works fine though.

pwm commented 2 years ago

Hi @abhin4v and thanks for opening the issue. I tried but could not reproduce it (which admittedly is a rather funny thing to write in a nix project). I'll look into this in more detail after the holidays. Thanks again for the report.

abhin4v commented 2 years ago

This is on OSX if that matters. I also tried this in an existing Haskell project in which I copied nixkell generated files to nixify it. The same issue happens there, cabal test doesn't run but cabal v1-test works fine.

abhin4v commented 2 years ago

FWIW, I have verified this behaviour on NixOS as well. Please note that I'm running the commands with no ~/.cabal directory, as it should not be needed when I'm using nix.

abhin4v commented 2 years ago

FYI, this issue seems to be because of cabal not finding the hspec-discover executable. See https://github.com/kenranunderscore/hspec-discover-repro for reference. What worked for me was to remove hspec-discover and list the specs directly.

pwm commented 2 years ago

@abhin4v sorted it now, sorry it took so long. It was indeed using build-tool-depends for hspec-discover which I removed. hspec seem to bring hspec-discover as a transitive dependency even without it so no breakage as far as I can tell:

~/w/foo (master) $ rg hspec package.yaml
78:      - hspec
~/w/foo (master) $ ghc-pkg list | rg hspec
    hspec-2.7.10
    hspec-core-2.7.10
    (hspec-discover-2.7.10)
    hspec-expectations-0.8.2
~/w/foo (master) $ type -p hspec-discover
/nix/store/lyaipip0mn5q8dbzfyd8dld7s0zxiy6g-aoc2021-env/bin/hspec-discover

Also added active-repositories: none to cabal.project to make sure it does not do any sneaky dependency management.