haskell / haskell/cabal

Error parsing if/else block in test-suite stanza of cabal file

Open
#6,530 2 comments 0 reactions 0 assignees View on GitHub
Cabal: parser re: conditional type: bug type: user-question
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

Using an `if`/`else` block to provide alternative `main-is` values in the test-suite stanza results in a parsing error:

> Test suite "cabal-bug" is missing required field "type" or the field is not present in all conditional branches.

[Minimal reproducible example.](https://gist.github.com/nghamilton/0a2240a189f66432ea090027b27f7469)

A workaround is to include `type` field in both branches, as suggested by the error message:

```
if flag(breaks)
main-is: Main1.hs
type: exitcode-stdio-1.0
else
main-is: Main2.hs
type: exitcode-stdio-1.0
```

If this is the expected behavior, the error message could possibly be expressed more clearly, or the documentation could state the `type` field should be present in all conditional branches.

Tested on cabal version 3.0.0.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.