Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cabal check testuite: add sanity checks #8248

Merged
merged 22 commits into from
Jun 28, 2022

Conversation

ffaf1
Copy link
Collaborator

@ffaf1 ffaf1 commented Jun 22, 2022

cabal check testsuite: sanity checks (i.e.: this bit).

Missing:


Please include the following checklist in your PR:

Please also shortly describe how you tested your change. Bonus points for added tests!

@ffaf1 ffaf1 changed the title Cabal check testsuite old sanity cabal check testuite: add sanity checks Jun 22, 2022
@ffaf1 ffaf1 mentioned this pull request Jun 22, 2022
4 tasks
@ffaf1 ffaf1 force-pushed the cabal-check-testsuite-old-sanity branch 2 times, most recently from aa717f3 to 8bad4c1 Compare June 23, 2022 06:56
@ffaf1 ffaf1 marked this pull request as ready for review June 23, 2022 09:41
Copy link
Member

@jneira jneira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work, to improve the test suite and coverage is one of the most valuables contributions to any codebase and cabal of course. Many thanks.

@ulysses4ever
Copy link
Collaborator

I wonder if hardcoding error messages in the test suite is really necessary, or a more flexible check (pun intended) that there is a warning (or that exit code is non zero) would suffice. The latter would be easier to maintain probably.

@ffaf1
Copy link
Collaborator Author

ffaf1 commented Jun 24, 2022

The question is sound, thanks for bringing it up.

If you test on the mere presence of errors/warnings (without comparing error messages):

  • on one hand, you risk marring some tests. As an example:
    , check (maybe False isAbsoluteOnAnyPlatform (repoSubdir repo)) $
    PackageDistInexcusable
    "The 'subdir' field of a source-repository must be a relative path."
    , do
    subdir <- repoSubdir repo
    err <- isGoodRelativeDirectoryPath subdir
    return $ PackageDistInexcusable $
    "The 'subdir' field of a source-repository is not a good relative path: " ++ show err

    “relative path” check and “good relative path check” are not the same; it is important for the end user to get a different specific message. By testing on warning we lose the assurance that the correct message is being printed (and not — e.g. — the other, both, multiple of the same type, a third unrelated one).
  • On the other hand it is way more easier to maintain; slight changes in output will not break tests. The more “internal” the change is, the bigger the breakage: if we were to change Warning: — which now starts every warning message — with Attention:, 95% of the testsuite would instantly turn red.

I wrote tests checking against output:

  • following what was already there in the repo; and
  • after reading this bit in the testsuite README:
    **How do I turn off accept tests? My test output wobbles too much.**
    Use `recordMode DoNotRecord`. This should be a last resort; consider
    modifying Cabal so that the output is stable. If you must do this, make
    sure you add extra, manual tests to ensure the output looks like what
    you expect.

    The one I wrote are (mostly) not accept-tests, but the bit on output stability I feel still applies.

The question is even more sound considering how I am approaching writing tests for cabal check. Along this pull request (22 tests), there is #8250 (another 15) and the one I am writing locally (+15). I am painstakingly going through all PackageDescription/Check.hs; I expect the final testsuite for cabal check to have several hundred tests.

Tests are indeed not cheap to maintain, any kind of direction on what maintainers are happy with is welcome.

CC @andreasabel who mentors me and is for sure interested.
I am happy with whatever decision is taken, reimplementing cabal check goes on!

@jneira
Copy link
Member

jneira commented Jun 24, 2022

well I think messages don't change so frequently and fix the test in front of no semantic changes is almost trivial: you get the test error and change the message
you also check the correct message is presented in the appropriate state

there are not unit tests for Chech messages, I want to remember there were some but not sure. Maybe the correct balance between unit and integration tests could make msintanence more lightweight

@ffaf1 ffaf1 force-pushed the cabal-check-testsuite-old-sanity branch from 8bad4c1 to 9581b46 Compare June 27, 2022 13:55
@ffaf1
Copy link
Collaborator Author

ffaf1 commented Jun 28, 2022

@ulysses4ever a consideration on tests maintainability. My plan to reimplement cabal check in #8211 includes this step: “tipify cabal check errors (as now they are Strings)”.

Once that is done there should be a way to convert the testsuite from checking against Strings to checking against data constructors, much more robust. Some of the switch could probably also be automated, at least for simple tests (e.g. this one, with just three files and a simple cabal.test.hs body).

Current testsuite would still be useful in refactoring cabal check errors; moreover the refactoring should give us some data on how the stability of cabal check output and how painful it is to rewrite a test (I had to rewrite the output of a test in #8258, I just passed --accept to cabal-test, that one felt easy).

I cannot promise a timeframe because my plate is quite full, but ideally I think checking against constructors will give us maintainability and precision at the same time.

@ulysses4ever
Copy link
Collaborator

@ffaf1 sounds good. Being able to check type constructors sounds exciting! But I understand everyone is busy and don't hold my breath.

@jneira

I think messages don't change so frequently and fix the test in front of no semantic changes is almost trivial

That is true. I thought about cases when you have to change many/all tests in bulk because e.g. the format of messages changed. Or when you have the same message in many tests. But maybe this is unlikely to happen.

@ffaf1 ffaf1 added the merge me Tell Mergify Bot to merge label Jun 28, 2022
ffaf1 added 13 commits June 28, 2022 12:09
No body: No executables, libraries, tests, or benchmarks found.
Executables can have the same name as the external library.
Internal libraries cannot have the same name as the pacakge.
`signatures` field can be used only with `cabal-version` ≥ 2.0
All in `autogen-modules` has to be present either in `other-modules`
or `exposed-modules`.
All in `autogen-includes` hs to be in either `includes` or
`install-includes`.
`main-is` has to be one of: .hs, .lhs, C/C++/obj-C source file.
You need `cabal-version` ≥ 1.18 to use C/C++/obj-C source files
in `main-is`.
All in `autogen-includes` hs to be in either `includes` or
`install-includes`.
All in `autogen-modules` has to be present either in `other-modules`
or `exposed-modules`.
`main-is` has to be one of: .hs, .lhs, C/C++/obj-C source file.
(testsuite)
You need `cabal-version` ≥ 1.18 to use C/C++/obj-C source files
in `main-is`. (testsuite)
All in `autogen-includes` hs to be in either `includes` or
`install-includes` (testsuite).
All in `autogen-modules` has to be present either in `other-modules`
or `exposed-modules` (testsuite).
`main-is` has to be one of: .hs, .lhs, C/C++/obj-C source file.
(benchmark)
All in `autogen-modules` has to be present either in `other-modules`
or `exposed-modules` (benchmark).
All in `autogen-includes` hs to be in either `includes` or
`install-includes` (benchmark).
@andreabedini andreabedini force-pushed the cabal-check-testsuite-old-sanity branch from 9581b46 to 156fb34 Compare June 28, 2022 12:09
@mergify mergify bot merged commit 1da1893 into haskell:master Jun 28, 2022
@ffaf1 ffaf1 deleted the cabal-check-testsuite-old-sanity branch June 28, 2022 15:25
@ulysses4ever
Copy link
Collaborator

I'm not sure whether it's best to merge 22 commits individually or squash them. It seems they have been merged individually. I think I'd prefer squashing (in the future, at least).

@ffaf1
Copy link
Collaborator Author

ffaf1 commented Jun 29, 2022

Ouch, I will do that next PR!

@Mikolaj
Copy link
Member

Mikolaj commented Jun 29, 2022

It's in a clearly separate loop of the git history, so not much harm (visible, e.g., with gitk).

@ffaf1 ffaf1 mentioned this pull request Sep 22, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants