1#! perl
2# Copyright (C) 2007-2009, Parrot Foundation.
3
4use strict;
5use warnings;
6use 5.008;
7
8use Getopt::Long;
9use File::Spec::Functions;
10
11use Test::More tests => 6;
12
13=head1 NAME
14
15tools/install/smoke.pl - checks parrot in install directory
16
17=head1 SYNOPSIS
18
19parrot in install tree
20
21    % cd /usr/local/parrot-$version
22    % perl smoke.pl
23
24parrot in build tree
25
26    % perl tools/install/smoke.pl --bindir=.
27
28test installation in DESTDIR:
29
30    % cd /usr/src/parrot
31    % mkdir .inst
32    % make install DESTDIR=.inst
33    % perl tools/install/smoke.pl DESTDIR=.inst
34
35=head1 DESCRIPTION
36
37Checks that most of things run (or just start) into the install directory,
38try to detect missing parts.
39
40=head1 OPTIONS
41
42=over
43
44=item --bindir=/usr/bin
45
46Override default value : 'bin'
47
48=back
49
50=cut
51
52my ($bindir, $DESTDIR);
53my $opts = GetOptions(
54    'bindir=s'  => \$bindir,
55    'DESTDIR=s' => \$DESTDIR,
56);
57
58$bindir = 'bin' unless $bindir;
59
60chdir $DESTDIR if ($DESTDIR);
61
62sub quote {
63    my $exe = shift;
64    $exe .= '.exe' if ($^O eq 'MSWin32');
65    $exe = '"' . $exe . '"' if ($exe =~ / /);
66    return $exe;
67}
68
69my $filename;
70my $exe;
71my $out;
72my $FH;
73my $parrot = quote(catfile($bindir, 'parrot'));
74my $nqp = quote(catfile($bindir, 'parrot-nqp'));
75
76#
77# parrot executable
78#
79
80$exe = quote(catfile($bindir, 'pbc_merge'));
81$out = `$exe`;
82ok($out =~ /^pbc_merge/, "check pbc_merge");
83
84$exe = quote(catfile($bindir, 'pbc_dump'));
85$out = `$exe`;
86ok($out =~ /^pbc_dump/, "check pbc_dump");
87
88ok(system("$parrot -V") == 0, "display parrot version");
89
90$out = `$parrot -V`;
91$out =~ m/version (\S+) built/;
92my $version = $1;
93
94my $libdir = ($bindir eq 'bin')
95           ? ($^O eq 'MSWin32') ? 'lib/parrot/library' : "lib/parrot/$version/library"
96           : 'runtime/parrot/library';
97
98my $compdir = ($bindir eq 'bin')
99           ? ($^O eq 'MSWin32') ? 'lib/parrot/languages' : "lib/parrot/$version/languages"
100            : 'compilers';
101
102#
103# some compiler tools
104#
105
106$filename = 'test.pg';
107open $FH, '>', $filename
108        or die "Can't open $filename ($!).\n";
109print $FH <<'PGE';
110grammar WSpace
111
112token TOP { \s* }
113PGE
114close $FH;
115$out = `$parrot $libdir/PGE/Perl6Grammar.pbc $filename`;
116ok($out =~ /## <WSpace::TOP>/, "check PGE");
117unlink($filename);
118
119$filename = 'test.nqp';
120open $FH, '>', $filename
121        or die "Can't open $filename ($!).\n";
122print $FH "say('hello world!');\n";
123close $FH;
124$out = `$nqp $filename`;
125ok($out eq "hello world!\n", "check nqp-rx");
126unlink($filename);
127
128# compilers/tge is typically not installed
129$filename = 'test.tg';
130open $FH, '>', $filename
131        or die "Can't open $filename ($!).\n";
132print $FH "transform past (ROOT) { }\n";
133close $FH;
134$out = `$parrot $compdir/tge/tgc.pir $filename`;
135ok($out =~ /^\n\.sub '_ROOT_past'/, "check TGE");
136unlink($filename);
137
138# Local Variables:
139#   mode: cperl
140#   cperl-indent-level: 4
141#   fill-column: 100
142# End:
143# vim: expandtab shiftwidth=4:
144
145