---
name: "VCP::TestUtils"
section: "3pm"
platform: "linux"
package: "libvcp-perl"
version: "0.9-20050110-1"
release: "Debian 4.0 (Etch)"
platforms: ["linux"]
url: "https://new.carta.tech/VCP::TestUtils"
---

# VCP::TestUtils(3pm)

support routines for VCP testing

## NAME

VCP::TestUtils - support routines for VCP testing

## General utility functions

- copy\_dir\_tree

  ```
     copy_dir_tree $src, $dest;
  ```

  Copy source directory tree to a destination directory.  Accepts absolute or relative directory names, but doesn't do tilde expansion.

- rm\_dir\_tree

  ```
      rm_dir_tree $path;
  ```

  Remove a directory tree.  Does not complain if it's not there to remove.

- assert\_eq

  DEPRECATED.  Use *ok\_or\_diff()* instead.

  ```
     assert_eq $test_name, $expected, $got;
  ```

- ok\_or\_diff

  ```
     ok_or_diff $got, $expected, ...;
  ```

  Use instead of ok to compare two strings and output a diff if they are indeed different.  Uses Test::Difference's *eq\_or\_diff()* if present, otherwise falls back to *Text::Diff::diff()*. Calls *Test::ok()*.

  If `$got` is empty and `$expected` is longer than 2 lines, *diff()* is not called and a special message is generated.  This is to prevent SPAMming out huge diffs when no output is received but `$expected` is big.

- slurp

  ```
     $guts = slurp $filename ;
     @lines = slurp $filename;
  ```

  ```
     read entire contents of file and return as a scalar, or array in
     array context (splitting on newlines.)
  ```

- perl\_cmd

  ```
     @perl = perl_cmd
  ```

  Returns a list containing the Perl executable and some options to reproduce the current Perl options , like -I.

- find\_command

  ```
     @vcp = find_command "vcp"
  ```

  Find a script within the main distro directory or one subdir under it. Looks for "bin/\<cmd\>" and "../bin/\<cmd\>".  This should be adequate for almost all uses.

- vcp\_cmd

  ```
     @vcp = vcp_cmd
  ```

  Returns a list containing the Perl executable and some options to reproduce the current Perl options , like -I.

  vcp\_cmd assumes it is called from within the main distro directory or one subdir under it, since it looks for "bin/vcp" and "../bin/vcp".  This should be adequate for almost all uses.

  vcp\_cmd caches it's results to allow it to be run from other directories after the first time it's called. (this is not a significant performance improvement; running the vcp process takes several orders of magnitude longer than the quick checks vcp\_cmd does).

  If `$ENV`{VCPTESTCOMMAND} is set, it is treated as a path to the executable to run plus parameters.  If the path includes spaces, it must be enclosed in quotation marks.  If the path is relative, it is assumed to be relative to the current working directory.

- compile\_dtd\_cmd

  ```
     @compile_dtd = compile_dtd_cmd
  ```

  Returns a list containing the Perl executable and some options to reproduce the current Perl options , like -I.

  compile\_dtd\_cmd assumes it is called from within the main distro directory or one subdir under it, since it looks for "bin/compile\_dtd" and "../bin/compile\_dtd".  This should be adequate for almost all uses.

  compile\_dtd\_cmd caches it's results to allow it to be run from other directories after the first time it's called.

- run

  Run a command using *IPC::Run3::run3()*, but with logging and a verbose exception on non-0 result code.

  Arguments are the same as and are passed to *IPC::Run3::run3()*.

- run\_p4

  calls 'run' to run p4 binary after deciding which platform specific program to run.

  determines p4 executable name based on operating system.

  builds p4 options string from `$p4_options` hash

  examples:

  ```
      run_p4 \@args, \$stdin, \$stdout, \$stderr, $p4_options;
      run_p4 [ qw(files) ], \undef, \$stdout, $p4_options;
  ```

  arguments:

  - 1\.

    array of words to add to end of p4 command

  - 2\...

    remaining arguments passed on to 'run' sub (except final arg)

  - final arg:

    p4\_options hash (may contain: port, user, client, password ... ?)

- parse\_files\_and\_revids\_from\_head\_revs\_db \<options-hash\>

  options:\
       state\_dir\
       repo\_id\
       remove\_rev\_root (string to be removed from front of filename)

  given a vcp state directory and repo\_id, dump the head revs to a string, and parse out the \<name\> and \<rev\_id\> elements within each \<rev\>, then return a string (sorted by line) of the form:

  ```
      <name1> <max_revision_num1>
      <name2> <max_revision_num2>
      <name3> <max_revision_num3>
      .
      .
      .
  ```

  examples:

  ```
     my $revs = parse_files_and_revids_from_head_revs_db
        { state_dir => $state_dir, repo_id => $repo_id }
     my $revs = parse_files_and_revids_from_head_revs_db $state_dir $repo_id
        { state_dir => $state_dir, repo_id => $repo_id, remove_rev_root => "/ignore/" }
  ```

- parse\_files\_and\_revids\_from\_revml

  given one or more revml filenames, slurp them up, parse out the \<name\> and \<rev\_id\> elements within each \<rev\>, then return a string (sorted by line) of the form:

  ```
      <name1> <max_revision_num1>
      <name2> <max_revision_num2>
      <name3> <max_revision_num3>
      .
      .
      .
  ```

  The final (optional) argument may be a reference to a hash of parameters.  Currently the only parameter is IGNORE\_REVS\_WITH\_DELETE\_FLAG, which if true, causes any revs containing the \<delete /\> or \<delete/\> tags to be ignored.

  examples:

  ```
     my $revs = parse_files_and_revids_from_revml $infile ;
     my $revs = parse_files_and_revids_from_revml $infile1, $infile2 ;
  ```

- parse\_files\_and\_revids\_from\_p4\_files

  Run p4 files command line to get list of changed files.  Parse the output so it can be diffed with the output of parse\_files\_and\_revids\_from\_revml.

  returns a string containing names and revision numbers, 1 per line. See that sub above for a description of the output format.

  arguments are:

  - 1\.

    revision root, e.g. "//depot/something/".  This string will be removed from the output so it may be diffed with parse\_files\_and\_revids\_from\_revml output.

  - 2\.

    options hash for *run\_p4()*

  - 3\...

    1 or more file\[revRange\] spec for p4 files command (run 'p4 help files' and 'p4 help revisions' command line for formatting help)

  example usage:

  ```
      parse_files_and_revids_from_p4_files $p4_rev_root, $p4_options, "//..."
  ```

- parse\_files\_and\_revids\_from\_cvs\_history

  Run cvs history command line to get list of changed files.  Parse the output so it can be diffed with the output of parse\_files\_and\_revids\_from\_revml.

  returns a string containing names and revision numbers, 1 per line. See that sub above for a description of the output format.

  arguments are:

  - 1\.

    cvs root directory.

  - 2\.

    cvs module name.  This string will be removed from the output so it may be diffed with parse\_files\_and\_revids\_from\_revml output.

  example usage:

  ```
      parse_files_and_revids_from_cvs_history "/home/blah/blah/cvsroot_0/", "module-blah"
  ```

- get\_vcp\_output

  ```
     @vcp = get_vcp_output "foo:", "-bar" ;
  ```

  Does a:

  ```
     run [ vcp_cmd, @_, "sort:", "--", "revml:", ... ], \undef, \$out
        or croak "`vcp blahdy blah` returned $?";
  ```

  and returns `$out`.  The "..." refers to whatever output options are needed to make the test output agree with `"bin/gentrevml"`'s test files (t/test-\*.revml).

  You may pass in options as a hash reference as the final argument. The supported option is:

  ```
    revml_out_spec
  ```

  which, if present, is tacked on to the revml: output spec's list of options,

## XML "cleanup" functions

These are used to get rid of content or elements that are known to differ when comparing the revml fed in to a repository with the revml that comes out.

- s\_content

  ```
     s_content
        $elt_type1, $elt_type2, ..., \$string1, \$string2, ..., $new_content ;
  ```

  Changes the contents of the elements, since some things, like suer id or mod\_time can't be the same after going through a repository.

  If `$new_val` is not supplied, a constant string is used.

- rm\_elts

  ```
     rm_elts $elt_type1, $elt_type2, ..., \$string1, \$string2
     rm_elts $elt_type1, $elt_type2, ..., qr/$content_re/, \$string1, \$string2
  ```

  Removes the specified elements from the strings, including leading whitespace and trailing line separators.  If the optional `$content_re` regular expression is provided, then only elements containing that pattern will be removed.

## p4 repository mgmt functions

- p4\_borken

  Returns true if the p4 is missing or too old (\< 99.2).

- tmpdir

  ```
      my $d = tmpdir            ## create a directory like /tmp/vcp_95cvs2p4_#####
      my $d = tmpdir( "foo" );  ## create a directory like /tmp/vcp_95cvs2p4_foo_#####
  ```

  Return a temporary directory that will be deleted in an END block.

  The prefix is advisory only and is meant to allow developers to intuit the purpose of a temporary directory from its name.

  See File::Spec::Unix's *tmpdir()* function for details, but you can set the TMPDIR environment variable to control where the VCP test suite places temp dirs (and, after testing, where vcp places test dirs, but vcp has separate temp directory management functions).

## CVS mgmt functions

- cvs\_borken

  Returns true if cvs -v works and outputs "Concurrent Versions System".

- init\_cvsroot

  ```
     my $cvs_options = init_cvsroot $prefix, $module_name ;
     my $cvs_options = init_cvsroot $prefix, $module_name, $rootdir ;
  ```

  Creates a CVS repository containing an empty module. Also sets `$ENV`{LOGNAME} if it notices that we're running as root, so CVS won't give a "cannot commit files as 'root'" error. Tries "nobody", then "guest".

  Returns the options needed to access the cvs repository.

## VSS mgmt functions

- vss\_borken

  Returns true if MKSS may be run.

## COPYRIGHT

Copyright 2000, Perforce Software, Inc.  All Rights Reserved.

This module and the VCP package are licensed according to the terms given in the file LICENSE accompanying this distribution, a copy of which is included in vcp.
