]>
Commit | Line | Data |
---|---|---|
152bbef4 CH |
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 | ||
7a95f387 CH |
30 | # https://bugzilla.proxmox.com/show_bug.cgi?id=4872 |
31 | my $prev; | |
32 | eval { | |
33 | local $SIG{ALRM} = sub { die "timed out!\n" }; | |
34 | $prev = alarm(1); | |
35 | $ret = run_command('sleep 5'); | |
36 | }; | |
37 | alarm($prev); | |
38 | ||
39 | is($@, "timed out!\n", 'SIGALRM interaction'); | |
40 | ||
152bbef4 CH |
41 | # Check the log for errors/warnings |
42 | my $log = file_read_all($log_file->filename); | |
43 | ok($log !~ m/(WARN|ERROR): /, 'no warnings or errors logged'); | |
44 | print $log if $log =~ m/(WARN|ERROR): /; | |
45 | ||
46 | done_testing(); |