Skip to content

Commit

Permalink
build tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Emohr-Tuxedo committed Feb 3, 2025
1 parent 7657461 commit 93dd4a8
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions codeCheck.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use warnings;
use File::Compare;

my %testResults;

# removes all whitespaces from input and string from file
sub countStrings {
my ($string, $file) = @_;
Expand Down Expand Up @@ -37,14 +39,13 @@ sub checkSyntax {
sub checkLint {
my ($file) = @_;
my $cmd = "perlcritic $file";
my $output = `$cmd`;
`$cmd`;
my $retValue = $?;
# exit code from perlcritic means:
# 0 = no errors, no problems
# 1 = something went wrong
# 2 = some code did not pass the test
if ($retValue > 0) {
print "output from perlcritic:\n$output\n";
return (1);
} else {
return (0);
Expand All @@ -57,86 +58,88 @@ sub checkDiff {
if ($result == 0) {
} elsif ($result == 1) {
print "file: $fileA and file: $fileB are different!!\n";
print "they should be the same\n\n";
print "they should be the same to continue the checks\n\n";
return (1);
} else {
print "some error has occured comparing the files $fileA and $fileB\n\n";
return (1);
}
return (0);
}

# Check if a TODO is present in the code
print "Checking for TODOs...\n";
my $todoPresent = countStrings('#TODO', './src/tuxedo-tomte');
if ($todoPresent) {
print "Found $todoPresent #TODOs!\n\n";
$testResults{'TODOs'} = countStrings('#TODO', './src/tuxedo-tomte');
if ($testResults{'TODOs'}) {
print "Found $testResults{'TODOs'} #TODOs!\n\n";
}

# Check if a higher log level is set
print "Checking for higher log level...\n";
my $higherloglevelPresent = countStrings('$logLevel=0', './src/tuxedo-tomte');
if ($higherloglevelPresent) {
$testResults{'higherloglevel'} = countStrings('$logLevel=0', './src/tuxedo-tomte');
if ($testResults{'higherloglevel'}) {
print "Found log level higher then 0!\n\n";
}

# Check if a test all modules is set
print "Checking for test all modules...\n";
my $testallmodulesPresent = countStrings('Readonlymy$TEST_ALL_MODULES=>1', './src/tuxedo-tomte');
if ($testallmodulesPresent) {
$testResults{'installAllModules'} = countStrings('Readonlymy$TEST_ALL_MODULES=>1', './src/tuxedo-tomte');
if ($testResults{'installAllModules'}) {
print "Found test all modules higher then 0!\n\n";
}


# Run the translationsCheck script and capture any output
print "Checking translations...\n";
my $checkTranslationsOutput=`perl ./translationsCheck.pl 2>&1`;
my $checkTranslationsCount=$?;
my $checkTranslationsOutput = `perl ./translationsCheck.pl 2>&1`;
$testResults{'translations'} = $?;

if ($checkTranslationsCount != 0) {
if ($testResults{'translations'} != 0) {
print "Found translations differences!\n";
print "$checkTranslationsOutput\n";
}

# check if the current module is same as the one we are testing
# the module has to be installed in the host system for
# the tests to work correctly
checkDiff('Tomte/Presets.pm', '/usr/share/perl5/Tomte/Presets.pm');
$testResults{'PresetsModule'} = checkDiff('Tomte/Presets.pm', '/usr/share/perl5/Tomte/Presets.pm');


# Check if there are syntax errors in the code
print "Checking for syntax errors in src/tuxedo-tomte...\n";
my $syntaxIncorrectTomte = checkSyntax('./src/tuxedo-tomte');
if ($syntaxIncorrectTomte) {
$testResults{'syntaxErrorsTomte'} = checkSyntax('./src/tuxedo-tomte');
if ($testResults{'syntaxErrorsTomte'}) {
print "Found syntax errors in src/tuxedo-tomte!\n\n";
}

print "Checking for syntax errors Tomte/Presets.pm...\n";
my $syntaxIncorrectPresets = checkSyntax('./Tomte/Presets.pm');
if ($syntaxIncorrectPresets) {
$testResults{'syntaxErrorsPresets'} = checkSyntax('./Tomte/Presets.pm');
if ($testResults{'syntaxErrorsPresets'}) {
print "Found syntax errors in Tomte/Presets.pm!\n\n";
}

print "Checking for lint errors src/tuxedo-tomte...\n";
my $lintIncorrectTomte = checkLint('./src/tuxedo-tomte');
if ($lintIncorrectTomte) {
$testResults{'lintErrorsTomte'} = checkLint('./src/tuxedo-tomte');
if ($testResults{'lintErrorsTomte'}) {
print "Found lint errors in src/tuxedo-tomte!\n\n";
}

print "Checking for lint errors Tomte/Presets.pm...\n";
my $lintIncorrectPresets = checkLint('./Tomte/Presets.pm');
if ($lintIncorrectPresets) {
$testResults{'lintErrorsPresets'} = checkLint('./Tomte/Presets.pm');
if ($testResults{'lintErrorsPresets'}) {
print "Found lint errors in Tomte/Presets.pm!\n\n";
}

# Calculate the exit code as the sum of the variables
my $exitCode = 0;
$exitCode = $todoPresent
+ $higherloglevelPresent
+ $testallmodulesPresent
+ $syntaxIncorrectTomte
+ $syntaxIncorrectPresets
+ $lintIncorrectTomte
+ $lintIncorrectPresets;
my $sumExitCodes = 0;

# print results
print "\nRESULTS\n";
foreach my $key (keys %testResults) {
$sumExitCodes += $testResults{$key};
print "$testResults{$key} <=> $key\n";
}

# Exit with the calculated exit code
print "exit code: $exitCode\n";
exit $exitCode
print "\nexit code: $sumExitCodes\n";
exit ($sumExitCodes);

0 comments on commit 93dd4a8

Please sign in to comment.