]> git.proxmox.com Git - pve-installer.git/blob - test/run-command.pl
7d5805e155258f0565e70c6bc1de8bc62a1f0ba4
[pve-installer.git] / test / run-command.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use File::Temp;
7 use Test::More;
8
9 use Proxmox::Sys::Command qw(run_command CMD_FINISHED);
10 use Proxmox::Sys::File qw(file_read_all);
11 use Proxmox::UI;
12
13 my $log_file = File::Temp->new();
14 Proxmox::Log::init($log_file->filename);
15
16 Proxmox::UI::init_stdio();
17
18 is(run_command('echo test'), "test\n", 'basic usage');
19
20 is(run_command('echo test', undef, undef, 1), 0, 'system()-mode');
21
22 my $ret = run_command('bash -c "echo test; sleep 1000; echo test"', sub {
23 my $line = shift;
24 is($line, 'test', 'using CMD_FINISHED - produced correct log line');
25
26 return CMD_FINISHED;
27 });
28 is($ret, '', 'using CMD_FINISHED');
29
30 # Check the log for errors/warnings
31 my $log = file_read_all($log_file->filename);
32 ok($log !~ m/(WARN|ERROR): /, 'no warnings or errors logged');
33 print $log if $log =~ m/(WARN|ERROR): /;
34
35 done_testing();