⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 object.t

📁 source of perl for linux application,
💻 T
字号:
#!/usr/local/bin/perl -w# Test for File::Temp - OO interfaceuse strict;use Test::More tests => 26;use File::Spec;# Will need to check that all files were unlinked correctly# Set up an END block here to do it# Arrays containing list of dirs/files to testmy (@files, @dirs, @still_there);# And a test for files that should still be around# These are tidied upEND {  foreach (@still_there) {    ok( -f $_, "Check $_ exists" );    ok( unlink( $_ ), "Unlinked $_" );    ok( !(-f $_), "$_ no longer there");  }}# Loop over an array hoping that the files dont existEND { foreach (@files) { ok( !(-e $_), "File $_ should not be there" )} }# And a test for directoriesEND { foreach (@dirs)  { ok( !(-d $_), "Directory $_ should not be there" ) } }# Need to make sure that the END blocks are setup before# the ones that File::Temp configures since END blocks are evaluated# in reverse order and we need to check the files *after* File::Temp# removes themBEGIN {use_ok( "File::Temp" ); }# Tempfile# Open tempfile in some directory, unlink at endmy $fh = new File::Temp( SUFFIX => '.txt' );ok( (-f "$fh"), "File $fh exists"  );# Should still be around after closingok( close( $fh ), "Close file $fh" );ok( (-f "$fh"), "File $fh still exists after close" );# Check again at exitpush(@files, "$fh");# TEMPDIR test# Create temp directory in current dirmy $template = 'tmpdirXXXXXX';print "# Template: $template\n";my $tempdir = File::Temp::tempdir( $template ,				   DIR => File::Spec->curdir,				   CLEANUP => 1,				 );print "# TEMPDIR: $tempdir\n";ok( (-d $tempdir), "Does $tempdir directory exist" );push(@dirs, $tempdir);# Create file in the temp dir$fh = new File::Temp(		     DIR => $tempdir,		     SUFFIX => '.dat',		    );ok( $fh->unlink_on_destroy, "should unlink");print "# TEMPFILE: Created $fh\n";ok( (-f "$fh"), "File $fh exists in tempdir?");push(@files, "$fh");# Test tempfile# ..and again (without unlinking it)$fh = new File::Temp( DIR => $tempdir, UNLINK => 0 );print "# TEMPFILE: Created $fh\n";ok( (-f "$fh" ), "Second file $fh exists in tempdir [nounlink]?");push(@files, "$fh");# and another (with template)$fh = new File::Temp( TEMPLATE => 'helloXXXXXXX',		      DIR => $tempdir,		      SUFFIX => '.dat',		    );print "# TEMPFILE: Created $fh\n";ok( (-f "$fh"), "File $fh exists? [from template]" );push(@files, "$fh");# Create a temporary file that should stay around after# it has been closed$fh = new File::Temp( TEMPLATE => 'permXXXXXXX', UNLINK => 0);print "# TEMPFILE: Created $fh\n";ok( -f "$fh", "File $fh exists?" );ok( close( $fh ), "Close file $fh" );ok( ! $fh->unlink_on_destroy, "should not unlink");push( @still_there, "$fh"); # check at END# Now create a temp file that will remain when the object# goes out of scope because of $KEEP_ALL$fh = new File::Temp( TEMPLATE => 'permXXXXXXX', UNLINK => 1);print "# TEMPFILE: Created $fh\n";ok( -f "$fh", "File $fh exists?" );ok( close( $fh ), "Close file $fh" );ok( $fh->unlink_on_destroy, "should unlink (in principal)");push( @still_there, "$fh"); # check at END$File::Temp::KEEP_ALL = 1;# Make sure destructors runundef $fh;# allow end blocks to run$File::Temp::KEEP_ALL = 0;# Now END block will execute to test the removal of directoriesprint "# End of tests. Execute END blocks\n";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -