From SME Server


esmith::TestUtils -- general utilities for writing esmith tests

In a root terminal you can do the command below if you want to display the up-to-date content

perldoc esmith::TestUtils


        my $username = get_random_username();
        my $newuser  = new_random_username();

        my $exit = simulate_perl_program($program);

        if (destruction_ok()) { ... }

        my $scratch_file = scratch_copy($file);


This module provides a bunch of useful little utility routines to facilitate writing tests on the SMEServer.


Returns true or false depending on whether or not it’s OK for tests to be destructive on this server.


          my $username = get_random_username;

Gets a random username from the accounts database.


          my $username = new_random_username;

Returns a random username (just a random string of at least 3 letters) which is not yet in the accounts database.


          my $exit = simulate_perl_program($program_file, @args);

"runs" the given $program_file for testing and reports it’s $exit code. @args will be expanded via glob() and passed into the program.

The $program_file is not actually run in a seperate process. Instead, it is run in the current processs, simulating calling the program. You’d do this in order to override certain functions it may call for testing purposes. For example:

begin testing

          use esmith::Broker ();

override esmith::Broker::saveConfig so it does not actually save the config. Instead, we trap the arguments for examination.

          my @sSC_args;
          sub esmith::Broker::saveServerConfig {
              @sSC_args = @_;
              return 1;

          my $exit = simulate_perl_program($Original_File, qw(wibble));

          is( $exit, 0, ’exited normally’ );
          is( $_STDOUT_, "wibble was frobnized\n" );
          is( $_STDERR_, ’’, ’no warnings’ );
          is_deeply( \@sSC_args, [(’Broker’, 1234, { foo => 23 })],
                                  ’saveServerConfig called correctly’ );

end testing


        $program_file must be a Perl program.

any args on the #! line may not be honored.

it cannot assume it’s in package main. If the program dies the error will be on $@. The output of the program will be available on $_STDOUT_ and $_STDERR_ as provided by Test::Inline.


        my $scratch = scratch_copy($src);
        my $scratch = scratch_copy($src, $dest);

Creates a scratch copy of the $src file that you can safely scribbled around with for testing. Returns the location of the $scratch file. If $dest is given it will use that for $scratch.

If the copy fails, $scratch will be undefined. When the program exits the $scratch file will be deleted.


Mitel Networks Corporation See for more information.