Skip to content

t: Add check script to ensure test modules compile with strict#24921

Open
perlpunk wants to merge 1 commit intoos-autoinst:masterfrom
perlpunk:add-strict-check-script
Open

t: Add check script to ensure test modules compile with strict#24921
perlpunk wants to merge 1 commit intoos-autoinst:masterfrom
perlpunk:add-strict-check-script

Conversation

@perlpunk
Copy link
Contributor

@perlpunk perlpunk commented Mar 11, 2026

This script will load all test modules under tests/ with the ENABLE_MODERN_PERL_FEATURES setting, which automatically adds

use Mojo::Base -strict, -signatures;

at the top.

You can use it to check all modules by doing

prove tools/check_strict

or check specific files with

perl tools/check_strict tests/category/one.pm tests/category/two.pm

This will fail right now, as there are many modules which use undeclared variables.
Please see #24709 for that and try to fix those issues in the modules you maintain. If you need any help / explanation for the error and how to fix it, don't hesitate to ask me for help.

Once we have fixed all errors, we can activate this as a CI check.

You will see a lot of warnings when running this. Those are currently not fatal, but I will work on that as a next step.

An alternative would be to not use the ENABLE_MODERN_PERL_FEATURES, but write a script that adds this line automatically to the source code in github - permanantly. The advantage is that you would be able to run a normal compile time check via perl -c tests/category/module.pm and get an error for undeclared variables or other strict errors.

With the above script, you always have to use that, because it only adds the strictures on the fly.

Let me know what you would prefer for osado.

This script will load all test modules under tests/ with the ENABLE_MODERN_PERL_FEATURES
setting, which automatically adds
    use Mojo::Base -strict, -signatures;
at the top.

You can use it to check all modules by doing

    prove tools/check_strict

or check specific files with

    perl tools/check_strict tests/category/one.pm tests/category/two.pm

Issue: https://progress.opensuse.org/issues/194002
@foursixnine
Copy link
Member

@perlpunk

The advantage is that you would be able to run a normal compile time check via perl -c tests/category/module.pm and get an error for undeclared variables or other strict errors.

This is also really useful as part of pre-commit hooks together with a target in the Makefile
foursixnine@65eb336:

.PHONY: check-strict
check-strict: tools/check_strict
	git diff --name-only -- *.pm | xargs -r $<
	@echo "[make] check_strict called over modified files. To check all the files use 'check-strict-full'"

.PHONY: check-strict-full
check-strict-full: tools/check_strict
	$<

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.

3 participants