2 # Copyright (C) 2005-2010, Parrot Foundation.
7 t/run/options.t - test parrot command line options
11 % prove t/run/options.t
15 Tests C<parrot> command line options.
21 use lib qw( lib . ../lib ../../lib );
23 use Test::More tests => 28;
25 use File::Temp 0.13 qw/tempfile/;
28 my $PARROT = ".$PConfig{slash}$PConfig{test_prog}";
30 # looking at the help message
31 my $help_message = `$PARROT --help`;
32 is( substr( $help_message, 0, 23 ), 'parrot [Options] <file>', 'Start of help message' );
33 ok( index( $help_message, '-t --trace [flags]' ) > 0, 'help for --trace' );
35 # setup PIR files for tests below
36 my $first_pir_file = create_pir_file('first');
37 my $second_pir_file = create_pir_file('second');
39 # executing a PIR file
40 is( `"$PARROT" "$first_pir_file"`, "first\n", 'running first.pir' );
41 is( `"$PARROT" "$second_pir_file"`, "second\n", 'running second.pir' );
43 # Ignore further arguments
44 is( `"$PARROT" "$first_pir_file" "$second_pir_file"`, "first\n", 'ignore a pir-file' );
45 is( `"$PARROT" "$first_pir_file" "asdf"`, "first\n", 'ignore nonsense' );
47 # redirect STDERR to avoid warnings
48 my $redir = '2>' . File::Spec->devnull();
51 # This is just sanity testing
52 my $expected_preprocesses_pir = <<'END_PIR';
63 is( `"$PARROT" -E "$first_pir_file" $redir`, $expected_preprocesses_pir, 'option -E' );
64 is( `"$PARROT" --pre-process-only "$first_pir_file" $redir`,
65 $expected_preprocesses_pir, 'option --pre-process-only' );
67 # Test the trace option
68 is( `"$PARROT" -t "$first_pir_file" $redir`, "first\n", 'option -t' );
69 is( `"$PARROT" --trace "$first_pir_file" $redir`, "first\n", 'option --trace' );
70 is( `"$PARROT" -t "$first_pir_file" "$second_pir_file" $redir`, "second\n",
71 'option -t with flags' );
72 is( `"$PARROT" --trace "$first_pir_file" "$second_pir_file" $redir`,
73 "second\n", 'option --trace with flags' );
75 ## test the -R & --runcore options
79 ## this test assumes these cores work on all platforms (a safe assumption)
80 for my $val (qw/ slow fast bounds trace /) {
81 for my $opt ( '-R ', '--runcore ', '--runcore=' ) {
82 $cmd = qq{"$PARROT" $opt$val "$second_pir_file" $redir};
83 is( qx{$cmd}, "second\n", "<$opt$val> option)" ) or diag $cmd;
87 $cmd = qq{"$PARROT" -D 8 -R slow "$second_pir_file" $redir};
88 is( qx{$cmd}, "second\n", "-r option <$cmd>" );
90 $cmd = qq{"$PARROT" -D 8 -R slow "$second_pir_file" 2>&1};
91 like( qx{$cmd}, qr/Parrot VM: slow core/, "-r option <$cmd>" );
94 ## TT #1150 test remaining options
96 # Test --runtime-prefix
97 like( qx{$PARROT --runtime-prefix}, qr/^.+$/, "--runtime-prefix" );
99 # clean up temporary files
100 unlink $first_pir_file;
101 unlink $second_pir_file;
103 sub create_pir_file {
106 my ( $fh, $filename ) = tempfile( UNLINK => 0, SUFFIX => '.pir', UNLINK => 1 );
107 print $fh <<"END_PIR";
122 #make sure that VERSION matches the output of --version
123 open(my $version_fh, "<", "VERSION") or die "couldn't open VERSION: $!";
124 my $file_version = <$version_fh>;
125 chomp($file_version);
127 like( qx{$PARROT --version}, qr/.*${file_version}.*/, "VERSION matches --version" );
132 # cperl-indent-level: 4
135 # vim: expandtab shiftwidth=4: