Skip to content

modules/test: check warnings/assertions#2048

Merged
mergify[bot] merged 3 commits intonix-community:mainfrom
MattSturgeon:test_warnings
Aug 22, 2024
Merged

modules/test: check warnings/assertions#2048
mergify[bot] merged 3 commits intonix-community:mainfrom
MattSturgeon:test_warnings

Conversation

@MattSturgeon
Copy link
Copy Markdown
Member

@MattSturgeon MattSturgeon commented Aug 21, 2024

Extracted from #1989 to reduce its scope. Also based on earlier work from #1986.

This PR moves responsibility for assertions/warnings in tests to the test derivation, instead of printing/throwing them.

They are still printed/thrown when building a non-test nixvim build.

Additionally, two new options are added to control this behaviour. Both default to true:

  • test.checkWarnings: Whether to check config.warnings in the test.
  • test.checkAssertions: Whether to check config.assertions in the test.

Note

Only module warnings/assertions defined using the respective options from assertions.nix are checked.
Anything printed manually with lib.warn, builtins.trace, etc, or errors thrown with assert, throw, abort, etc will not be handled correctly by the test.

  • Errors would still fail CI; the test would fail before even running
  • Warnings printed manually will just print to the console, bypassing the test

In the future we can expand on this to allow "expecting" assertions, which will make our test system more flexible.

@MattSturgeon MattSturgeon marked this pull request as ready for review August 21, 2024 03:44
@MattSturgeon
Copy link
Copy Markdown
Member Author

I wonder if it'd be worth including a test.ignoreWarnings option in this PR?

It may make the schemastore changes simpler, since we wouldn't have to avoid creating the warnings.

@MattSturgeon MattSturgeon requested a review from a team August 21, 2024 04:27
@khaneliman
Copy link
Copy Markdown
Contributor

khaneliman commented Aug 21, 2024

I wonder if it'd be worth including a test.ignoreWarnings option in this PR?

It may make the schemastore changes simpler, since we wouldn't have to avoid creating the warnings.

My first reaction is that it would be nice to have that functionality. But, I'm trying to think of how often we'd do that. Are there cases that the test might include warnings and we need to silence them so we can keep the test enabled to watch for errors? That could be nice for maintenance. I think as long as we have inline notes around why a particular test's warnings are ignored, it shouldn't cause any serious negative side effects.

@MattSturgeon
Copy link
Copy Markdown
Member Author

I'm trying to think of how often we'd do that. Are there cases that the test might include warnings and we need to silence them so we can keep the test enabled to watch for errors?

The only other example is nvim-osc52, a plugin that prints a deprecation warning when enabled.

I've updated this PR to just mkForce remove the warnings.

In the future we can extend the test module with additional options, but let's not let the scope of this PR creep out of control. 😁

@MattSturgeon
Copy link
Copy Markdown
Member Author

In the future we can extend the test module with additional options, but let's not let the scope of this PR creep out of control. 😁

I decided it wasn't too much work to just implement basic checkWarnigns and checkAssertions options in this PR.

@MattSturgeon MattSturgeon force-pushed the test_warnings branch 2 times, most recently from 5a57f91 to 17bc33b Compare August 22, 2024 10:07
Copy link
Copy Markdown
Contributor

@khaneliman khaneliman left a comment

Choose a reason for hiding this comment

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

LGTM, probably needs a rebase real quick though.

Warnings and assertions defined as `config.warnings` and `config.assertions`
respectively will be checked as part of the test derivation, instead of
when evaluating the modules.

Adds new `checkWarnings` and `checkAssertions` test options (default true).
Follow up to a1a3488

Uses new `test.checkWarnings` option.
@MattSturgeon
Copy link
Copy Markdown
Member Author

@Mergifyio queue

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Aug 22, 2024

queue

✅ The pull request has been merged automatically

Details

The pull request has been merged automatically at 0641962

@mergify mergify bot merged commit 0641962 into nix-community:main Aug 22, 2024
@mergify mergify bot temporarily deployed to github-pages August 22, 2024 13:49 Inactive
@MattSturgeon MattSturgeon deleted the test_warnings branch August 22, 2024 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants