From: Chris W. <la...@us...> - 2004-12-05 18:50:24
|
Update of /cvsroot/openinteract/OpenInteract2/t In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10472/t Modified Files: 00_manage_create_website.t config_readonly.t utils.pl Log Message: modify OI2::Config::Readonly to be more usable (object instead of class methods); modify all usages, tests, etc. Index: 00_manage_create_website.t =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/t/00_manage_create_website.t,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** 00_manage_create_website.t 28 Nov 2004 20:29:09 -0000 1.1 --- 00_manage_create_website.t 5 Dec 2004 18:50:11 -0000 1.2 *************** *** 17,21 **** my $website_dir = get_test_site_dir(); ! # If the testing site already exists it's history if ( -d $website_dir ) { rmtree( $website_dir ); --- 17,21 ---- my $website_dir = get_test_site_dir(); ! # Delete the testing site if it already exists if ( -d $website_dir ) { rmtree( $website_dir ); Index: config_readonly.t =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/t/config_readonly.t,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** config_readonly.t 6 Jun 2004 06:13:40 -0000 1.4 --- config_readonly.t 5 Dec 2004 18:50:11 -0000 1.5 *************** *** 7,12 **** require 'utils.pl'; use File::Copy qw( cp ); ! use File::Spec::Functions qw( catfile ); ! use Test::More tests => 12; require_ok( 'OpenInteract2::Config::Readonly' ); --- 7,12 ---- require 'utils.pl'; use File::Copy qw( cp ); ! use File::Spec::Functions qw( catfile ); ! use Test::More tests => 14; require_ok( 'OpenInteract2::Config::Readonly' ); *************** *** 14,64 **** my $use_dir = get_use_dir(); ! # Copy our test data to the right name ! cp( get_use_file( 'test_no_overwrite', 'name' ), ! get_use_file( '.no_overwrite', 'name' ) ); ! # Check reading the file ! my $readonly = OpenInteract2::Config::Readonly->read_config( $use_dir ); ! is( scalar @{ $readonly }, 2, 'Number of readonly entries' ); ! is( $readonly->[0], 'test_file.pdf', 'Readonly entry 1' ); ! is( $readonly->[1], 'test_file.gif', 'Readonly entry 2' ); ! # Check is_writeable_file against the list and directory ! my $write_enum_nok = OpenInteract2::Config::Readonly ! ->is_writeable_file( $readonly, 'test_file.pdf' ); ! my $write_dir_nok = OpenInteract2::Config::Readonly ! ->is_writeable_file( $use_dir, 'test_file.pdf' ); ! my $write_enum_ok = OpenInteract2::Config::Readonly ! ->is_writeable_file( $readonly, 'test_nonexist.pdf' ); ! my $write_dir_ok = OpenInteract2::Config::Readonly ! ->is_writeable_file( $use_dir, 'test_nonexist.pdf' ); ! ok( ! $write_enum_nok, "Marked readonly file from list" ); ! ok( ! $write_dir_nok, "Marked readonly file from dir" ); ! ok( $write_enum_ok, "Not marked readonly file from list" ); ! ok( $write_dir_ok, "Not marked readonly file from dir" ); ! # Check get_writeable_files against files in t/ using listing and $dir - opendir( USEDIR, $use_dir ); - my @test_files = grep { -f catfile( $use_dir, $_ ) } - readdir( USEDIR ); - my $writeable_enum = OpenInteract2::Config::Readonly - ->get_writeable_files( $readonly, \@test_files ); - my $writeable_dir = OpenInteract2::Config::Readonly - ->get_writeable_files( $use_dir, \@test_files ); - is( scalar @{ $writeable_enum }, scalar( @test_files ) - 2, "Number of writeable files from list" ); - is( scalar @{ $writeable_dir }, scalar( @test_files ) - 2, "Number of writeable files from dir" ); unlink( get_use_file( '.no_overwrite' ) ); ! # Check writing a config - my $file_written = eval { - OpenInteract2::Config::Readonly - ->write_config( $use_dir, [ 'file_a.txt', 'file_b.txt' ] ) - }; - ok( ! $@, 'Readonly listing written to file' ) || diag "Error: $@"; - my $read_written = get_use_file( '.no_overwrite', 'content' ); - is( $read_written, "file_a.txt\nfile_b.txt", 'Written readonly listing matches' ); unlink( get_use_file( '.no_overwrite' ) ); --- 14,88 ---- my $use_dir = get_use_dir(); ! # get rid of any leftovers ! unlink( get_use_file( '.no_overwrite', 'name' ) ); ! { ! # Copy our test data to the right name ! cp( get_use_file( 'test_no_overwrite', 'name' ), ! get_use_file( '.no_overwrite', 'name' ) ); ! my $ro = eval { OpenInteract2::Config::Readonly->new( $use_dir ) }; ! is( ref( $ro ), 'OpenInteract2::Config::Readonly', ! 'Constructor returned object of correct type' ); ! is( $ro->directory, $use_dir, ! 'Directory property same as what we passed into constructor' ); ! # Check number of files read in ! my $readonly_files = $ro->get_readonly_files; ! is( scalar @{ $readonly_files }, 2, 'Number of readonly entries' ); ! my %readonly_map = map { $_ => 1 } @{ $readonly_files }; ! for ( qw( test_file.pdf test_file.gif ) ) { ! ok( $readonly_map{ $_ }, "Readonly entry exists '$_'" ); ! } ! # Check is_writeable against the list and directory ! ok( ! $ro->is_writeable( 'test_file.pdf' ), ! 'Readonly file is not writeable' ); ! ok( $ro->is_writeable( 'test_nonexist.pdf' ), ! 'Non-readonly file is writeable' ); ! # Check case_sensitivity ! ok( $ro->is_writeable( 'test_file.PDF' ), ! 'Readonly file with uppercase extension is writeable' ); ! ! # Check list of all writeable files against what we read ! my $writeable_files = $ro->get_all_writeable_files; ! ! opendir( USEDIR, $use_dir ); ! my @test_files = grep { -f catfile( $use_dir, $_ ) } ! grep { $_ ne '.no_overwrite' } ! readdir( USEDIR ); ! ! is( scalar @{ $writeable_files }, scalar( @test_files ) - 2, ! 'Number of writeable files from dir' ) ! || diag( "Writeable: " . join( ', ', @{ $writeable_files } ) . "\n" . ! "Test: " . join( ', ', @test_files ) ); ! } unlink( get_use_file( '.no_overwrite' ) ); ! { ! # Check writing a config ! my $ro = OpenInteract2::Config::Readonly->new( $use_dir ); ! eval { ! $ro->write_readonly_files( [ 'file_a.txt', 'file_b.txt' ] ); ! }; ! ok( ! $@, 'Readonly listing written to file' ) || diag "Error: $@"; ! my $read_written = get_use_file( '.no_overwrite', 'content' ); ! is( $read_written, "file_a.txt\nfile_b.txt", ! 'Written readonly listing matches' ); ! ! # ...with comment ! eval { ! $ro->write_readonly_files( [ 'file_a.txt', 'file_b.txt' ], ! 'This is a comment' ); ! }; ! ok( ! $@, 'Readonly listing with comment written to file' ) ! || diag "Error: $@"; ! my $read_written_cmt = get_use_file( '.no_overwrite', 'content' ); ! is( $read_written_cmt, "# This is a comment\n\nfile_a.txt\nfile_b.txt", ! 'Written readonly listing with comment matches' ); ! } unlink( get_use_file( '.no_overwrite' ) ); + Index: utils.pl =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/t/utils.pl,v retrieving revision 1.83 retrieving revision 1.84 diff -C2 -d -r1.83 -r1.84 *** utils.pl 5 Dec 2004 08:51:18 -0000 1.83 --- utils.pl 5 Dec 2004 18:50:11 -0000 1.84 *************** *** 23,32 **** BEGIN { ! $log = OpenInteract2::Log->init_file( 'oi2_tests.log', $DEBUG ); ! $log->info( "Starting test run" ); } END { ! $log->info( "Finished test run" ); } --- 23,35 ---- BEGIN { ! #my $log_level = $DEBUG; ! # TODO: Change before distributing! ! my $log_level = $WARN; ! $log = OpenInteract2::Log->init_file( 'oi2_tests.log', $log_level ); ! $log->warn( "Starting test run" ); } END { ! $log->warn( "Finished test run" ); } |