]> git.donarmstrong.com Git - deb_pkgs/libstatistics-r-perl.git/blob - t/03-run.t
Import Upstream version 0.24
[deb_pkgs/libstatistics-r-perl.git] / t / 03-run.t
1 #! perl
2
3 use strict;
4 use warnings;
5 use Test::More;
6 use Statistics::R;
7
8 plan tests => 15;
9
10
11 my ($R, $expected);
12
13 my $file = 'file.ps';
14
15 ok $R = Statistics::R->new();
16
17 ok $R->bin() =~ /\S+/, 'Binary';
18
19 $expected = '';
20 is $R->run( ), $expected;
21
22 $expected = '';
23 is $R->run( qq`postscript("$file" , horizontal=FALSE , width=500 , height=500 , pointsize=1)`), $expected, 'Basic';
24
25 $expected = '';
26 is $R->run( q`plot(c(1, 5, 10), type = "l")` ), $expected;
27
28 $expected = 
29 'null device 
30           1 ';
31 is $R->run( q`dev.off()` ), $expected; # RT bug #66190
32
33 ok -e $file; # RT bug #70307
34 unlink $file;
35
36 $expected =
37 'loop iteration 1
38 loop iteration 2
39 loop iteration 3';
40 is $R->run( q`for (j in 1:3) { cat("loop iteration "); cat(j); cat("\n") }` ), $expected;
41
42 $expected = 'Some innocuous message on stderr';
43 is $R->run( q`write("Some innocuous message on stderr", stderr())` ), $expected, 'IO';
44
45 $expected = 'Some innocuous message on stdout';
46 is $R->run( q`write("Some innocuous message on stdout", stdout())` ), $expected;
47
48 $expected = '[1] 123';
49 is $R->run( qq`x <- 123 \n print(x)` ), $expected, 'Multi-line commands';
50
51 $expected = '456';
52 my $cmd1 = 'x <- 456 ; write.table(x, file="", row.names=FALSE, col.names=FALSE)';
53 is $R->run( $cmd1 ), $expected; # RT bug #70314
54
55 my $cmd2 = <<EOF;
56 a <- 2
57 b <- 5
58 c <- a * b
59 print('ok')
60 EOF
61 $expected = '[1] "ok"';
62 is $R->run( $cmd2 ), $expected, 'Heredoc commands';
63
64 $expected =
65 '456
66 [1] "ok"';
67 is $R->run( $cmd1, $cmd2 ), $expected, 'Multiple commands';
68
69 $expected =
70 'Some innocuous message on stderr
71 loop iteration: [1] 1
72 loop iteration: [1] 2
73 loop iteration: [1] 3
74 Some innocuous message on stdout
75
76 [1] 123
77 456
78 [1] "ok"';
79 is $R->run_from_file( './t/data/script.R' ), $expected, 'Commands from file';
80