I am writing a simple test automation suite that will tell me the number of test cases passed and failed. Below is a simple example that will describe the code:
#! /usr/bin/perl -w
use Test::Simple tests => 1;
print "Enter the name of the Book: ";
$name = <STDIN>;
chomp($name);
print "You have entered $name \n";
$ori_name = "TextBook";
chomp($ori_name);
ok($name eq $ori_name, 'Checking name');
The output I am getting after entering 'TextBox' as input is as follows:
1..1
Enter the name of the Book: TextBook
You have entered TextBook
ok 1 - Checking name
I would like to redirect the same output to a file which should look like
ok 1 - Checking name
If I add the following subroutine
log_message (ok ($name eq $ori_name, 'Checking name');
sub log_message
{
my $message = @_;
open(DA, '>>PJ.txt') or die "Couldn't open file PJ.txt";
print DA $message;
close (DA);
}
Then I get either '1
' or '0
' - not the text I would like.
How should I proceed so that the result of my code redirects to a file which should have the following format:
ok 1 - Checking name
ok 2 - Checking others
and so on?