1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
# --
# Copyright (C) 2001-2021 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::Console::Command::Dev::UnitTest::Run;
use strict;
use warnings;
use parent qw(Kernel::System::Console::BaseCommand);
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::UnitTest',
);
sub Configure {
my ( $Self, %Param ) = @_;
$Self->Description('Execute unit tests.');
$Self->AddOption(
Name => 'test',
Description =>
"Run individual test files, e.g. 'Ticket' or 'Ticket/ArchiveFlags' (can be specified several times).",
Required => 0,
HasValue => 1,
Multiple => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddOption(
Name => 'directory',
Description => "Run all test files in the specified directory.",
Required => 0,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddOption(
Name => 'verbose',
Description => "Show details for all tests, not just failing.",
Required => 0,
HasValue => 0,
);
$Self->AddOption(
Name => 'data-diff-type',
Description => "Choose which diff type to use for the data diff (table or unified).",
Required => 0,
HasValue => 1,
ValueRegex => qr/^(table|unified)$/ismx,
);
$Self->AddOption(
Name => 'submit-url',
Description => "Send unit test results to a server (URL).",
Required => 0,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddOption(
Name => 'submit-auth',
Description => "Authentication string for unit test result server.",
Required => 0,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddOption(
Name => 'submit-result-as-exit-code',
Description =>
"Specify if command return code should not indicate if tests were ok/not ok, but if submission was successful instead.",
Required => 0,
HasValue => 0,
);
$Self->AddOption(
Name => 'job-id',
Description => "Job ID for unit test submission to server.",
Required => 0,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddOption(
Name => 'scenario',
Description => "Scenario identifier for unit test submission to server.",
Required => 0,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddOption(
Name => 'attachment-path',
Description =>
"Send an additional file to the server, for example to submit the complete command output that has been redirected to a file. You can use wildcards like '/opt/otrs/var/log/*.log' here, but make sure to protect them via '' quotes from shell expansion.",
Required => 0,
HasValue => 1,
ValueRegex => qr/.*/smx,
Multiple => 1
);
$Self->AddOption(
Name => 'post-test-script',
Description =>
'Script(s) to execute after a test has been run. You can specify %File%, %TestOk% and %TestNotOk% as dynamic arguments.',
Required => 0,
HasValue => 1,
ValueRegex => qr/.*/smx,
Multiple => 1
);
$Self->AddOption(
Name => 'pre-submit-script',
Description =>
'Script(s) to execute after all tests have been executed and the results are about to be sent to the server.',
Required => 0,
HasValue => 1,
ValueRegex => qr/.*/smx,
Multiple => 1
);
$Self->AddOption(
Name => 'test-runs',
Description => 'Number of successive runs for every single unit test, default 1.',
Required => 0,
HasValue => 1,
ValueRegex => qr/^\d+$/smx,
);
return;
}
sub PreRun {
my ( $Self, %Param ) = @_;
if ( $Self->GetOption('submit-result-as-exit-code') && !$Self->GetOption('submit-url') ) {
die "Please specify a valid 'submit-url'.";
}
return;
}
sub Run {
my ( $Self, %Param ) = @_;
$Kernel::OM->ObjectParamAdd(
'Kernel::System::UnitTest' => {
ANSI => $Self->{ANSI},
},
);
# Allow specification of a default directory to limit test execution.
my $DefaultDirectory = $Kernel::OM->Get('Kernel::Config')->Get('UnitTest::DefaultDirectory');
my $FunctionResult = $Kernel::OM->Get('Kernel::System::UnitTest')->Run(
Tests => $Self->GetOption('test'),
Directory => $Self->GetOption('directory') || $DefaultDirectory,
JobID => $Self->GetOption('job-id'),
Scenario => $Self->GetOption('scenario'),
SubmitURL => $Self->GetOption('submit-url'),
SubmitAuth => $Self->GetOption('submit-auth'),
SubmitResultAsExitCode => $Self->GetOption('submit-result-as-exit-code') || '',
Verbose => $Self->GetOption('verbose'),
DataDiffType => $Self->GetOption('data-diff-type'),
AttachmentPath => $Self->GetOption('attachment-path'),
PostTestScripts => $Self->GetOption('post-test-script'),
PreSubmitScripts => $Self->GetOption('pre-submit-script'),
NumberOfTestRuns => $Self->GetOption('test-runs'),
);
if ($FunctionResult) {
return $Self->ExitCodeOk();
}
return $Self->ExitCodeError();
}
1;
|