added automated code testing framework

This commit is contained in:
JT Smith 2005-11-07 01:54:35 +00:00
parent ea868a8c0e
commit e017005b17
6 changed files with 437 additions and 0 deletions

View file

@ -9,6 +9,7 @@
as much as 100%. See gotcha.txt for details.
- Changed macro API which cuts macro memory consumption in half. See
migration.txt for details.
- Added automated code testing framework.
6.7.7

62
sbin/testCodebase.pl Normal file
View file

@ -0,0 +1,62 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2005 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
$|=1;
use strict;
use lib '../..';
use Getopt::Long;
my $configFile;
my $help;
GetOptions(
'configFile=s'=>\$configFile,
'help'=>\$help
);
if ($help || !$configFile) {
print <<STOP;
perl $0 --configFile
--configFile The config file of the WebGUI site you'll use
to test the codebase. Note that you should not
use a production config file as some tests may
be destructive.
STOP
exit;
}
opendir(DIR,"../t");
my @files = readdir(DIR);
closedir(DIR);
chdir("../t");
my $someTestFailed = 0;
foreach my $file (@files) {
next unless $file =~ m/^(.*?)\.t$/;
my $testType = $1;
$testType =~ s/_/ /g;
print "Running $testType tests...\n";
unless (system("$^X $file --configFile=$configFile")) {
print "All $testType tests were successful.\n";
} else {
$someTestFailed = 1;
print "----------------------------\n";
print "Some $testType tests failed!\n";
print "----------------------------\n";
sleep(2);
}
print "\n";
}
exit $someTestFailed;

56
t/Id.t Normal file
View file

@ -0,0 +1,56 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2005 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
# ---- BEGIN DO NOT EDIT ----
use strict;
use lib '../lib';
use Getopt::Long;
use WebGUI::Session;
# ---- END DO NOT EDIT ----
use Test::More tests => 2; # increment this value for each test you create
use WebGUI::Id;
use WebGUI::Utility;
initialize(); # this line is required
# generate
my $generateId = WebGUI::Id::generate();
is(length($generateId), 22, "generate() - length of 22 characters");
my @uniqueIds;
my $isUnique = 1;
for (1..2000) {
last unless $isUnique;
my $id = WebGUI::Id::generate();
$isUnique = !isIn($id,@uniqueIds);
push(@uniqueIds,$id);
}
ok($isUnique, "generate() - unique");
cleanup(); # this line is required
# ---- DO NOT EDIT BELOW THIS LINE -----
sub initialize {
$|=1; # disable output buffering
my $configFile;
GetOptions(
'configFile=s'=>\$configFile
);
exit 1 unless ($configFile);
WebGUI::Session::open("..",$configFile);
}
sub cleanup {
WebGUI::Session::close();
}

166
t/SQL.t Normal file
View file

@ -0,0 +1,166 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2005 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
# ---- BEGIN DO NOT EDIT ----
use strict;
use lib '../lib';
use Getopt::Long;
use WebGUI::Session;
# ---- END DO NOT EDIT ----
use Test::More tests => 31; # increment this value for each test you create
use WebGUI::SQL;
initialize(); # this line is required
# read
ok(my $sth = WebGUI::SQL->read("select * from settings"), "read()");
# array
my @row = $sth->array;
is(@row, 2, "array()");
# getColumnNames
my @columnNames = $sth->getColumnNames;
ok($columnNames[0] eq "name" && $columnNames[1] eq "value", "geColumnNames()");
# hash
is(scalar($sth->hash), "2/8", "hash()");
# hashRef
is(scalar(%{$sth->hashRef}), "2/8", "hashRef()");
# rows
ok($sth->rows > 1, "rows()");
# finish
ok($sth->finish, "finish()");
# unconditionalRead
ok(my $sth = WebGUI::SQL->unconditionalRead("select * from tableThatDoesntExist"), "unconditionalRead()");
# errorCode
is($sth->errorCode, "1146" ,"errorCode()");
# errorMessage
ok($sth->errorMessage =~ m/Table .*\.tablethatdoesntexist. doesn.t exist/ , "errorMessage()");
$sth->finish;
# quote
is(quote("that's great"), "'that\\\'s great'", "quote()");
# quoteAndJoin
my @quoteAndJoin = ("that's great", '"Howdy partner!"');
is(quoteAndJoin(\@quoteAndJoin), "'that\\\'s great','\\\"Howdy partner!\\\"'", "quoteAndJoin()");
# beginTransaction
SKIP: {
skip("Don't know how to test beginTransaction.",1);
ok(undef,"beginTransaction()");
}
# commit
SKIP: {
skip("Don't know how to test commit",1);
ok(undef, "commit()");
}
# rollback
SKIP: {
skip("Don't know how to test rollback()",1);
ok(undef, "rollback()");
}
# prepare
ok(my $sth = WebGUI::SQL->prepare("select value from settings where name=?"), "prepare()");
# execute
$sth->execute(['showDebug']);
is($sth->errorCode, undef, "execute()");
$sth->finish;
# quickArray
my ($value) = WebGUI::SQL->quickArray("select value from settings where name='authMethod'");
ok($value, "quickArray()");
# write
WebGUI::SQL->write("delete from incrementer where incrementerId='theBigTest'"); # clean up previous failures
WebGUI::SQL->write("insert into incrementer (incrementerId, nextValue) values ('theBigTest',25)");
my ($value) = WebGUI::SQL->quickArray("select nextValue from incrementer where incrementerId='theBigTest'");
is($value, 25, 'write()');
# quickCSV
is(WebGUI::SQL->quickCSV("select * from incrementer where incrementerId='theBigTest'"), "incrementerId,nextValue\ntheBigTest,25\n", "quickCSV()");
# quickHash
my %quickHash = WebGUI::SQL->quickHash("select * from incrementer where incrementerId='theBigTest'");
is($quickHash{nextValue}, 25, "quickHash()");
# quickHash
my $quickHashRef = WebGUI::SQL->quickHashRef("select * from incrementer where incrementerId='theBigTest'");
is($quickHashRef->{nextValue}, 25, "quickHashRef()");
# quickTab
is(WebGUI::SQL->quickTab("select * from incrementer where incrementerId='theBigTest'"), "incrementerId\tnextValue\ntheBigTest\t25\n", "quickCSV()");
# buildArray
my ($buildArray) = WebGUI::SQL->buildArray("select nextValue from incrementer where incrementerId='theBigTest'");
is($buildArray, 25, "buildArray()");
# buildArrayRef
my $buildArrayRef = WebGUI::SQL->buildArrayRef("select nextValue from incrementer where incrementerId='theBigTest'");
is($buildArrayRef->[0], 25, "buildArrayRef()");
# buildHash
my %buildHash = WebGUI::SQL->buildHash("select incrementerId,nextValue from incrementer where incrementerId='theBigTest'");
is($buildHash{theBigTest}, 25, "buildHash()");
# buildHashRef
my $buildHashRef = WebGUI::SQL->buildHashRef("select incrementerId,nextValue from incrementer where incrementerId='theBigTest'");
is($buildHashRef->{theBigTest}, 25, "buildHashRef()");
# getNextId
is(getNextId('theBigTest'), 25, "getNextId()");
WebGUI::SQL->write("delete from incrementer where incrementerId='theBigTest'");
# setRow
my $setRowId = WebGUI::SQL->setRow("incrementer","incrementerId",{incrementerId=>"new", nextValue=>47});
ok($setRowId ne "", "setRow() - return ID");
my ($setRowResult) = WebGUI::SQL->quickArray("select nextValue from incrementer where incrementerId=".quote($setRowId));
is($setRowResult, 47, "setRow() - set data");
# getRow
my $getRow = WebGUI::SQL->getRow("incrementer","incrementerId",$setRowId);
is($getRow->{nextValue}, 47, "getRow()");
WebGUI::SQL->write("delete from incrementer where incrementerId=".quote($setRowId));
cleanup(); # this line is required
# ---- DO NOT EDIT BELOW THIS LINE -----
sub initialize {
$|=1; # disable output buffering
my $configFile;
GetOptions(
'configFile=s'=>\$configFile
);
exit 1 unless ($configFile);
WebGUI::Session::open("..",$configFile);
}
sub cleanup {
WebGUI::Session::close();
}

109
t/Utility.t Normal file
View file

@ -0,0 +1,109 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2005 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
# ---- BEGIN DO NOT EDIT ----
use strict;
use lib '../lib';
use Getopt::Long;
use WebGUI::Session;
# ---- END DO NOT EDIT ----
use Test::More tests => 20; # increment this value for each test you create
initialize(); # this line is required
# commify
is(WebGUI::Utility::commify(10), "10", 'commify() - no comma needed');
is(WebGUI::Utility::commify(1000), "1,000", 'commify() - single comma');
is(WebGUI::Utility::commify(10000000), "10,000,000", 'commify() - multiple commas');
# formatBytes
is(WebGUI::Utility::formatBytes(10), '10 B', 'formatBytes() - bytes');
is(WebGUI::Utility::formatBytes(4300), '4 kB', 'formatBytes() - kilobytes');
is(WebGUI::Utility::formatBytes(1700000), '2 MB', 'formatBytes() - megabytes');
# isBetween
ok(WebGUI::Utility::isBetween(0,-1,1), 'isBetween() - negative and positive range');
ok(WebGUI::Utility::isBetween(11,1,15), 'isBetween() - positive range');
ok(WebGUI::Utility::isBetween(-5,-10,-2), 'isBetween() - negative range');
# isIn
ok(WebGUI::Utility::isIn("webgui", qw(cars trucks webgui trains)), 'isIn()');
# makeArrayCommaSafe
my @commaFilledArray = ("this,that", "foo,bar", "x-y");
WebGUI::Utility::makeArrayCommaSafe(\@commaFilledArray);
my $noCommaFound = 1;
foreach my $row (@commaFilledArray) {
$noCommaFound = 0 if ($row =~ m/,/);
}
ok($noCommaFound, 'makeArrayCommaSafe()');
# makeCommaSafe
ok(!(WebGUI::Utility::makeCommaSafe("this,that,foo,,bar") =~ m/,/), 'makeCommaSafe()');
# makeTabSafe
ok(!(WebGUI::Utility::makeTabSafe("this\tthat\tfoo\tbar\t") =~ m/\t/), 'makeTabSafe()');
# randint
my $number = WebGUI::Utility::randint(50,75);
ok($number >= 50 && $number <= 75, 'randint()');
# randomizeArray
SKIP: {
skip("Don't know how to test randomizeArray.",1);
ok(undef, 'randomizeArray()');
}
# randomizeHash
SKIP: {
skip("Don't know how to test randomizeHash.",1);
ok(undef, 'randomizeHash()');
}
# round
is(WebGUI::Utility::round(47.133984233, 0), 47, 'round() - 0 significant digits');
is(WebGUI::Utility::round(47.133984233, 3), 47.134, 'round() - multiple significant digits');
# sortHash
SKIP: {
skip("Don't know how to test sortHash.",1);
ok(undef, 'sortHash()');
}
# sortHashDescending
SKIP: {
skip("Don't know how to test sortHashDescending.",1);
ok(undef, 'sortHashDescending()');
}
cleanup(); # this line is required
# ---- DO NOT EDIT BELOW THIS LINE -----
sub initialize {
$|=1; # disable output buffering
my $configFile;
GetOptions(
'configFile=s'=>\$configFile
);
exit 1 unless ($configFile);
WebGUI::Session::open("..",$configFile);
}
sub cleanup {
WebGUI::Session::close();
}

43
t/_test.skeleton Normal file
View file

@ -0,0 +1,43 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2005 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
# ---- BEGIN DO NOT EDIT ----
use strict;
use lib '../lib';
use Getopt::Long;
use WebGUI::Session;
# ---- END DO NOT EDIT ----
use Test::More tests => 1; # increment this value for each test you create
initialize(); # this line is required
# put your tests here
cleanup(); # this line is required
# ---- DO NOT EDIT BELOW THIS LINE -----
sub initialize {
$|=1; # disable output buffering
my $configFile;
GetOptions(
'configFile=s'=>\$configFile
);
exit 1 unless ($configFile);
WebGUI::Session::open("..",$configFile);
}
sub cleanup {
WebGUI::Session::close();
}