diff Lib/IMPL/Test.pm @ 165:76515373dac0

Added Class::Template, Rewritten SQL::Schema 'use parent' directive instead of 'use base'
author wizard
date Sat, 23 Apr 2011 23:06:48 +0400
parents f8de52d3c112
children 029c9610528c
line wrap: on
line diff
--- a/Lib/IMPL/Test.pm	Mon Mar 28 01:36:24 2011 +0400
+++ b/Lib/IMPL/Test.pm	Sat Apr 23 23:06:48 2011 +0400
@@ -6,7 +6,7 @@
 
 require Exporter;
 our @ISA = qw(Exporter);
-our @EXPORT_OK = qw(&test &shared &failed &cmparray &skip &run_plan);
+our @EXPORT_OK = qw(&test &shared &failed &cmparray &skip &run_plan &assert);
 
 require IMPL::Test::Unit;
 require IMPL::Test::Plan;
@@ -38,6 +38,12 @@
     die new IMPL::Test::FailException(@_);
 }
 
+sub assert {
+	my ($condition,@params) = @_;
+	
+	die new IMPL::Test::FailException(@params ? @params : ("Assertion failed" , _GetSourceLine( (caller)[1,2] )) ) unless $condition;
+}
+
 sub skip($;@) {
 	die new IMPL::Test::SkipException(@_);
 }
@@ -54,6 +60,18 @@
     return 1;
 }
 
+sub _GetSourceLine {
+	my ($file,$line) = @_;
+	
+	open my $hFile, $file or return "failed to open file: $file: $!";
+	
+	my $text;
+	$text = <$hFile> for ( 1 .. $line);
+	chomp $text;
+	$text =~ s/^\s+//;
+	return "line $line: $text";
+}
+
 sub run_plan {
 	my (@units) = @_;