stack build results in "output was redirected with -o, but no output will be generated because there is no Main module." - haskell

Didn't see any relevant result when google searching for this error so thought I'd post it.
stack build
Building all executables for `gitchapter' once. After a successful build of all of them, only specified executables will be rebuilt.
gitchapter-0.1.0.0: build (exe)
Preprocessing executable 'app' for gitchapter-0.1.0.0..
Building executable 'app' for gitchapter-0.1.0.0..
Preprocessing executable 'test' for gitchapter-0.1.0.0..
Warning: Enabling workaround for Main module 'Main' listed in 'other-modules'
Building executable 'test' for gitchapter-0.1.0.0..
illegaly!
<no location info>: error:
output was redirected with -o, but no output will be generated
because there is no Main module.
-- While building custom Setup.hs for package gitchapter-0.1.0.0 using:
/home/chris/.stack/setup-exe-cache/x86_64-linux-nopie/Cabal-simple_mPHDZzAJ_2.0.1.0_ghc-8.2.2 --builddir=.stack-work/dist/x86_64-linux-nopie/Cabal-2.0.1.0 build exe:app exe:test --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
It definitely is related to the 'test' executable definition - as if I remove this, it completes the stack build successfully - but without the required test executable.
gitchapter.cabal
-- This file has been generated from package.yaml by hpack version 0.28.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: a3e4a735ee8304dd50f5af53a64d7b639894cbcc24ba01d0171a588e67455018
name: gitchapter
version: 0.1.0.0
author: Chris Stryczynski
maintainer: Chris Stryczynski
license: BSD3
license-file: LICENSE
build-type: Simple
cabal-version: >= 1.10
executable app
main-is: Main.hs
other-modules:
BlogLiterately
Example
FileSection
GHCi
GHCiSession
Git
GitTextPartial
Hart
Operations
Operations.Parsers
QuasiText
Render
Section
Test
Paths_gitchapter
hs-source-dirs:
src
build-depends:
HUnit
, QuickCheck
, base >=4.9 && <4.11
, directory
, extra
, filepath
, foldl
, mtl
, optparse-applicative
, pandoc-include-code
, parsec
, pretty-simple
, process
, regex-pcre
, regex-posix
, safe
, string-conversions
, system-filepath
, template-haskell
, text
, transformers
, turtle
, unix
, unordered-containers
default-language: Haskell2010
executable test
main-is: Test.hs
other-modules:
BlogLiterately
Example
FileSection
GHCi
GHCiSession
Git
GitTextPartial
Hart
Main
Operations
Operations.Parsers
QuasiText
Render
Section
Paths_gitchapter
hs-source-dirs:
src
build-depends:
HUnit
, QuickCheck
, base >=4.9 && <4.11
, directory
, extra
, filepath
, foldl
, mtl
, optparse-applicative
, pandoc-include-code
, parsec
, pretty-simple
, process
, regex-pcre
, regex-posix
, safe
, string-conversions
, system-filepath
, template-haskell
, text
, transformers
, turtle
, unix
, unordered-containers
default-language: Haskell2010

You need to set
executable test
ghc-options: -main-is Test
in your cabal file.

Related

How to fix a "could not find module" error in Cabal, when it seems correctly specified?

I'm currently not using stack at all on this project (just Cabal), and all was going well when everything was in Main.hs. I decided to split up code, moving my dhall dep and related code from my executable deps to my library deps, and now seem to have this strange error when running cabal new-build:
Building executable 'FarmDataServer.exe' for FarmDataServer-0.1.0.0..
<no location info>: warning: [-Wmissing-home-modules]
These modules are needed for compilation but not listed in your .cabal file's other-modules: FDS
FDS.Config.Core
FDS.Config.DhallConf
[2 of 4] Compiling FDS.Config.DhallConf ( src/FDS/Config/DhallConf.hs, /home/brandon/workspace/CIDA/FarmDataServer/dist-newstyle/buil
d/x86_64-linux/ghc-8.4.4/FarmDataServer-0.1.0.0/x/FarmDataServer.exe/build/FarmDataServer.exe/FarmDataServer.exe-tmp/FDS/Config/Dhall
Conf.o )
src/FDS/Config/DhallConf.hs:7:1: error:
Could not find module `Dhall'
Use -v to see a list of the files searched for.
|
7 | import Dhall
| ^^^^^^^^^^^^^^^^^^^^^^
Certainly I'm also a bit confused by the Wmissing-home-modules message since I seem to have added those in my cabal file.
Relevant bits of my .cabal file:
cabal-version: 2.4
name: FarmDataServer
version: 0.1.0.0
library
exposed-modules:
FDS
other-modules:
FDS.Config.Core
, FDS.Config.DhallConf
build-depends: base ^>=4.11.1.0
, conduit ^>=1.3.1
, csv-conduit ^>=0.7.0.0
, dhall ^>=1.20.0
, text ^>=1.2.3.1
hs-source-dirs: src
executable FarmDataServer.exe
main-is: Main.hs
build-depends: base ^>=4.11.1.0
, conduit ^>=1.3.1
, csv-conduit ^>=0.7.0.0
, scotty ^>=0.11.3
, text ^>=1.2.3.1
, FarmDataServer ^>=0.1.0.0
My src folder:
$ pwd
/home/brandon/workspace/CIDA/FarmDataServer/src
$ du -a
4 ./FDS/Config/DhallConf.hs
4 ./FDS/Config/Core.hs
12 ./FDS/Config
16 ./FDS
4 ./FDS.hs
4 ./Main.hs
28 .
For the missing modules, sink your program executable into a directory such that the module hierarchy for yoru library isn't visible:
mkdir program ; mv src/Main.hs program/
and in cabal for the executable
hs-source-dirs: program
For your missing module Dhall, add the dhall build dependency to your executable stanza in the cabal file.

Not in scope: type constructor or class ‘Test.Framework.TestSuite’ when trying to create unit tests

I'm writing a small library in Haskell, and want to have tests to accompany it. For testing I intend to use HFT, and the project as a whole is managed by stack. stack test fails for some reason with the following output:
[1 of 2] Compiling Main ( test/Ini.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.0.1.0/build/ini-tests/ini-tests-tmp/Main.o ) │····························
[2 of 2] Compiling Paths_schemer ( .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.0.1.0/build/ini-tests/autogen/Paths_schemer.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.0.1.0/build/ini-tests/ini-tests-tm│····························
p/Paths_schemer.o ) │····························
│····························
/stuff/projects/schemer/.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.0.1.0/build/ini-tests/autogen/Paths_schemer.hs:54:39: error: │····························
Not in scope: type constructor or class ‘Test.Framework.TestSuite’ │····························
No module named ‘Test.Framework’ is imported. │····························
│····························
/stuff/projects/schemer/.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.0.1.0/build/ini-tests/autogen/Paths_schemer.hs:55:38: error: │····························
Not in scope: ‘Test.Framework.makeTestSuite’ │····························
No module named ‘Test.Framework’ is imported. │····························
My Ini.hs file that will later contain the tests is very bare-bone, just
import Test.Framework
main :: IO ()
main = htfMain htf_thisModulesTests
My package.yaml is
name: schemer
version: 0.1.0.0
github: "mpevnev/schemer"
license: BSD3
author: "Michail Pevnev"
maintainer: "mpevnev#gmail.com"
copyright: ""
extra-source-files: []
# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web
# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Please see the README on GitHub at <https://github.com/mpevnev/schemer#readme>
dependencies:
- attoparsec
- base >= 4.7 && < 5
- text
library:
source-dirs: src
tests:
ini-tests:
main: Ini.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
- -F
- -pgmF htfpp
dependencies:
- schemer
- text
- HTF
Here's the autogenerated schemer.cabal:
-- This file has been generated from package.yaml by hpack version 0.28.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: 17ae623236b8f5b101f56373c975656e898efa7506acb143db7375f229509a79
name: schemer
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/mpevnev/schemer#readme>
homepage: https://github.com/mpevnev/schemer#readme
bug-reports: https://github.com/mpevnev/schemer/issues
author: Michail Pevnev
maintainer: mpevnev#gmail.com
license: BSD3
license-file: LICENSE
build-type: Simple
cabal-version: >= 1.10
source-repository head
type: git
location: https://github.com/mpevnev/schemer
library
exposed-modules:
Control.Scheme.Ini
Control.Schemer
other-modules:
Paths_schemer
hs-source-dirs:
src
build-depends:
attoparsec
, base >=4.7 && <5
, text
default-language: Haskell2010
test-suite ini-tests
type: exitcode-stdio-1.0
main-is: Ini.hs
other-modules:
Paths_schemer
hs-source-dirs:
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N -F -pgmF htfpp
build-depends:
HTF
, attoparsec
, base >=4.7 && <5
, schemer
, text
default-language: Haskell2010
I'm not sure what's wrong and what is this Paths_schemer thing. Help is appreciated.
The options -F -pgmF htfpp are switched on globally. This applies the HTF preprocessor to all the files of the test suite, including the autogenerated Paths_schemer.
The more scalable solution is to enable the preprocessor only on files that import Test.Framework, using the OPTIONS_GHC pragma in each one:
{-# OPTIONS_GHC -F -pgmF htfpp #-}
Another way is to set other-modules: [] in the test-suite section in package.yaml to avoid generating Paths_schemer, although that only solves the problem for this one module.

How do I check what version of a package is installed with stack?

Within my project's .cabal file I've got the following under the executable section:
executable ArchPkgstatsScraper
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, ArchPkgStatsScraper
, text
, conduit
, html-conduit
, http-conduit
, xml-conduit
, resourcet
, transformers
After I've successfully installed / built the above with stack, how could I check which version of xml-conduit is installed?
The command
stack ls dependencies
or for older version of stack:
stack list-dependencies
will list every dependency installed for the current project, along with its version.
The new command is going to be
stack ls dependencies
which is replacement of stack list-dependencies
You can read more about it here

Haskell stack not building test executable

Background
I'm building a logfile parser in Haskell. I'm using stack to build it. Running the stack build command works happily and my project compiles. Running stack test, however, produces the following error:
parser-test: executable not found
I see the the following warning above the error message but I don't know how to avoid the redirect to which it refers.
Warning: output was redirected with -o, but no output will be generated because there is no Main module.
Relevant files
I haven't written any tests yet so the test file is as it was created by stack new. My cabal file looks like this:
...
category: Executable
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10
library
hs-source-dirs: src
exposed-modules: LogParser
build-depends: base >= 4.7 && < 5
, attoparsec
, bytestring
, old-locale
, time
default-language: Haskell2010
executable parser-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, attoparsec
, bytestring
, old-locale
, time
, parser
default-language: Haskell2010
test-suite parser-test
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
build-depends: base
, attoparsec
, bytestring
, hspec
, hspec-attoparsec
, old-locale
, time
, parser
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010
source-repository head
type: git
...
I presume I'm missing something but I can't find where what I'm missing is documented.
Desired behaviour
I should see the Test suite not yet implemented message outlined in the stack documentation.
The content of the test/Spec.hs file from the template is:
main :: IO ()
main = putStrLn "Test suite not yet implemented"
You can see this content at commercialhaskell/stack-templates in new-template.hsfiles.
I'm not sure where the module ParserSpec where line comes from (as brought up in the Github issue), but it's not part of the template. On my system, stack new bar && cd bar && stack test succeeds.
As to the reason behind the Main module requirement: it comes from the Cabal library, and as I understand it was added due to limitations in other compilers Cabal supports. In other words, GHC could technically allow this code to compile, but Cabal does not pass in those arguments to remain compatible with other compilers.

Executable within a library and while using the same library in cabal

This is my first try at an open source project, but I still can't get the right way to set up my .cabal file.
I have have library, an executable and a (soon to come) test config.
I want to use the library and within the executable, so the both of them can be used when it gets downloaded.
I followed this guide, but I'm still struggling with the cabal-config as I only get it to work while importing everything again.
My current directory
- src/
- Main.hs
- Format/
- C.hs
- Converter.hs
- Raw.hs
- RGB565.hs
- tests/...
- dist/...
- UTFTConverter.cabal
The executable Main.hs header looks like this.
module Main where
import Format.C
import Format.Converter
The library files in Format/ look like this.
module Format.{filename} where
...
This is what the cabal file looks like.
name: UTFTConverter
...
cabal-version: >=1.10
library
exposed-modules: Format.C
, Format.Converter
, Format.Raw
, Format.RGB565
build-depends: base >=4.7 && <4.8
, filepath >=1.3 && <1.4
, directory >=1.2 && <1.3
, time >=1.4 && <1.5
, bytestring >=0.10 && <0.11
, JuicyPixels >=3.2 && <3.3
hs-source-dirs: src
...
executable UTFTConverter
main-is: Main.hs
build-depends: base >=4.7 && <4.8
, filepath >=1.3 && <1.4
, directory >=1.2 && <1.3
, time >=1.4 && <1.5
, bytestring >=0.10 && <0.11
, JuicyPixels >=3.2 && <3.3
--, UTFTConverter ==0.1 <-- this does not work
hs-source-dirs: src
...
test-suite tests:
...
Without the comment this error comes up when I cabal build.
...
cabal: At least the following dependencies are missing:
UTFTConverter ==0.1
...
It works right now, but in the tutorial the executable was using the library in the same cabal file.
executable bassbull
main-is: Main.hs
ghc-options: -rtsopts -O2
build-depends: base,
bassbull, -- <-- this is the name of the library
bytestring,
cassava
hs-source-dirs: src
default-language: Haskell2010
I know this is currently working, but I would rather use it the right way from the start. Is this the "right" way?
That's due to your library version being 0.1.0.0, not 0.1. They don't match up exactly, thus cabal doesn't recognize your library as a candidate. Instead, use 0.1.* or 0.1.0.0 depending on your version policy:
executable UTFTConverter
main-is: Main.hs
build-depends: base >=4.7 && <4.8
, filepath >=1.3 && <1.4
, directory >=1.2 && <1.3
, time >=1.4 && <1.5
, bytestring >=0.10 && <0.11
, JuicyPixels >=3.2 && <3.3
, UTFTConverter ==0.1.0.0
hs-source-dirs: src
References
Cabal User Guide, section "Build Information".

Resources