[LyX/master] Cmake tests: Add test for possible wrong used constants in our ui-files
Kornel Benko
kornel at lyx.org
Thu Nov 7 13:06:04 UTC 2024
commit 695b2f485cf0372bef96d7cdfb53db89f747f23f
Author: Kornel Benko <kornel at lyx.org>
Date: Thu Nov 7 14:16:03 2024 +0100
Cmake tests: Add test for possible wrong used constants in our ui-files
---
development/autotests/CMakeLists.txt | 6 +++
development/autotests/checkQtConstants.pl | 64 +++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+)
diff --git a/development/autotests/CMakeLists.txt b/development/autotests/CMakeLists.txt
index 471922972f..7116d7a4ad 100644
--- a/development/autotests/CMakeLists.txt
+++ b/development/autotests/CMakeLists.txt
@@ -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}
+)
diff --git a/development/autotests/checkQtConstants.pl b/development/autotests/checkQtConstants.pl
new file mode 100644
index 0000000000..95eca214c9
--- /dev/null
+++ b/development/autotests/checkQtConstants.pl
@@ -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);
+ }
+}
More information about the lyx-cvs
mailing list