citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

lib_viewer.t (1499B)


      1 #
      2 # Check that the runtime starts the viewer.
      3 #
      4 # Cases:
      5 # 1) citrun_gl not on the PATH
      6 # 2) citrun_gl on the PATH
      7 #
      8 use Modern::Perl;
      9 use Test::Cmd;
     10 use Test::More tests => 8;
     11 
     12 use lib 't';
     13 require utils;
     14 
     15 
     16 my $wrap = Test::Cmd->new( prog => 'bin/citrun_wrap', workdir => '' );
     17 
     18 # Write and compile bare minimum source file.
     19 $wrap->write( 'main.c', 'int main(void) { return 0; }' );
     20 $wrap->run( args => utils::os_compiler() . 'main main.c',
     21 	chdir => $wrap->curdir );
     22 
     23 # Don't check stdout.
     24 is(	$wrap->stderr,	'',	'citrun_wrap compile stderr silent' );
     25 is(	$? >> 8,	0,	'citrun_wrap compile exit code 0' );
     26 
     27 #
     28 # Case 1.
     29 #
     30 
     31 my $inst_prog = Test::Cmd->new( prog => $wrap->workdir . "/main",
     32 	workdir => '' );
     33 
     34 my $err_good = 'libcitrun: exec citrun_gl: No such file or directory';
     35 
     36 $inst_prog->run( chdir => $inst_prog->curdir );
     37 is(	$inst_prog->stdout,	'',		'case 1 stdout silent' );
     38 like(	$inst_prog->stderr,	qr/$err_good/,	'case 1 stderr an error' );
     39 is(	$? >> 8,		0,		'case 1 exit code 0' );
     40 unlink "/tmp/citrun.out";
     41 
     42 #
     43 # Case 2.
     44 #
     45 
     46 $inst_prog->write( 'citrun_gl', <<EOF );
     47 #!/bin/sh
     48 echo ran citrun_gl
     49 EOF
     50 chmod(0775, $inst_prog->workdir . '/citrun_gl') or die $!;
     51 
     52 $ENV{PATH} .= ".:";
     53 
     54 $inst_prog->run( chdir => $wrap->curdir );
     55 
     56 # citrun_gl gets forked so we must wait for it to finish.
     57 sleep(1);
     58 
     59 like(	$inst_prog->stdout,	qr/ran citrun_gl/, 'case 2 viewer started' );
     60 is(	$inst_prog->stderr,	'',	'case 2 stderr empty' );
     61 is(	$? >> 8,		0,	'case 2 exit code zero' );
     62 unlink "/tmp/citrun.out";