From cc2e323cde69e41702155dbd6165d1a5b22028fb Mon Sep 17 00:00:00 2001
From: "benjamin.franksen" <benjamin.franksen@helmholtz-berlin.de>
Date: Tue, 28 Jun 2011 10:57:17 +0000
Subject: [PATCH] test/compiler: factor out common stuff into make_test_lib.pm

---
 test/compiler/make64_test.plt  | 51 ++++++++--------------------------
 test/compiler/make_test.plt    | 51 ++++++++--------------------------
 test/compiler/make_test_lib.pm | 42 ++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 80 deletions(-)
 create mode 100644 test/compiler/make_test_lib.pm

diff --git a/test/compiler/make64_test.plt b/test/compiler/make64_test.plt
index 95a6c2d0..745f0800 100644
--- a/test/compiler/make64_test.plt
+++ b/test/compiler/make64_test.plt
@@ -2,44 +2,15 @@
 # Instead, run make64_test.t inside O.$(EPICS_HOST_ARCH)
 
 use strict;
-use Test::More;
-
-my $success = {
-};
-
-my $error = {
-  tooLong => undef,
-  varinit => undef,
-  varinitOptr => undef,
-};
-
-sub do_test {
-  my ($test) = @_;
-  $_ = `make -B -s TESTPROD=$test 2>&1`;
-  # uncomment this comment to find out what went wrong:
-  #diag("$test result=$?, response=$_");
-}
-
-sub check_success {
-  ok($? != -1 and $? == 0 and not /error/);
-}
-
-sub check_error {
-  my $ne = 0;
-  ok($? != -1 and $? != 0);
-}
-
-plan tests => keys(%$success) + keys(%$error);
-
-my @alltests = (
-  [\&check_success, $success],
-  [\&check_error, $error],
+use lib "..";
+use make_test_lib;
+
+make_test_lib::do_tests(
+  success => [qw(
+  )],
+  failure => [qw(
+    tooLong
+    varinit
+    varinitOptr
+  )]
 );
-
-foreach my $group (@alltests) {
-  my ($check,$tests) = @$group;
-  foreach my $test (sort(keys(%$tests))) {
-    do_test($test);
-    &$check();
-  }
-}
diff --git a/test/compiler/make_test.plt b/test/compiler/make_test.plt
index 5e9fb429..8c1be424 100644
--- a/test/compiler/make_test.plt
+++ b/test/compiler/make_test.plt
@@ -2,44 +2,15 @@
 # Instead, run make_test.t inside O.$(EPICS_HOST_ARCH)
 
 use strict;
-use Test::More;
-
-my $success = {
-  tooLong => undef,
-};
-
-my $error = {
-  varinit => undef,
-  varinitOptr => undef,
-};
-
-sub do_test {
-  my ($test) = @_;
-  $_ = `make -B -s TESTPROD=$test 2>&1`;
-  # uncomment this comment to find out what went wrong:
-  #diag("$test result=$?, response=$_");
-}
-
-sub check_success {
-  ok($? != -1 and $? == 0 and not /error/);
-}
-
-sub check_error {
-  my $ne = 0;
-  ok($? != -1 and $? != 0);
-}
-
-plan tests => keys(%$success) + keys(%$error);
-
-my @alltests = (
-  [\&check_success, $success],
-  [\&check_error, $error],
+use lib "..";
+use make_test_lib;
+
+make_test_lib::do_tests(
+  success => [qw(
+    tooLong
+  )],
+  failure => [qw(
+    varinit
+    varinitOptr
+  )]
 );
-
-foreach my $group (@alltests) {
-  my ($check,$tests) = @$group;
-  foreach my $test (sort(keys(%$tests))) {
-    do_test($test);
-    &$check();
-  }
-}
diff --git a/test/compiler/make_test_lib.pm b/test/compiler/make_test_lib.pm
new file mode 100644
index 00000000..75edd9ab
--- /dev/null
+++ b/test/compiler/make_test_lib.pm
@@ -0,0 +1,42 @@
+package make_test_lib;
+
+use strict;
+use Test::More;
+
+sub do_test {
+  my ($test) = @_;
+  $_ = `make -B -s TESTPROD=$test 2>&1`;
+  # uncomment this comment to find out what went wrong:
+  #diag("$test result=$?, response=$_");
+}
+
+sub check_success {
+  ok($? != -1 and $? == 0 and not /error/);
+}
+
+sub check_failure {
+  my $ne = 0;
+  ok($? != -1 and $? != 0);
+}
+
+sub do_tests {
+  my %tests = @_;
+
+  my @alltests = (
+    [\&check_success, $tests{success}],
+    [\&check_failure, $tests{failure}],
+  );
+
+  plan tests => @{$tests{success}} + @{$tests{failure}};
+
+  foreach my $group (@alltests) {
+    my ($check,$tests) = @$group;
+    foreach my $test (@$tests) {
+      do_test($test);
+      &$check();
+    }
+  }
+
+}
+
+1;
-- 
GitLab