yesod test - missing dependency yesod-test - haskell

I was setting up a yesod scaffolded site using the yesod init command, and I named my project yesodtry. I proceeded to setup a scaffolded site using this command, which was given by yesod init:
cd yesodtry && cabal sandbox init && cabal install && yesod devel
Everything went smoothly, and I accessed the demo site at 127.0.0.1:3000. Out of curiosity, I tried to try the yesod test command. Here's the output I got:
Resolving dependencies...
Configuring yesodtry-0.0.0...
cabal: At least the following dependencies are missing:
hspec -any, yesod-test ==1.2.*
Seeing how the yesodtry.cabal file has a test section, I tried executing cabal build test, and this is the output:
cabal: Cannot build the test suite 'test' because test suites are not enabled.
Run configure with the flag --enable-tests
Ok... so it tells me to run cabal configure --enable-tests. And here's the output:
Resolving dependencies...
Configuring yesodtry-0.0.0...
cabal: At least the following dependencies are missing:
hspec -any, yesod-test ==1.2.*
I see this line in yesodtry.cabal, for the build-depends of the test-suite test "section":
yesod-test >= 1.2 && < 1.3
It seems like cabal is not installing the dependencies here. How do I do that?
Thank you.

Ok, I think I found the answer on this Haskell-cafe thread.
We have to do:
cabal configure --enable-tests
cabal install --only-dependencies --enable-tests
And the dependencies for the test-suite test section will be installed.
I then ran yesod test, and here's the last few lines of the output:
Linking dist/build/test/test ...
Building yesodtry-0.0.0...
Preprocessing library yesodtry-0.0.0...
In-place registering yesodtry-0.0.0...
Preprocessing test suite 'test' for yesodtry-0.0.0...
Linking dist/build/test/test ...
Running 1 test suites...
Test suite test: RUNNING...
Test suite test: PASS
Test suite logged to: dist/test/yesodtry-0.0.0-test.log
1 of 1 test suites (1 of 1 test cases) passed.
Hopefully this will help anyone who encounters the same problem in the future.

Related

Cannot build project with z3-haskell on windows 10

I want to build the haskell bindings for z3 in a Cabal project, the following is the minimum (faulty) example:
Using a project initialized by cabal init:
test/
- Main.hs
- Setup.hs
- CHANGELOG.md
- test.cabal
With modified test.cabal:
cabal-version: 3.0
name: z3-test
version: 0.1.0.0
extra-source-files: CHANGELOG.md
executable test
main-is: Main.hs
build-depends: base >=4.14 && <4.15
, z3 ^>=408.2
default-language: Haskell2010
Z3 binaries are located at C:\z3-4.8.5-x86-win.
Z3-bindings are installed:
cabal v1-install z3 --extra-lib-dirs=C:/z3-4.8.5-x64-win/bin --extra-include-dirs=C:/z3-4.8.5-x64-win/include -v3
All the requested packages are already installed:
z3-408.2
Use --reinstall if you want to reinstall anyway.
Now building the project using:
cabal v2-build --extra-lib-dirs=C:/z3-4.8.5-x64-win/bin --extra-include-dirs=C:/z3-4.8.5-x64-win/include -v3
Results in the error:
Build profile: -w ghc-8.10.2 -O1
In order, the following will be built (use -v for more details):
- z3-408.2 (lib) (requires build)
- z3-test-0.1.0.0 (exe:test) (first run)
Starting z3-408.2 (lib)
Failed to build z3-408.2. The failure occurred during the configure step.
Build log (
C:\cabal\logs\ghc-8.10.2\z3-408.2-1722a25655334afbca91ac935f14ff0d20ccf8c4.log
):
Configuring library for z3-408.2..
cabal.exe: Missing dependency on a foreign library:
* Missing (or bad) header file: z3.h
* Missing (or bad) C library: z3
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the
library file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.
If the header file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.
cabal.exe: Failed to build z3-408.2 (which is required by exe:test from
z3-test-0.1.0.0). See the build log above for details.
How can I build a project with the z3 bindings?
Note that:
GHC version = 8.10.2
Cabal version = 3.2.0.0
I can only use cabal
Using cabal install ... or cabal v2-install ... results in Cannot build .. z3 because none of the components are available to build:

flycheck-haskell and doctest don't work on Cabal 3.0 v2-build project

I tried to create a Nix-style local build (v2-build) project on Cabal 3.0.
But several development tools (flycheck-haskell and doctest) don't work.
They worked on new-build project on Cabal 2.4.
Error message says they cannot find dependencies, as far as I read.
$ cabal v2-clean
$ cabal v2-build
$ cabal v2-test
Build profile: -w ghc-8.8.1 -O1
In order, the following will be built (use -v for more details):
- hstest9-0.1.0.0 (test:doctestd) (first run)
Configuring test suite 'doctestd' for hstest9-0.1.0.0..
Preprocessing test suite 'doctestd' for hstest9-0.1.0.0..
Building test suite 'doctestd' for hstest9-0.1.0.0..
[1 of 1] Compiling Main ( test/doctest-driver.hs, /Users/user/work/hstest9/dist-newstyle/build/x86_64-osx/ghc-8.8.1/hstest9-0.1.0.0/t/doctestd/build/doctestd/doctestd-tmp/Main.o )
Linking /Users/user/work/hstest9/dist-newstyle/build/x86_64-osx/ghc-8.8.1/hstest9-0.1.0.0/t/doctestd/build/doctestd/doctestd ...
Running 1 test suites...
Test suite doctestd: RUNNING...
/Users/user/work/hstest9/src/MyLib.hs:3:1: error:
Could not find module ‘Control.Effect’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import Control.Effect
| ^^^^^^^^^^^^^^^^^^^^^
Test suite doctestd: FAIL
Test suite logged to:
/Users/user/work/hstest9/dist-newstyle/build/x86_64-osx/ghc-8.8.1/hstest9-0.1.0.0/t/doctestd/test/hstest9-0.1.0.0-doctestd.log
0 of 1 test suites (0 of 1 test cases) passed.
cabal: Tests failed for test:doctestd from hstest9-0.1.0.0.
Your doctest doesn't find proper GHC_ENVIRONEMNT.
Since Cabal 3.0, cabal v2-build doesn't generate environment files by default.
Since Cabal 3.0, defaults to never. Before that, defaulted to creating them only when compiling with GHC 8.4.4 and older (GHC 8.4.4 is the first version that supports the -package-env - option that allows ignoring the package environment files).
https://www.haskell.org/cabal/users-guide/nix-local-build.html#cfg-field-write-ghc-environment-files
So you should set this option on v2-build.
$ cabal v2-build --write-ghc-environment-files=ghc8.4.4+
Or you can write this in $HOME/.cabal/config for default cabal behavior.
write-ghc-environment-files: ghc8.4.4+

Generate coverage report with stack

I want to generate code coverage report using Stack. I run command that
amounts to (omitting options passed to test suite via --test-arguments):
$ stack test --coverage
This performs the testing and then outputs the following:
Error: The coverage report for myproject's test-suite "tests" did not
consider any code. One possible cause of this is if your test-suite builds
the library code (see stack issue #1008). It may also indicate a bug in
stack or the hpc program. Please report this issue if you think your
coverage report should have meaningful results.
I think it should (this creates empty report). GHC options are identical for
all components of my package. There is no need for test suite to rebuild the
library. After all, if Cabal can generate the report, Stack should be able
to do it given the same Cabal config or am I mistaken?
I've opened
an issue on Stack
GitHub repo as suggested.
After a while I decided to create good old sandbox and generate the report
using Cabal instead (I really need to see the report, you know). It worked
previously, but now I get:
$ cabal sandbox init
… <everything OK>
$ cabal update
… <everything OK>
$ cabal install --only-dependencies --enable-tests
… <everything OK>
$ cabal configure --enable-tests --enable-coverage
… <everything OK>
$ cabal build
… <everything OK>
$ cabal test
Running 2 test suites...
Test suite tests: RUNNING...
Test suite tests: PASS
Test suite logged to: dist/test/myproject-0.1.0-tests.log
hpc: can not find HUnit_DDLSMCRs3jyLBDbJPCH01j/Test.HUnit.Lang in ["./.hpc","./dist/hpc/vanilla/mix/myproject-0.1.0","./dist/hpc/vanilla/mix/tests"]
What? I've never seen this, although I generated many reports
before. Someone up there just decided that I won't get that report today,
it seems.
Do you know how to generate coverage report using Stack? Has anyone
succeeded at this?
In my case I was still getting this error. Running:
stack clean
stack test --coverage
solved the problem, as reported here.
Recent changes upstream fixed it. Should be resolved for users of 0.1.7.0 and later.

cabal install regex-dfa fails

I'm trying to install the regex-dfa package. I installed other regex packages like regex-tdfa, and they worked fine.
However, when I run sudo cabal install regex-dfa I get an error message:
Resolving dependencies...
[1 of 1] Compiling Main ( /tmp/regex-dfa-0.91-9125/regex-dfa-0.91/Setup.hs, /tmp/regex-dfa-0.91-9125/regex-dfa-0.91/dist/setup/Main.o )
Linking /tmp/regex-dfa-0.91-9125/regex-dfa-0.91/dist/setup/setup ...
Configuring regex-dfa-0.91...
Warning: No 'build-type' specified. If you do not need a custom Setup.hs or
./configure script then use 'build-type: Simple'.
Building regex-dfa-0.91...
Preprocessing library regex-dfa-0.91...
Text/Regex/DFA/Wrap.hs:1:16: Warning:
-fglasgow-exts is deprecated: Use individual extensions instead
<no location info>:
Failing due to -Werror.
Failed to install regex-dfa-0.91
cabal: Error: some packages failed to install:
regex-dfa-0.91 failed during the building phase. The exception was:
ExitFailure 1
What can I do about this?
The package is very old, the last (and the only) upload was in 2007. Don't use it if you can. Or contact the maintainer and ask him to update the package.
To fix this particular issue, you can cabal unpack regex-dfa, remove the -Werror and then cabal install it. But I'm not sure you will get another build error after that.

Haskell Yesod on Windows 7: Launching development server with 'yesod devel' issue

I am very new to Haskell and I am currently using Windows 7 OS.
I am attempting to develop a web service using Haskell framework Yesod. When I execute the yesod devel command to start the development server, I get the following error:
C:\Users\Sticky\workspace\Yesod\testYesod>yesod devel
Yesod devel server. Press ENTER to quit
Resolving dependencies...
Configuring testYesod-0.0.0...
cabal: At least the following dependencies are missing:
data-default -any,
hamlet ==1.1.*,
hjsmin ==0.1.*,
http-conduit >=1.5 && <1.7,
monad-control ==0.3.*,
persistent ==1.0.*,
persistent-sqlite ==1.0.*,
shakespeare-css ==1.0.*,
shakespeare-js ==1.0.*,
shakespeare-text ==1.0.*,
wai-extra ==1.3.*,
warp ==1.3.*,
yaml ==0.8.*,
yesod ==1.1.*,
yesod-auth ==1.1.*,
yesod-core >=1.1.2 && <1.2,
yesod-default ==1.1.*,
yesod-form ==1.1.*,
yesod-static ==1.1.*,
yesod-test ==0.3.*
Rebuilding application...
Forcing recompile for .\Model.hs because of config/models
Forcing recompile for .\Foundation.hs because of config/routes
Forcing recompile for .\Foundation.hs because of messages/en.msg
Forcing recompile for .\Foundation.hs because of templates/default-layout-wrappe
r.hamlet
Forcing recompile for .\Foundation.hs because of templates/default-layout.hamlet
Forcing recompile for .\Handler\Home.hs because of templates/homepage.hamlet
cabal: Run the 'configure' command fBuild failure, pausing...
irst.
I have tried to run cabal configure and this seems to execute fine though I feel I am missing something due to my inexperience, any direction would be much appreciated. I have not been able to find any related questions but again this is likely due to my not knowing exactly what I need to know :)
Looks like the dependencies for your project aren't installed. Run the following commands in your project directory:
# alex at least, possibly also happy, are required by hjsmin
cabal install happy alex
# Make sure alex is on your path, then
cabal install --only-dependencies

Resources