Cmake tests: Add test for possible wrong used constants in our ui-files

This commit is contained in:
Kornel Benko 2024-11-07 14:16:03 +01:00
parent d75ab6d6f0
commit 695b2f485c
2 changed files with 70 additions and 0 deletions

View File

@ -127,3 +127,9 @@ if (LYX_ENABLE_EXPORT_TESTS)
message(STATUS "Number of ignored export tests now ${lyx_ignored_count}")
set(LYX_ignored_count ${lyx_ignored_count} PARENT_SCOPE)
endif()
set(CHECK_QT_CONSTANTS_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/checkQtConstants.pl")
add_test(NAME "check_Qt_ui_Constants"
WORKING_DIRECTORY ${TOP_SRC_DIR}
COMMAND ${PERL_EXECUTABLE} ${CHECK_QT_CONSTANTS_SCRIPT}
)

View File

@ -0,0 +1,64 @@
#! /usr/bin/env perl
# -*- mode: perl; -*-
#
use strict;
use warnings;
BEGIN {
use File::Spec;
my $p = File::Spec->rel2abs(__FILE__);
$p =~ s/[\/\\]?[^\/\\]+$//;
unshift(@INC, "$p");
}
my $no_founds = 0;
sub checkConstants($);
sub collectUiFiles($$);
my @UIFiles = ();
collectUiFiles('.', \@UIFiles);
for my $ui (@UIFiles) {
checkConstants($ui);
}
exit($no_founds);
###########################################
sub checkConstants($) {
my ($ui) = @_;
#print "Checking $ui\n";
if (open(my $FI, '<', $ui)) {
my $lineno = 0;
while (my $l = <$FI>) {
$lineno += 1;
if ($l =~ /\bQ[a-zA-Z]+\:\:[a-zA-Z]+\:\:/) {
print "$ui:$lineno $l";
$no_founds += 1;
}
}
close($FI);
}
}
# Recursive collect UI files
sub collectUiFiles($$) {
my ($dir, $rFiles) = @_;
my @subdirs = ();
if (opendir(my $DI, $dir)) {
while (my $f = readdir($DI)) {
if (-d "$dir/$f") {
next if ($f =~ /^\.(\.)?$/);
push(@subdirs, "$dir/$f");
}
elsif ($f =~ /\.ui$/) {
push(@{$rFiles}, "$dir/$f");
}
}
closedir($DI);
}
for my $d (@subdirs) {
collectUiFiles($d, $rFiles);
}
}