#!/usr/local/bin/perl -w =head1 NAME p4.t - testing of vcp p4 i/o =cut use strict ; use Carp ; use File::Spec ; use IPC::Run qw( run ) ; use POSIX ':sys_wait_h' ; use Test ; use VCP::TestUtils ; sub __ok { goto \&ok; die unless @_ == 1 ? ok $_[0] : @_ == 2 ? ok $_[0], $_[1] : @_ == 3 ? ok $_[0], $_[1], $_[2] : die "too many args (".@_.") for __ok"; } my @vcp = vcp_cmd ; my $t = -d 't' ? 't/' : '' ; my $p4_options ; my $p4_spec_base ; my $p4_spec ; my $incr_change ; # what change number to start incremental export at my $cvs_options ; my $cvs_module ; my $cvs_borken = cvs_borken; sub clean_p4_branch_spec { ## mutates ( $in, $out ) in place $_[0] =~ s{(<p4_branch_spec.*?>)(.*)(</p4_branch_spec>)}{ ## $in my ( $stag, $etag ) = ( $1, $3 ); local $_ = $2; s{//ignored/}{//depot/foo/}g; "$stag$_$etag"; }sge; $_[1] =~ s{(<p4_branch_spec.*?>)(.*)(</p4_branch_spec>)}{ ## $out my ( $stag, $etag ) = ( $1, $3 ); local $_ = $2; s/^#.*\r?\n\r?\n?//mg; s/^Access:.*\r?\n\r?\n//mg; "$stag$_$etag"; }sge; } my @tests = ( sub { return skip $cvs_borken, "" if $cvs_borken ; # init_cvs before initting p4d, since it may need to set the uid and euid. $cvs_module = 'p4_t_module' ; $cvs_options = init_cvs "p4_", $cvs_module ; __ok 1 ; }, sub { $ENV{P4USER} = "foobar_user" ; $ENV{P4PORT} = "foobar_port" ; $ENV{P4CLIENT} = "foobar_client" ; $ENV{P4PASSWD} = "foobar_passwd" ; $p4_options = launch_p4d "p4_" ; $p4_spec_base = "p4:$p4_options->{user}:\@$p4_options->{port}:" ; $p4_spec = "$p4_spec_base//depot/foo/" ; __ok 1 ; }, ## ## Empty import ## sub { run [ @vcp, "revml:-", $p4_spec ], \"<revml/>" ; __ok $?, 0, "`vcp revml:- $p4_spec` return value" ; }, sub {}, ## Two __ok's in next test. sub { ## revml -> p4 -> revml, bootstrap export my $infile = $t . "test-p4-in-0.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. ## ## We are also testing to see if we can re-root the files under foo/... ## eval { run [ @vcp, "revml:$infile", $p4_spec ], \undef or die "`vcp revml:$infile $p4_spec` returned $?" ; __ok 1 ; my $in = slurp $infile ; my $out = get_vcp_output "$p4_spec..." ; s_content qw( rep_desc time user_id p4_info ), \$in, \$out ; s_content qw( rev_root ), \$in, "depot/foo" ; rm_elts qw( label ), qr/r_\w+|ch_\w+/, \$in, \$out ; $in =~ s{(id="|_id>)/+ignored}{$1//depot/foo}g; clean_p4_branch_spec $in, $out; assert_eq $infile, $in, $out ; } ; __ok $@ || '', '', "diff" ; }, sub { ## Test a single file extraction from a p4 repo. This file exists in ## change 1. __ok( get_vcp_output( "${p4_spec}add/f1" ), qr{<rev_root>depot/foo/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. __ok( get_vcp_output( "${p4_spec}add/f2" ), qr{<rev_root>depot/foo/add</.+<name>f2<.+<change_id>2<.+<change_id>3<.+</revml>}s ) ; }, ## ## p4->revml, re-rooting a dir tree ## sub { eval { ## Hide global $p4_spec for the nonce my $p4_spec = "$p4_spec_base//depot/foo/a/deeply/" ; my $infile = $t . "test-p4-in-0.revml" ; my $in = slurp $infile ; my $out = get_vcp_output "${p4_spec}..." ; s_content qw( rep_desc time user_id ), \$in, \$out ; s_content qw( rev_root ), \$in, "depot/foo/a/deeply" ; rm_elts qw( mod_time change_id p4_info ), \$in, \$out ; rm_elts qw( label ), qr/r_\w+|ch_\w+/, \$out ; ## Strip out all files from $in that shouldn't be there rm_elts qw( rev ), qr{(?:(?!a/deeply).)*?}s, \$in ; ## Adjust the $in paths to look like the result paths. $in is ## now the "expected" output. $in =~ s{<name>a/deeply/}{<name>}g ; $in =~ s{(id="|_id>)/+ignored}{$1//depot/foo}g; rm_elts qw( branches ), \$in; assert_eq $infile, $in, $out ; } ; __ok $@ || '', '', 'diff' ; }, ## ## p4->cvs->revml bootstrap ## sub { ## Two __ok's in next test. return skip $cvs_borken, "" if $cvs_borken ; }, sub { return skip $cvs_borken, "" if $cvs_borken ; $ENV{CVSROOT} = $cvs_options->{repo}; eval { run [ @vcp, "${p4_spec}...", "cvs:$cvs_module/" ], \undef or die "`vcp ${p4_spec}... cvs:$cvs_module/` returned $?" ; __ok 1 ; my $infile = $t . "test-p4-in-0.revml" ; my $in = slurp $infile ; my $out = get_vcp_output "cvs:$cvs_module/", qw( -r 1.1: ) ; s_content qw( rep_desc rep_type time user_id ), \$in, \$out ; s_content qw( rev_root ), \$in, $cvs_module ; rm_elts qw( p4_info change_id ), \$in ; rm_elts qw( label ), qr/r_\w+|ch_\w+/, \$in, \$out ; $out =~ s{<rev_id>1.}{<rev_id>}g ; $out =~ s{<base_rev_id>1.}{<base_rev_id>}g ; $out =~ s{((id="|_id>)?[^>]*#)1\.}{$1}g; $in =~ s{(id="|_id>)/+ignored}{$1/$cvs_module}g; assert_eq $infile, $in, $out ; } ; __ok $@ || '', '', 'diff' ; }, ## ## revml -> p4 -> revml, incremental export ## sub {}, ## Two __ok's in next test. sub { eval { my $p4_binary = $^O =~ /Win32/ ? "p4.exe" : "p4" ; run [ $p4_binary, "-u", $p4_options->{user}, "-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 $infile = $t . "test-p4-in-1.revml" ; run [ @vcp, "revml:$infile", "$p4_spec" ], \undef or die "`vcp revml:$infile $p4_spec` returned $?" ; __ok 1 ; my $in = slurp $infile ; my $out = get_vcp_output "${p4_spec}...\@$incr_change,#head" ; $in =~ s{</rev_root>}{/foo</rev_root>} ; s_content qw( rep_desc time user_id p4_info ), \$in, \$out ; s_content qw( rev_root ), \$in, "depot/foo" ; rm_elts qw( label ), qr/r_\w+|ch_\w+/, \$in, \$out ; rm_elts qw( branches ), \$in ; ## TODO: This is an incremental export and perforce does not give us ## a trivial way to figure out what branch a file is on (since ## multiple branch views can cover the same file), so we bail ## on that for now. rm_elts qw( branch_id ), \$in ; $in =~ s{(id="|_id>)/+ignored}{$1//depot/foo}g; assert_eq $infile, $in, $out ; } ; __ok $@ || '', '', 'diff' ; }, ## ## p4->cvs->revml incremental export ## sub { ## Two __ok's in next test. return skip $cvs_borken, "" if $cvs_borken ; }, sub { return skip $cvs_borken, "" if $cvs_borken ; $ENV{CVSROOT} = $cvs_options->{repo}; eval { run [ @vcp, "${p4_spec}...\@$incr_change,#head", "cvs:$cvs_module/" ], \undef or die "`vcp ${p4_spec}...\@$incr_change,#head cvs:$cvs_module/` returned $?" ; __ok 1 ; my $infile = $t . "test-p4-in-1.revml" ; my $in = slurp $infile ; my $out = get_vcp_output "cvs:$cvs_module/", "-r", "ch_$incr_change:" ; s_content qw( rep_desc rep_type time user_id ), \$in, \$out ; s_content qw( rev_root ), \$in, $cvs_module ; rm_elts qw( p4_info change_id ), \$in ; rm_elts qw( label ), qr/r_\w+|ch_\w+/, \$in, \$out ; $out =~ s{<rev_id>1.}{<rev_id>}g ; $out =~ s{<base_rev_id>1.}{<base_rev_id>}g ; $out =~ s{((id="|_id>)?[^>]*#)1\.}{$1}g; $in =~ s{(id="|_id>)/+ignored}{$1/$cvs_module}g; rm_elts qw( branches ), \$in ; ## TODO: This is an incremental export and perforce does not give us ## a trivial way to figure out what branch a file is on (since ## multiple branch views can cover the same file), so we bail ## on that for now. rm_elts qw( branch_id ), \$in ; assert_eq $infile, $in, $out ; } ; __ok $@ || '', '', 'diff' ; }, ## ## p4 -> revml, incremental export in bootstrap mode ## sub { eval { my $infile = $t . "test-p4-in-1-bootstrap.revml" ; my $in = slurp $infile ; my $out = get_vcp_output "${p4_spec}...\@$incr_change,#head", "--bootstrap=**" ; $in =~ s{</rev_root>}{/foo</rev_root>} ; s_content qw( rep_desc time user_id p4_info ), \$in, \$out ; s_content qw( rev_root ), \$in, "depot/foo" ; rm_elts qw( label ), qr/r_\w+|ch_\w+/, \$in, \$out ; $in =~ s{(id="|_id>)/+ignored}{$1//depot/foo}g; rm_elts qw( branches ), \$in ; ## TODO: This is an incremental export and perforce does not give us ## a trivial way to figure out what branch a file is on (since ## multiple branch views can cover the same file), so we bail ## on that for now. rm_elts qw( branch_id ), \$in ; assert_eq $infile, $in, $out ; } ; __ok $@ || '', '', 'diff' ; }, ) ; plan tests => scalar @tests ; my $p4d_borken = p4d_borken ; my $why_skip ; $why_skip .= "p4 command not found\n" unless ( `p4 -V` || 0 ) =~ /^Perforce/ ; $why_skip .= "$p4d_borken\n" if $p4d_borken ; $why_skip ? skip( $why_skip, '' ) : $_->() for @tests ;
# | 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. |