#!/usr/local/bin/perl -w =head1 NAME p4.t - testing of vcp p4 i/o =cut use strict ; use Carp ; use Cwd ; use File::Path ; use File::Spec ; use IPC::Run qw( run ) ; use POSIX ':sys_wait_h' ; use Test ; use VCP::TestUtils ; my $cwd = cwd ; ## TODO: Test bootstrap mode my %seen ; my @perl = ( $^X, map { my $s = $_ ; $s = File::Spec->rel2abs( $_ ) ; "-I$s" ; } grep ! $seen{$_}++, @INC ) ; ## We always run vcp by doing a @perl, vcp, to make sure that vcp runs under ## the same version of perl that we are running under. my $vcp = 'vcp' ; $vcp = "bin/$vcp" if -x "bin/$vcp" ; $vcp = "../bin/$vcp" if -x "../bin/$vcp" ; $vcp = File::Spec->rel2abs( $vcp ) ; my @vcp = ( @perl, $vcp ) ; my $t = -d 't' ? 't/' : '' ; my $p4_options = p4_options "p4_" ; #my $p4repo = File::Spec->catdir( $tmp, "p4repo" ) ; #my $p4work = File::Spec->catdir( $tmp, "p4work" ) ; #my ( $p4user, $p4client, $p4port ) = qw( p4_t_user p4_t_client 19666 ) ; my $p4spec = "p4:$p4_options->{user}($p4_options->{client}):\@$p4_options->{port}:" ; my $tmp = File::Spec->tmpdir ; my $cvsroot = File::Spec->catdir( $tmp, "p4cvsroot" ) ; my $cvswork = File::Spec->catdir( $tmp, "p4cvswork" ) ; END { rmtree [ $p4_options->{repo}, $p4_options->{work}, $cvsroot, $cvswork ] ; } $ENV{CVSROOT} = $cvsroot; my $cvs_module = 'depot' ; my $depot = "//depot" ; my $incr_change ; # what change number to start incremental export at sub slurp { my ( $fn ) = @_ ; open F, "<$fn" or die "$!: $fn" ; local $/ ; return <F> ; } my @tests = ( sub {}, ## Two ok's in next test. sub { ## revml -> p4 -> revml, bootstrap export my $type = 'p4' ; my $infile = $t . "test-$type-in-0.revml" ; my $outfile = $t . "test-$type-out-0.revml" ; my $infile_t = "test-$type-in-0-tweaked.revml" ; my $outfile_t = "test-$type-out-0-tweaked.revml" ; ## ## Idempotency test ## ## These depend on the "test-foo-in-0.revml" files built in the makefile. ## See MakeMaker.PL for how those are generated. ## my $diff = '' ; eval { my $out ; ## $in and $out allow us to avoide execing diff most of the time. run [ @vcp, "revml:$infile", $p4spec, '-w', $p4_options->{work} ], \undef or die "`$vcp revml:$infile $p4spec` returned $?" ; ok( 1 ) ; run [ @vcp, "$p4spec..." ], \undef, \$out or die "`$vcp $p4spec...` returned $?" ; my $in = slurp $infile ; #$out =~ s{<name>depot/}{<name>}g ; $in =~ s{^\s*<p4_info>.*?</p4_info>\n}{}smg ; $in =~ s{<rep_desc>.*?</rep_desc>}{<rep_desc><!--deleted by p4.t--></rep_desc>}s ; $out =~ s{<rep_desc>.*?</rep_desc>}{<rep_desc><!--deleted by p4.t--></rep_desc>}s ; $in =~ s{<time>.*?</time>}{<time><!--deleted by p4.t--></time>}sg ; $out =~ s{<time>.*?</time>}{<time><!--deleted by p4.t--></time>}sg ; $out =~ s{\s*<p4_info>.*?</p4_info>}{}sg ; ## The r_ and ch_ labels are not present in the source files. $out =~ s{.*<label>(r|ch)_\w+</label>\r?\n\r?}{}g ; open F, ">$infile_t" ; print F $in ; close F ; open F, ">$outfile_t" ; print F $out ; close F ; if ( $in ne $out && run( [ 'diff', '-U', '10', $infile_t, $outfile_t ], \undef, \$diff ) && $? != 256 ) { die "`diff -d -u $infile_t $outfile_t` returned $?" ; } } ; $diff = $@ if $@ ; chomp $diff ; ok( $diff, '' ) ; if ( $diff eq '' ) { if ( -e $infile_t ) { unlink $infile_t or warn "$!: $infile_t" ; } if ( -e $outfile_t ) { unlink $outfile_t or warn "$!: $outfile_t" ; } } # chdir $cwd or die "$!: $cwd" ; }, sub { ## Test a single file extraction from a p4 repo. This file exists in ## change 1. my $out ; run( [@vcp, "$p4spec//depot/add/f1"], \undef, \$out ) ; ok( $out, qr{<rev_root>depot/add</.+<name>f1<.+<rev_id>1<.+<rev_id>2<.+</revml>}s ) ; }, sub { ## Test a single file extraction from a p4 repo. This file does not exist ## in change 1. my $out ; run( [@vcp, "$p4spec//depot/add/f2"], \undef, \$out ) ; ok( $out, qr{<rev_root>depot/add</.+<name>f2<.+<change_id>2<.+<change_id>3<.+</revml>}s ) ; }, sub {}, ## Two ok's in next test. sub { ## p4 -> cvs bootstrap my $type = 'p4' ; my $infile = $t . "test-$type-in-0.revml" ; my $outfile = $t . "test-$type-out-0-cvs.revml" ; my $infile_t = "test-$type-in-0-cvs-tweaked.revml" ; my $outfile_t = "test-$type-out-0-cvs-tweaked.revml" ; ## ## Idempotency test ## ## These depend on the "test-foo-in.revml" files built in the makefile. ## See MakeMaker.PL for how those are generated. ## my $diff = '' ; eval { my $out ; run( [ @vcp, "$p4spec//depot/...", "cvs" ], \undef ) or die "`$vcp $p4spec//depot/... cvs` returned $?" ; ok( 1 ) ; ## Gotta use a working directory with a checked-out version chdir $cvswork or die $! . ": '$cvswork'" ; run [qw( cvs checkout ), $cvs_module], \undef, \*STDERR or die $! ; run( [ @vcp, "cvs:$cvs_module", qw( -r 1.1: ) ], \undef, \$out ) or die "`$vcp cvs:$cvs_module -r 1.1: ` returned $?" ; chdir $cwd or die $! ; my $in = slurp $infile ; #$out =~ s{<name>depot/}{<name>}g ; $in =~ s{^\s*<p4_info>.*?</p4_info>\n}{}smg ; $in =~ s{<rep_type>.*?</rep_type>}{<rep_type><!--deleted by p4.t--></rep_type>}s ; $out =~ s{<rep_type>.*?</rep_type>}{<rep_type><!--deleted by p4.t--></rep_type>}s ; $in =~ s{<rep_desc>.*?</rep_desc>}{<rep_desc><!--deleted by p4.t--></rep_desc>}s ; $out =~ s{<rep_desc>.*?</rep_desc>}{<rep_desc><!--deleted by p4.t--></rep_desc>}s ; $in =~ s{^\s*<change_id>.*?</change_id>\n}{}smg ; $out =~ s{^\s*<label>r_.*?</label>\n}{}smg ; $out =~ s{^\s*<label>ch_.*?</label>\n}{}smg ; $out =~ s{<rev_id>1.}{<rev_id>}g ; $out =~ s{<base_rev_id>1.}{<base_rev_id>}g ; $in =~ s{<user_id>.*?</user_id>}{<user_id><!--deleted by p4.t--></user_id>}sg ; $out =~ s{<user_id>.*?</user_id>}{<user_id><!--deleted by p4.t--></user_id>}sg ; $in =~ s{<time>.*?</time>}{<time><!--deleted by p4.t--></time>}sg ; $out =~ s{<time>.*?</time>}{<time><!--deleted by p4.t--></time>}sg ; $out =~ s{\s*<p4_info>.*?</p4_info>}{}sg ; open F, ">$infile_t" ; print F $in ; close F ; open F, ">$outfile_t" ; print F $out ; close F ; if ( $in ne $out && run( [ 'diff', '-U', '10', $infile_t, $outfile_t ], \undef, \$diff ) && $? != 256 ) { die "`diff -d -u $infile_t $outfile_t returned $?" ; } } ; $diff = $@ if $@ ; chomp $diff ; ok( $diff, '' ) ; if ( $diff eq '' ) { if ( -e $infile_t ) { unlink $infile_t or warn "$!: $infile_t" ; } if ( -e $outfile_t ) { unlink $outfile_t or warn "$!: $outfile_t" ; } } }, sub {}, ## Two ok's in next test. sub { ## revml -> p4 -> revml, incremental export my $type = 'p4' ; my $infile = $t . "test-$type-in-1.revml" ; my $outfile = $t . "test-$type-out-1.revml" ; my $infile_t = "test-$type-in-1-tweaked.revml" ; my $outfile_t = "test-$type-out-1-tweaked.revml" ; ## ## Idempotency test ## ## These depend on the "test-foo-in-0.revml" files built in the makefile. ## See MakeMaker.PL for how those are generated. ## my $diff = '' ; eval { run [ qw( p4 -u ), $p4_options->{user}, "-c", $p4_options->{client}, "-p", $p4_options->{port}, qw( counter change ) ], \undef, \$incr_change ; chomp $incr_change ; die "Invalid change counter value: '$incr_change'" unless $incr_change =~ /^\d+$/ ; ++$incr_change ; my $out ; ## $in and $out allow us to avoide execing diff most of the time. run [ @vcp, "revml:$infile", "$p4spec", '-w', $p4_options->{work} ], \undef or die "`$vcp revml:$infile $p4spec` returned $?" ; ok( 1 ) ; run [ @vcp, "$p4spec...\@$incr_change,#head" ], \undef, \$out or die "`$vcp $p4spec...\@$incr_change,#head` returned $?" ; my $in = slurp $infile ; $out =~ s{<name>depot/}{<name>}g ; $in =~ s{^\s*<p4_info>.*?</p4_info>\n}{}smg ; $in =~ s{<rep_desc>.*?</rep_desc>}{<rep_desc><!--deleted by p4.t--></rep_desc>}s ; $out =~ s{<rep_desc>.*?</rep_desc>}{<rep_desc><!--deleted by p4.t--></rep_desc>}s ; $in =~ s{<time>.*?</time>}{<time><!--deleted by p4.t--></time>}sg ; $out =~ s{<time>.*?</time>}{<time><!--deleted by p4.t--></time>}sg ; $out =~ s{\s*<p4_info>.*?</p4_info>}{}sg ; ## The r_ and ch_ labels are not present in the source files. $out =~ s{.*<label>(r|ch)_\w+</label>\r?\n\r?}{}g ; open F, ">$infile_t" ; print F $in ; close F ; open F, ">$outfile_t" ; print F $out ; close F ; if ( $in ne $out && run( [ 'diff', '-U', '10', $infile_t, $outfile_t ], \undef, \$diff ) && $? != 256 ) { die "`diff -d -u $infile_t $outfile_t returned $?" ; } } ; $diff = $@ if $@ ; chomp $diff ; ok( $diff, '' ) ; if ( $diff eq '' ) { if ( -e $infile_t ) { unlink $infile_t or warn "$!: $infile_t" ; } if ( -e $outfile_t ) { unlink $outfile_t or warn "$!: $outfile_t" ; } } # chdir $cwd or die "$!: $cwd" ; }, sub { ## p4 -> revml, incremental export in bootstrap mode my $type = 'p4' ; my $infile = $t . "test-$type-in-1-bootstrap.revml" ; my $outfile = $t . "test-$type-out-1-bootstrap.revml" ; my $infile_t = "test-$type-in-1-bootstrap-tweaked.revml" ; my $outfile_t = "test-$type-out-1-bootstrap-tweaked.revml" ; ## ## Idempotency test ## ## These depend on the "test-foo-in-0.revml" files built in the makefile. ## See MakeMaker.PL for how those are generated. ## my $diff = '' ; eval { my $out ; run( [ @vcp, "$p4spec...\@$incr_change,#head", "--bootstrap=**" ], \undef, \$out ) or die( "`$vcp $p4spec...\@$incr_change,#head --bootstrap=**` returned $?" ) ; my $in = slurp $infile ; $out =~ s{<name>depot/}{<name>}g ; $in =~ s{^\s*<p4_info>.*?</p4_info>\n}{}smg ; $in =~ s{<rep_desc>.*?</rep_desc>}{<rep_desc><!--deleted by p4.t--></rep_desc>}s ; $out =~ s{<rep_desc>.*?</rep_desc>}{<rep_desc><!--deleted by p4.t--></rep_desc>}s ; $in =~ s{<time>.*?</time>}{<time><!--deleted by p4.t--></time>}sg ; $out =~ s{<time>.*?</time>}{<time><!--deleted by p4.t--></time>}sg ; $out =~ s{\s*<p4_info>.*?</p4_info>}{}sg ; ## The r_ and ch_ labels are not present in the source files. $out =~ s{.*<label>(r|ch)_\w+</label>\r?\n\r?}{}g ; open F, ">$infile_t" ; print F $in ; close F ; open F, ">$outfile_t" ; print F $out ; close F ; if ( $in ne $out && run( [ 'diff', '-U', '10', $infile_t, $outfile_t ], \undef, \$diff ) && $? != 256 ) { die "`diff -d -u $infile_t $outfile_t` returned $?" ; } } ; $diff = $@ if $@ ; chomp $diff ; ok( $diff, '' ) ; if ( $diff eq '' ) { if ( -e $infile_t ) { unlink $infile_t or warn "$!: $infile" ; } if ( -e $outfile_t ) { unlink $outfile_t or warn "$!: $outfile" ; } } # chdir $cwd or die "$!: $cwd" ; }, ) ; plan tests => scalar @tests ; ## ## Build a repository and they will come... ## my $why_skip ; my $p4d_borken = p4d_borken ; $why_skip .= "# '$vcp' not found\n" unless -x $vcp ; $why_skip .= "p4 command not found\n" unless ( `p4 -V` || 0 ) =~ /^Perforce/ ; $why_skip .= "$p4d_borken\n" if $p4d_borken ; unless ( $why_skip ) { ## Give vcp ... p4:... a repository to work with. Note that it does not ## use $p4work, just this test script does. rmtree [ $p4_options->{repo}, $p4_options->{work} ] ; mkpath [ $p4_options->{repo}, $p4_options->{work} ], 0, 0700 ; # END { rmtree [$p4repo,$p4work] } rmtree [ $cvsroot, $cvswork ] ; mkpath [ $cvsroot, $cvswork ], 0, 0700 ; # END { rmtree [$cvsroot,$cvswork] } $ENV{P4USER} = "foobar_user" ; $ENV{P4PORT} = "foobar_port" ; $ENV{P4CLIENT} = "foobar_client" ; $ENV{P4PASSWD} = "foobar_passwd" ; launch_p4d $p4_options ; init_p4_client $p4_options ; init_cvs() ; } print STDERR $why_skip if $why_skip ; $why_skip ? skip( 1, '' ) : $_->() for @tests ; ############################################################################### sub init_cvs { ## Give vcp ... cvs:... a repository to work with. Note that it does not ## use $cvswork, just this test script does. system qw( cvs init ) and die "cvs init failed" ; chdir $cvswork or die "$!: $cvswork" ; mkdir $cvs_module, 0770 or die "$!: $cvs_module" ; chdir $cvs_module or die "$!: $cvs_module" ; system qw( cvs import -m foo ), $cvs_module, $cvs_module, qw( foo ) and die "cvs import failed" ; chdir $cwd or die "$!: $cwd" ; # chdir ".." or die "$! .." ; # # system qw( cvs checkout CVSROOT/modules ) and die "cvs checkout failed" ; # # open MODULES, ">>CVSROOT/modules" or die "$!: CVSROOT/modules" ; # print MODULES "\n$module $module/\n" or die "$!: CVSROOT/modules" ; # close MODULES or die "$!: CVSROOT/modules" ; # # system qw( cvs commit -m foo CVSROOT/modules ) # and die "cvs commit failed" ; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#30 | 2589 | John Fetkovich |
Split 90p4.t into 90revml2p4_0.t, 90revml2p4_1.t, 91p42revml.t, 95p42cvs.t. Added some utilities to the library files listed. |
||
#29 | 2368 | John Fetkovich | removed __ok debug sub, replaced calls with ok. | ||
#28 | 2319 | Barrie Slaymaker | make t/test-*.revml be consistent with cvs2p4 and p42cvs scenarios | ||
#27 | 2276 | Barrie Slaymaker |
optimize away extra p4 label -o / -i calls for speed, elegance update t/90p4.t |
||
#26 | 2247 | Barrie Slaymaker | add $ENV{CVSBORKEN} | ||
#25 | 2059 | Barrie Slaymaker | Support for branching in p4->p4 added | ||
#24 | 2049 | Barrie Slaymaker | Get branching working in Dest::p4, clean up some tests. | ||
#23 | 2042 | Barrie Slaymaker | Basic source::p4 branching support | ||
#22 | 2006 | Barrie Slaymaker |
more preparations for branching support, handling of cvs :foo:... CVSROOT specs, misc fixes, improvements |
||
#21 | 1998 | Barrie Slaymaker | Initial, revml and core VCP support for branches | ||
#20 | 1855 | Barrie Slaymaker |
Major VSS checkin. Works on Win32 |
||
#19 | 1816 | Barrie Slaymaker | hack around the p4 client -o Options: hibit corruption problem | ||
#18 | 1728 | Barrie Slaymaker | CVS on win32, minor bugfixes | ||
#17 | 1358 | Barrie Slaymaker | Win32 changes | ||
#16 | 1055 | Barrie Slaymaker |
add sorting, revamp test suite, misc cleanup. Dest/revml is not portable off my system yet (need to release ...::Diff) |
||
#15 | 827 | Barrie Slaymaker | Add a test for and debug p4->cvs incremental exports. | ||
#14 | 825 | Barrie Slaymaker |
test, handle case where no revs are transferred and VCP::Dest::*::handle_footer() blew up. |
||
#13 | 815 | Barrie Slaymaker | minor cleanup. | ||
#12 | 719 | Barrie Slaymaker | vcp 0.221 | ||
#11 | 701 | Barrie Slaymaker | Fixed VCP::Dest::p4 re-rooting problem, further t/* cleanup | ||
#10 | 699 | Barrie Slaymaker | test suite cleanup | ||
#9 | 692 | Barrie Slaymaker |
Add VCP::Utils::p4 and use it to get VCP::Dest::p4 to create it's own client view as needed. |
||
#8 | 669 | Barrie Slaymaker |
0.1 Wed Jul 4 00:27:35 EDT 2001 Fix VCP::Dest::p4 to take the filespec from the p4:<dest> spec and use it as the rev_root. No --rev-root option at this time, not sure if it's needed. Reported by david d zuhn <zoo@bravara.com>. |
||
#7 | 615 | Barrie Slaymaker |
Detect p4d <= 99.2 and skip tests. Fix a use strict problem. Both reported by Nick Ing-Simmons. |
||
#6 | 608 | Barrie Slaymaker |
Lots of changes to get vcp to install better, now up to 0.066. Many thanks to Matthew Attaway for testing & suggestions. |
||
#5 | 481 | Barrie Slaymaker | Made test suites use File::Spec->tmpdir and clean up after themselves | ||
#4 | 478 | Barrie Slaymaker |
0.05 Mon Dec 18 07:27:53 EST 2000 - Use `p4 labels //...@label` command as per Rober Cowham's suggestion, with the '-s' flag recommended by Christopher Siewald and Amaury.FORGEOTDARC@atsm.fr. Though it's actually something like vcp: running /usr/bin/p4 -u safari -c safari -p localhost:5666 -s files //.../NtLkly //...@compiler_a3 //.../NtLkly //...@compiler_may3 and so //on //for 50 parameters to get the speed up. I use the //.../NtLkly "file" as //a separator between the lists of files in various //revisions. Hope nobody has any files named that :-). What I should do is choose a random label that doesn't occur in the labels list, I guess. - VCP::Source::revml and VCP::Dest::revml are now binary, control code, and "hibit ASCII" (I know, that's an oxymoron) clean. The <comment>, <delta>, and <content> elements now escape anything other than tab, line feed, space, or printable chars (32 <= c <= ASCII 126) using a tag like '<char code="0x09">'. The test suite tests all this. Filenames should also be escaped this way, but I didn't get to that. - The decision whether to do deltas or encode the content in base64 is now based on how many characters would need to be escaped. - We now depend on the users' diff program to have a "-a" option to force it to diff even if the files look binary to it. I need to use Diff.pm and adapt it for use on binary data. - VCP::Dest::cvs now makes sure that no two consecutive revisions of the same file have the same mod_time. VCP::Source::p4 got so fast at pulling revisions from the repositories the test suite sets up that CVS was not noticing that files had changed. - VCP::Plugin now allows you to set a list of acceptable result codes, since we now use p4 in ways that make it return non-zero result codes. - VCP::Revs now croaks if you try to add two entries of the same VCP::Rev (ie matching filename and rev_id). - The <type> tag is now limited to "text" or "binary", and is meant to pass that level of info between foreign repositories. - The <p4_info> on each file now carries the one line p4 description of the file so that p4->p4 transferes can pick out the more detailed info. VCP::Source::p4, VCP::Dest::p4 do this. - VCP::{Source,Dest}::{p4,cvs} now set binaryness on added files properly, I think. For p4->p4, the native p4 type is preserved. For CVS sources, seeing the keyword substitution flag 'o' or 'b' implies binaryness, for p4, seeing a filetype like qr/u?x?binary/ or qr/x?tempobj/ or "resource" implies binaryness (to non-p4 destinations). NOTE: Seeing a 'o' or 'b' in a CVS source only ends up setting the 'b' option on the destination. That should be ok for most uses, but we can make it smarter for cvs->cvs transfers if need be. |
||
#3 | 473 | Barrie Slaymaker |
0.04 Tue Dec 12 00:15:57 EST 2000 - Reorg of VCP::Source::p4 - One large filelog command is run instead of many small ones. This takes advantage of the -m option to make sure enough changes are listed. Many extra revisions of most files are probably listed, but listing and ignoring them is quicker than spawning p4 over and over. Wish p4 filelog had a revision range... - it now doesn't suck the entire filelog output in to memory, it parses it line by line as it's emitted from the `p4 filelog` - `p4 print` is now used to print a bunch of files at once, using the header line to separate one file from the next, kind of like splitting a mime-encoded message. There's a very slight chance that it will misjudge the boundary between two files if a file happens to have a line that looks very much like the header line for the next file. This is pretty unlikely and I'll fix it if it crops up. I could batch them more, right now it never puts two revisions of the same filename in the same batch, for no really good reason. Another method might be to batch 25 or 50 revs each time. - it turns out there's a problem spawning multiple p4 commands at the same time against the same p4d (p4d is 99.2, FWIW). Or at least running large `p4 files ...` while there's a large `p4 filelog` still also running. - filelog lines beginning with "... ..." are now ignored. These are notifications of copy, branch, and integrate events that we don't yet do anything with. - deleted cur() and P4_CUR - deleted P4_IS_INCREMENTAL - Made an assertion in VCP::Dest::revml::handle_rev() a little clearer - Added some ok(1) calls to 90p4.t to make it easier to figure out which child process is whining or aborting - Made the message that's printed when a subcommand emits unexpected output say "stderr" instead of "stdout". - Cleaned up documentation for VC::Plugin::work_path(). |
||
#2 | 468 | Barrie Slaymaker |
- VCP::Dest::p4 now does change number aggregation based on the comment field changing or whenever a new revision of a file with unsubmitted changes shows up on the input stream. Since revisions of files are normally sorted in time order, this should work in a number of cases. I'm sure we'll need to generalize it, perhaps with a time thresholding function. - t/90cvs.t now tests cvs->p4 replication. - VCP::Dest::p4 now doesn't try to `p4 submit` when no changes are pending. - VCP::Rev now prevents the same label from being applied twice to a revision. This was occuring because the "r_1"-style label that gets added to a target revision by VCP::Dest::p4 could duplicate a label "r_1" that happened to already be on a revision. - Added t/00rev.t, the beginnings of a test suite for VCP::Rev. - Tweaked bin/gentrevml to comment revisions with their change number instead of using a unique comment for every revision for non-p4 t/test-*-in-0.revml files. This was necessary to test cvs->p4 functionality. |
||
#1 | 467 | Barrie Slaymaker | Version 0.01, initial checkin in perforce public depot. |