Meta::Development::Assert - object to inherit verbose objects from.


Meta documentation Contained in the Meta distribution.

Index


Code Index:

NAME

Top

Meta::Development::Assert - object to inherit verbose objects from.

COPYRIGHT

Top

LICENSE

Top

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.

DETAILS

Top

	MANIFEST: Assert.pm
	PROJECT: meta
	VERSION: 0.00

SYNOPSIS

Top

	package foo;
	use Meta::Development::Assert qw();
	Meta::Development::Assert::assert_meq(3+4,7);

DESCRIPTION

Top

This module is a set of functions to ease making assertions in the code and handling the result of a failed assertion in a centralized manner. The modules default behaviour is to throw an Error::Simple exception whenever an assertion fails.

FUNCTIONS

Top

	assert_true($$)
	assert_false($$)
	assert_eq($$$)
	assert_ne($$$)
	assert_ge($$$)
	assert_gt($$$)
	assert_le($$$)
	assert_lt($$$)
	assert_seq($$$)
	assert_sne($$$)
	assert_isa($$$)
	is_number($)
	TEST($)

FUNCTION DOCUMENTATION

Top

assert_true($$)

Assert that the value passed is indeed true.

assert_false($$)

Assert that the value passed is indeed false.

assert_eq($$$)

Assert that two numerical values are equal.

assert_ne($$$)

Assert that two numerical values are different.

assert_ge($$$)

Assert that one numeric value is greater or equal to the other.

assert_gt($$$)

Assert that one numeric value is greater than the other.

assert_le($$$)

Assert that one numeric value is less or equal to the other.

assert_lt($$$)

Assert that one numeric value is less than the other.

assert_seq($$$)

Assert that two values are the same string.

assert_sne($$$)

Assert that two values are not the same string.

assert_isa($$$)

Assert that an object is of a certain type.

is_number($)

Assert that the string given is a number.

TEST($)

This is a testing suite for the Meta::Development::Assert module. This test is should be run by a higher level management system at integration or release time or just as a regular routine to check that all is well.

Currently this test suite just makes a simple assertion.

SUPER CLASSES

Top

None.

BUGS

Top

None.

AUTHOR

Top

	Name: Mark Veltzer
	Email: mailto:veltzer@cpan.org
	WWW: http://www.veltzer.org
	CPAN id: VELTZER

HISTORY

Top

	0.00 MV md5 issues

SEE ALSO

Top

Error(3), strict(3)

TODO

Top

Nothing.


Meta documentation Contained in the Meta distribution.

#!/bin/echo This is a perl module and should not be run

package Meta::Development::Assert;

use strict qw(vars refs subs);
use Error qw(:try);

our($VERSION,@ISA);
$VERSION="0.00";
@ISA=qw();

#sub assert_true($$);
#sub assert_false($$);
#sub assert_eq($$$);
#sub assert_ne($$$);
#sub assert_ge($$$);
#sub assert_gt($$$);
#sub assert_le($$$);
#sub assert_lt($$$);
#sub assert_seq($$$);
#sub assert_sne($$$);
#sub assert_isa($$$);
#sub is_number($);
#sub TEST($);

#__DATA__

sub assert_true($$) {
	my($val,$msg)=@_;
	if(!$val) {
		throw Meta::Error::Simple("value [".$val."] should be true [".$msg."]");
	}
}

sub assert_false($$) {
	my($val,$msg)=@_;
	if($val) {
		throw Meta::Error::Simple("value [".$val."] should be false [".$msg."]");
	}
}

sub assert_eq($$$) {
	my($one,$two,$msg)=@_;
	if($one!=$two) {
		throw Meta::Error::Simple("[".$one."]!=[".$two."] [".$msg."]");
	}
}

sub assert_ne($$$) {
	my($one,$two,$msg)=@_;
	if($one==$two) {
		throw Meta::Error::Simple("[".$one."]==[".$two."] [".$msg."]");
	}
}

sub assert_ge($$$) {
	my($one,$two,$msg)=@_;
	if($one<$two) {
		throw Meta::Error::Simple("[".$one."]<[".$two."] [".$msg."]");
	}
}

sub assert_gt($$$) {
	my($one,$two,$msg)=@_;
	if($one<=$two) {
		throw Meta::Error::Simple("[".$one."]<=[".$two."] [".$msg."]");
	}
}

sub assert_le($$$) {
	my($one,$two,$msg)=@_;
	if($one>$two) {
		throw Meta::Error::Simple("[".$one."]>[".$two."] [".$msg."]");
	}
}

sub assert_lt($$$) {
	my($one,$two,$msg)=@_;
	if($one>=$two) {
		throw Meta::Error::Simple("[".$one."]>=[".$two."] [".$msg."]");
	}
}

sub assert_seq($$$) {
	my($one,$two,$msg)=@_;
	if($one ne $two) {
		throw Meta::Error::Simple("[".$one."] ne [".$two."] [".$msg."]");
	}
}

sub assert_sne($$$) {
	my($one,$two,$msg)=@_;
	if($one eq $two) {
		throw Meta::Error::Simple("[".$one."] eq [".$two."] [".$msg."]");
	}
}

sub assert_isa($$$) {
	my($object,$type,$msg)=@_;
	if(!$object->isa($type)) {
		throw Meta::Error::Simple("object [".$object."] not of type [".$type."] [".$msg."]");
	}
}

sub is_number($) {
	my($num)=@_;
	if($num!~/\d+/) {
		throw Meta::Error::Simple("string [".$num."] is not a number");
	}
}

sub TEST($) {
	my($context)=@_;
	Meta::Develop::Assert::assert_eq(3+4,7);
	return(1);
}

1;

__END__