1 # $Id: run.t,v 1.1 2004/02/11 01:18:33 comdog Exp $
3 use Test::More tests => 43;
6 use File::Basename qw(basename);
9 my $script_path = 'blib/script/scriptdist';
10 my $script_name = basename( $script_path );
12 my $target_script = 'test_script';
13 my $options = $target_script;
15 my $Home = $ENV{HOME} = File::Spec->catfile(
16 getcwd(), 't', 'test_home_dir');
18 my $Templates = File::Spec->catfile( $Home, "." . $script_name );
19 my $Config = File::Spec->catfile( $Home, "." . $script_name . "rc" );
20 my $program = File::Spec->catfile( $Home, $target_script );
22 my $Makefile = File::Spec->catfile( $Templates, 'Makefile.PL' );
23 my $Install = File::Spec->catfile( $Templates, 'INSTALL' );
25 # ensure all of the files are in place
26 ok( -e $script_path, 'scriptdist exists' );
27 ok( -x $script_path, 'scriptdist is executable' );
28 ok( -e $program, 'Target program exists' );
29 ok( -e $Config, 'Config file exists' );
30 ok( -d $Templates, 'Template directory exists' );
31 ok( -f $Makefile, 'Template Makefile.PL exists' );
32 ok( -f $Install, 'Template INSTALL exists' );
36 my $changed = chdir $Home;
37 ok( $changed, 'Changed to home directory' );
39 system "../../$script_path", $options;
41 # ensure scriptdist created files
43 my @Files = ( qw(Makefile.PL Changes MANIFEST MANIFEST.SKIP INSTALL
44 .cvsignore .releaserc),
46 map { File::Spec->catfile( 't', $_ ) }
47 qw(compile.t pod.t prereq.t test_manifest)
50 my $program_dir = "$target_script.d";
51 my $t_dir = File::Spec->catfile( $program_dir, 't' );
53 # ensure directories exist
54 ok( -d $program_dir, 'Target directory exists' );
55 ok( -d $t_dir, 'Test directory exists' );
58 foreach my $file ( map { File::Spec->catfile( $program_dir, $_ ) }
61 ok( -e $file, "File $file exists" );
64 #ensure template files have replacements
65 my $install = File::Spec->catfile( $program_dir, 'INSTALL' );
66 my $opened = open my($fh), $install;
67 ok( $opened, "Opened replacements test file\n" );
68 my $data = do { local $/; <$fh> };
70 like( $data, qr/file for \Q$target_script/, 'Replacement test has script name' );
71 like( $data, qr/version \Q0.10/, 'Replacement test has version' );
72 unlike( $data, qr/%%SCRIPTDIST.*?%%/, 'Replacement test has no more placeholders' );
74 # ensure we are in the right directory before we delete files
75 $changed = chdir $program_dir;
76 ok( $changed, 'Change to program directory' );
80 diag( "cwd is $cwd\n" );
82 skip "I do not think I am in the right directory!", scalar @Files + 3,
84 like( $cwd, qr/\Q$program_dir\E$/,
85 'Path has the new directory' );
87 diag( "Cleaning up...\n" );
89 foreach my $file ( @Files )
91 #diag( "\tunlinking file $file\n" );
92 ok( unlink $file, "Removed $file" );
95 $changed = chdir '..';
96 ok( $changed, 'Moved above program dir' );
98 foreach my $dir ( $t_dir, $program_dir )
100 #diag( "\tremoving dir $dir\n" );
101 ok( rmdir $dir, "Removed $dir" );