#! perl -w # filetest.t # should be invoked from different directories (prove -r). use strict; use warnings; use Test::More tests => 2; use File::Basename; use File::Spec; my $filename = (eval{caller})[1]; diag("filename of this test-script: $filename"); my $dirname = dirname( $filename ); diag("dirname of this test-script: $dirname"); my $location = File::Spec->catfile( $dirname, 'non-existing-file' ); diag("testing a non existing file: $location"); cmp_ok( defined -f $location, '==', 1, 'this test should fail' ); $location = File::Spec->catfile( $dirname, 'filetest.t' ); diag("testing an existing file: $location"); cmp_ok( defined -f $location, '==', 1, 'this file should exist' ); #### 1..2 # filename of this test-script: lib/t/filetest.t # dirname of this test-script: lib/t # testing a non existing file: lib/t/non-existing-file not ok 1 - this test should fail # Failed test 'this test should fail' # at lib/t/filetest.t line 19. # got: # expected: 1 # testing an existing file: lib/t/filetest.t ok 2 - this file should exist # Looks like you failed 1 test of 2.