Martyn J. Pearce > Log-Info > xt/fork_log.t

Download:
Log-Info-2.00.tar.gz

Annotate this POD

CPAN RT

New  2
Open  0
View/Report Bugs
Source  

Unit Test Package for Log::Info functions ^

This package tests the fork_log subr.

Test 1: compilation

This test confirms that the test script and the modules it calls compiled successfully.

Test 2: adding a sink

This test deletes the SINK_STDERR sink, and adds a sink (SINK1), to CHAN_INFO. The test is that no exception is thrown.

Tests 3--5: invoke fork_log (simple perl stdout)

Invoke fork_log, where the fork simply prints MESSAGE1 to stdout.

(1) Test no exception thrown. (2) Test exactly one message logged to CHAN_INFO (3) Test MESSAGE1 is message logged to CHAN_INFO

MESSAGE1 is deliberately not newline terminated, to check handling of incomplete lines.

Tests 6--8: invoke fork_log (simple perl stderr)

Invoke fork_log, where the fork simply prints MESSAGE2 to stdout.

(1) Test no exception thrown. (2) Test exactly one message logged to CHAN_INFO (3) Test MESSAGE2 is message logged to CHAN_INFO

MESSAGE2 is deliberately newline terminated, to check handling of complete lines.

Tests 9--11: invoke fork_log (simple perl out/err)

Invoke fork_log, where the fork prints MESSAGE1 (newline-terminated) to stdout, and MESSAGE2 (not newline-terminated) to stderr.

(1) Test no exception thrown. (2) Test exactly two messages logged to CHAN_INFO (3) Test MESSAGE1, MESSAGE2 are messages logged to CHAN_INFO (in either order).

Tests 12--16: invoke fork_log (simple perl ordered)

Invoke fork_log, where the fork prints MESSAGES 3, 4, and 5 to stdout, each newline-terminated, with no delay between 3 & 4, and 2 seconds between 4 & 5.

(1) Test no exception thrown. (2) Test exactly three messages logged to CHAN_INFO (3) Test MESSAGE3 is the first message logged (4) Test MESSAGE4 is the second message logged (5) Test MESSAGE5 is the third message logged

Tests 17--21: invoke fork_log (start/end logged)

Invoke fork_log, where the fork prints MESSAGE 3 to stderr (without a newline). fork_log is requested to print start/end messages.

(1) Test no exception thrown. (2) Test exactly three messages logged to CHAN_INFO (3) Test the start message is the first message logged (4) Test MESSAGE3 is the second message logged (5) Test the end message is the third message logged

Tests 22--25: fork_log, capturing a specified filehandle

Invoke fork log, specifying a code snippet that prints MESSAGE4 (no newline) to a temporary file handle.

(1) Test no exception thrown. (2) Test that exactly one message has been captured. (3) Test that the captured message is MESSAGE4. (4) Test that nothing was written to the temp file.

Tests 26--28: fork_log, capturing a specified filedescriptor

Invoke fork log, specifying a code snippet that prints MESSAGE5 (with newline) to a numbered file descriptor (to a temporary file). The file descriptor is explicitly closed by the code snippet.

(1) Test no exception thrown. (2) Test that exactly one message has been captured. (3) Test that the captured message is MESSAGE5. (4) Test that nothing was written to the temp file.

Tests 30--37: complex use of specified descriptors

Set up CHAN1, CHAN2 to log to arrays.

Invoke fork log, specifying a code snippet that prints MESSAGES1,2 (with newline) to a temporary filehandle, printing MESSAGE3 (no newline) to a numbered secondary temprorary filehandle, passed by file descriptor, in between the two. The file descriptor is not explicitly closed by the code snippet.

The temporary filename is requested to be directed to CHAN1, the file descriptor to CHAN2.

(1) Test no exception thrown by channel setup. (2) Test no exception thrown by fork_log. (3) Test that exactly two messages have been captured to CHAN1. (4) Test that the first captured message to CHAN1 is MESSAGE1. (5) Test that the second captured message to CHAN1 is MESSAGE2. (6) Test that exactly one message has been captured to CHAN2. (7) Test that the captured message to CHAN2 is MESSAGE3. (8) Test that nothing was written to the temp file.

Tests 38--43: Formatting Code

Invoke fork_log, with a code snippet that prints MESSAGE2 to stdout, and then MESSAGE1 to stderr, with a formatter that precedes the message with [source], and reverses the message.

(1) Test no exception thrown. (2) Test exactly four messages are logged to CHAN_INFO (3) Test first message is [SRC_INFO] reverse "Starting process: test1" (4) Test second/third message is [stdout] reverse MESSAGE2 (5) Test third/second message is [stderr] reverse MESSAGE1 (6) Test fourth message is [SRC_INFO] reverse "Finishing process: test1"

Note that the order is not defined for the messages printed (since they are printed to different filehandles).

Tests 44--47: Arrayref exec test

Invoke fork_log, passing in an arrayref that is [ cat data/testfile1 ].

(1) Test that no exception is thrown. (2) Check that there is one message for each line in the file (3) Check that each message corresponds to a line in the file (4) Check that no extraneous lines were found in the messages

Tests 48--51: Log to Alternative Channels/Levels

Initialize CHAN3 to log to arrayref. Set channel level on 3 to be LOG_WARNING.

Invoke fork_log, where the fork simply prints MESSAGE3 to stdout (with newline), and MESSAGE1 to stderr (without newline). Request stdout to go to CHAN3 (level LOG_INFO), and stderr to go to CHAN3 (level LOG_WARNING).

(1) Test no exception thrown by channel setup. (2) Test no exception thrown by fork_log. (3) Test exactly one message logged to CHAN3 (4) Test MESSAGE1 is message logged to CHAN3

Tests 52--56: Log Process Arguments (arrayref)

Invoke fork_log, using the arrayref proc to cat data/testfile1, with argument logging turned on.

(1) Test no exception thrown by fork_log. (2) Check for the presence of an appropriate Process Args message (as the first message). (3) Check that there is one message for each line in the file (4) Check that each message corresponds to a line in the file (5) Check that no extraneous lines were found in the messages

Tests 57--60: Log Process Arguments (coderef)

Invoke fork_log, using the coderef proc to print MESSAGE1 (no newline), with argument logging turned on.

(1) Test no exception thrown by fork_log. (2) Check that there are exactly two messages. (3) Check for the presence of an appropriate Process Args message (as the first message). (4) Check that the second message is MESSAGE1.

Tests 61--64: Log Process Results One

Invoke fork_log, forking the code

  print MESSAGE5;
  exit 10;

with results printing turned on.

(1) Test no exception thrown by fork_log. (2) Test that there are exactly two messages (3) Check that the first message is MESSAGE5 (4) Check that the second message is an appropriate exit message

Tests 65--68: Log Process Results Two

Invoke fork_log, forking the arrayref [ 'echo', MESSAGE3 ], with results printing turned on.

(1) Test no exception thrown by fork_log. (2) Test that there are exactly two messages (3) Check that the first message is MESSAGE3 (4) Check that the second message is an appropriate exit message

Tests 61--64: Return Process Results One

Invoke fork_log, forking the code

  exit 10;

(1) Test no exception thrown by fork_log. (2) Test that there are no messages (3) Check that the return code is 10 << 8.

syntax highlighting: