Changes

From SME Server
Jump to navigationJump to search
118 bytes removed ,  13:12, 3 January 2014
no edit summary
Line 1: Line 1: −
NAME
+
== NAME ==
      esmith::TestUtils -- general utilities for writing esmith tests<br />
+
esmith::TestUtils -- general utilities for writing esmith tests<br />
    
In a root terminal you can do the command below if you want to display the up-to-date content  
 
In a root terminal you can do the command below if you want to display the up-to-date content  
 
  perldoc esmith::TestUtils
 
  perldoc esmith::TestUtils
SYNOPSIS
+
== SYNOPSIS ==
 
         my $username = get_random_username();
 
         my $username = get_random_username();
 
         my $newuser  = new_random_username();
 
         my $newuser  = new_random_username();
 
+
 
         my $exit = simulate_perl_program($program);
 
         my $exit = simulate_perl_program($program);
 
+
 
         if (destruction_ok()) { ... }
 
         if (destruction_ok()) { ... }
 
+
 
         my $scratch_file = scratch_copy($file);
 
         my $scratch_file = scratch_copy($file);
   −
DESCRIPTION
+
== DESCRIPTION ==
      This module provides a bunch of useful little utility routines to facilitate writing tests on the SMEServer.
+
This module provides a bunch of useful little utility routines to facilitate writing tests on the SMEServer.
   −
      destruction_ok()
+
=== destruction_ok() ===
 
+
Returns true or false depending on whether or not it’s OK for tests to be destructive on this server.
      Returns true or false depending on whether or not it’s OK for tests to be destructive on this server.
+
=== get_random_username() ===
 
  −
      get_random_username()
      
           my $username = get_random_username;
 
           my $username = get_random_username;
   −
      Gets a random username from the accounts database.
+
Gets a random username from the accounts database.
   −
      new_random_username()
+
=== new_random_username() ===
    
           my $username = new_random_username;
 
           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.
+
Returns a random username (just a random string of at least 3 letters) which is not yet in the accounts database.
 
+
=== simulate_perl_program ===
      simulate_perl_program
      
           my $exit = simulate_perl_program($program_file, @args);
 
           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.
+
"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.
+
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:
      You’d do this in order to override certain functions it may call for testing purposes.  For example:
+
==== begin testing ====
 
  −
          =begin testing
   
           use esmith::Broker ();
 
           use esmith::Broker ();
   −
          # override esmith::Broker::saveConfig so it does not
+
override esmith::Broker::saveConfig so it does not actually save the config.  Instead, we trap the arguments for examination.
          # actually save the config.  Instead, we trap the arguments
  −
          # for examination.
   
           my @sSC_args;
 
           my @sSC_args;
 
           sub esmith::Broker::saveServerConfig {
 
           sub esmith::Broker::saveServerConfig {
Line 54: Line 47:  
               return 1;
 
               return 1;
 
           }
 
           }
 
+
 
           my $exit = simulate_perl_program($Original_File, qw(wibble));
 
           my $exit = simulate_perl_program($Original_File, qw(wibble));
 
+
 
           is( $exit, 0, ’exited normally’ );
 
           is( $exit, 0, ’exited normally’ );
 
           is( $_STDOUT_, "wibble was frobnized\n" );
 
           is( $_STDOUT_, "wibble was frobnized\n" );
Line 63: Line 56:  
                                   ’saveServerConfig called correctly’ );
 
                                   ’saveServerConfig called correctly’ );
   −
          =end testing
+
==== end testing ====
   −
      Restrictions
+
=== Restrictions ===
    
         $program_file must be a Perl program.
 
         $program_file must be a Perl program.
   −
        any args on the #! line may not be honored.
+
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.
+
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.
      scratch_copy
+
=== scratch_copy ===
    
         my $scratch = scratch_copy($src);
 
         my $scratch = scratch_copy($src);
 
         my $scratch = scratch_copy($src, $dest);
 
         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.
+
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.
+
If the copy fails, $scratch will be undefined.
 +
When the program exits the $scratch file will be deleted.
   −
AUTHOR
+
== AUTHOR ==
 
       Mitel Networks Corporation
 
       Mitel Networks Corporation
  

Navigation menu