Set default run
I have a test-suite and an executable, and I want to automatically run the executable when I type cabal run. However, it says that the run command is for running a single executable at once (since it doesn't know whether to run the test or the exe). How do I make cabal ignore test suites when executing cabal run?
I don't want to disable tests, I want to execute tests when I type cabal test and execute the executable when I type cabal run
Hello Pedro, can you tell us why cabal run exectutable-name does not fit your workflow?
I can answer this - because (a) one might not remember what exact names executables in the project have, (b) for a simple project (one "target" exe, one "test" exe) it's ~~silly~~ inconvenient for the user to supply info that Cabal ought to know by itself.
I can envision difficulties with projects that build several executables (and/or several test-binaries).
for (b), cabal is doing the right thing already, am I wrong?
# `.cabal` file with one exe, one testsuite
f@mkiii:~/francesco/progetti/progr/lentill$ cabal run # no target specified here
Warning: this is a debug build of cabal-install with assertions enabled.
Up to date
Missing: PATH...
Usage: lentil [-h|--help] PATH... [-x PATH] [-f TYPE]
[-t EXPR | -T EXPR | -p EXPR | -P EXPR | -d EXPR | -D EXPR]
[-a ALIAS] [-w FLAGWORD] [--output FILE] [-v|--version]
(a) I am not really sure. If you do not remember the name it is because there are multiple executables, and if there are multiple executables you should specify one.
Alas, no.
For (a), the name of a sole executable could be <project_name>, or <project_name-exe>, or something altogether different. While looking it up should be as simple as browsing the <project_name>.cabal file (or doing cabal --list-bins), it's an extra and unnecessary effort.
Fur (b), we claim that the "right thing to do" when only one executable was built, would be to execute it upon command cabal run, as there's no ambiguity.
It's a small thing.
I would also like to have a default run (and repl) target.
Right now to get the executable I want I have to type:
cabal run busyhask:exe:busyhask
This snowballs further when I want to use ghcid:
ghcid "--command=cabal repl busyhask:exe:busyhask" -r
Note that the default ghcid command for a cabal project is cabal repl, so if I could set a default I would instead just have to type:
ghcid -r
The command help mentions "executable-like" and that the [TARGET] is not needed if a single "executable-like" is resolvable without it. Seems reasonable to expect that an executable is more executable-like than a test suite.
[!NOTE] It took me a long time to realise that I could
cabal runa test suite. I had expected these would needcabal test.
$ cabal run --help
Run an executable.
Usage: cabal run [TARGET] [FLAGS] [-- EXECUTABLE_FLAGS]
Runs the specified executable-like component (an executable, a test, or a
benchmark), first ensuring it is up to date.
Any executable-like component in any package in the project can be specified.
A package can be specified if contains just one executable-like, preferring a
single executable. The default is to use the package in the current directory
if it contains just one executable-like.
...
Examples:
cabal run
Run the executable-like in the package in the current directory
cabal run foo-tool
Run the named executable-like (in any package in the project)