-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path03-run.t
96 lines (71 loc) · 2.23 KB
/
03-run.t
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
#! perl
use strict;
use warnings;
use Test::More;
use File::Copy;
use File::Temp;
use Statistics::R;
use File::Spec::Functions;
my ($R, $expected, $bin, $version);
my $file = 'file.ps';
ok $R = Statistics::R->new();
ok $bin = $R->bin();
ok $bin =~ /\S+/, 'Executable name';
$expected = '';
is $R->run( ), $expected;
ok $bin = $R->bin();
ok $bin =~ /\S+/, 'Executable path';
ok $version = $R->version();
ok $version =~ /^\d+\.\d+\.\d+$/, 'Version';
diag "R version $version found at $bin\n";
$expected = '';
is $R->run( qq`postscript("$file" , horizontal=FALSE , width=500 , height=500 , pointsize=1)`), $expected, 'Basic';
$expected = '';
is $R->run( q`plot(c(1, 5, 10), type = "l");` ), $expected;
$expected =
'null device
1 ';
is $R->run( q`dev.off()` ), $expected; # RT bug #66190
ok -e $file; # RT bug #70307
unlink $file;
$expected =
'loop iteration 1
loop iteration 2
loop iteration 3';
is $R->run( q`for (j in 1:3) { cat("loop iteration "); cat(j); cat("\n") }` ), $expected;
$expected = 'Some innocuous message on stderr';
is $R->run( q`write("Some innocuous message on stderr", stderr())` ), $expected, 'IO';
$expected = 'Some innocuous message on stdout';
is $R->run( q`write("Some innocuous message on stdout", stdout())` ), $expected;
$expected = '[1] 123';
is $R->run( qq`x <- 123 \n print(x)` ), $expected, 'Multi-line commands';
$expected = '456';
my $cmd1 = 'x <- 456 ; write.table(x, file="", row.names=FALSE, col.names=FALSE)';
is $R->run( $cmd1 ), $expected; # RT bug #70314
my $cmd2 = <<EOF;
a <- 2
b <- 5
c <- a * b
print('ok')
EOF
$expected = '[1] "ok"';
is $R->run( $cmd2 ), $expected, 'Heredoc commands';
$expected =
'456
[1] "ok"';
is $R->run( $cmd1, $cmd2 ), $expected, 'Multiple commands';
$expected =
'Some innocuous message on stderr
loop iteration: [1] 1
loop iteration: [1] 2
loop iteration: [1] 3
Some innocuous message on stdout
[1] 123
456
[1] "ok"';
$file = catfile('t', 'data', 'script.R');
is $R->run_from_file( $file ), $expected, 'Command from file (relative path)';
my $absfile = File::Temp->new( UNLINK => 1 )->filename;
copy($file, $absfile) or die "Error: Could not copy file $file to $absfile: $!\n";
is $R->run_from_file( $absfile ), $expected, 'Commands from file (absolute path)';
done_testing;