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

Test: Add syntax tests and add missing use warnings #712

Merged
merged 6 commits into from
Oct 31, 2024

Conversation

nicomen
Copy link
Contributor

@nicomen nicomen commented Oct 30, 2024

A new dependency is introduced, but only while testing

t/~syntax.t Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Is the name supposed to start with ~?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just convention to let it be the first test to run, ~ is sorted before most other characters. We can use numbers or perhaps a testrules.yml file too. https://perldoc.perl.org/TAP::Harness#new (look for testrules.yml)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently it's ran last now :-D Maybe it's the last one. Oh well. We can rename it and just drop the ~. It's not that many tests that you want to fail fast.

Copy link
Member

Choose a reason for hiding this comment

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

That would be cleaner, yes.

Or at least please add a comment.

@DarthGandalf
Copy link
Member

Btw, from "Add syntax tests" it was obvious enough that it's about tests :D

t/syntax.t Outdated
local $Test::Strict::TEST_WARNINGS = 1;

my @dirs = ('t', 'bin', "$Bin/../share/shutter/resources/modules/");
my @files = Test::Strict::_all_perl_files(@dirs);
Copy link
Member

Choose a reason for hiding this comment

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

This is a private function of Test::Strict? It's not documented at https://metacpan.org/pod/Test::Strict

Why all_perl_files_ok was not enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To run them in parallell. First it finds all files to test with _all_perl_files, then in the next part below it runs them in parallell, in this case 4 at a time. I could find "all perl-like" files myself, but thought it was best to use Test::Strict own way to find them.

This is just a standard syntax check I add in all projects.

When a project is big it gets slow to run syntax checks on all files sequentially.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can be just this:

#!/usr/bin/env perl

use strict;
use warnings;

use Test::More;
use Test::Strict;

use FindBin qw/$Bin/;

# Check syntax, use strict and use warnings on all perl files

local $Test::Strict::TEST_WARNINGS = 1;

my @dirs  = ('t', 'bin', "$Bin/../share/shutter/resources/modules/");

all_perl_files_ok(@dirs);

done_testing;

Locally that takes 10 seconds vs 4 seconds in parallell.

If you prefer I can use the "simple" approach instead.

Copy link
Member

Choose a reason for hiding this comment

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

10 seconds is good enough. Additional 6 seconds don't deserve the added complexity

@DarthGandalf DarthGandalf merged commit be6df92 into shutter-project:master Oct 31, 2024
1 check passed
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