changeset 683:ccc17667ffb2

...
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Fri, 21 Aug 2020 08:08:43 +0900
parents 49d57e7fce39
children 117c0ef2279f
files src/parallel_execution/lib/Gears/Util.pm src/parallel_execution/perlTests/README.md src/parallel_execution/perlTests/util.t
diffstat 3 files changed, 24 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/lib/Gears/Util.pm	Fri Aug 21 06:35:07 2020 +0900
+++ b/src/parallel_execution/lib/Gears/Util.pm	Fri Aug 21 08:08:43 2020 +0900
@@ -16,7 +16,8 @@
   my $ir = _parse_base($file_name);
 
   unless ($ir->{name}) {
-    croak "invalid struct name $file_name";
+    carp "[WARN] invalid interface name at $file_name";
+    return undef;
   }
   return $ir;
 }
@@ -252,8 +253,9 @@
 sub file_checking {
   my ($class, $file_name) = @_;
   unless (-f $file_name) {
-    croak "invalid filepath :$file_name\n";
+    croak "[ERROR] invalid filepath :$file_name\n";
   }
+  return $file_name;
 }
 
 sub slup {
@@ -266,18 +268,18 @@
 
 
 sub find_cbc_sources_from_path {
-  my $class = shift;
-  my $find_path = shift // ".";
+  my ($class, $find_path) = @_;
+  $find_path //= ".";
 
-  my @files;
-  find( { wanted => sub { push @files, $_ if /\.cbc/ }, no_chdir => 1 }, $find_path);
+  my @files;  find( { wanted => sub { push @files, $_ if /\.
+cbc/ }, no_chdir => 1 }, $find_path);
 
   return \@files;
 }
 
 sub find_headers_from_path {
-  my $class = shift;
-  my $find_path = shift // ".";
+  my ($class, $find_path) = @_;
+  $find_path //= ".";
 
   my @files;
   find( { wanted => sub { push @files, $_ if /\.(?:h|dg)/ }, no_chdir => 1 }, $find_path);
--- a/src/parallel_execution/perlTests/README.md	Fri Aug 21 06:35:07 2020 +0900
+++ b/src/parallel_execution/perlTests/README.md	Fri Aug 21 08:08:43 2020 +0900
@@ -3,5 +3,5 @@
 ## USAGE
 
 ```
-$prove -v perlTests -Ilib
+$prove -Ilib -v perlTests
 ```
--- a/src/parallel_execution/perlTests/util.t	Fri Aug 21 06:35:07 2020 +0900
+++ b/src/parallel_execution/perlTests/util.t	Fri Aug 21 08:08:43 2020 +0900
@@ -1,10 +1,22 @@
 #!/usr/bin/env perl
 use strict;
 use warnings;
+use FindBin;
 
 use Test::More;
 
-use_ok "Gears::Util";
+use_ok "Gears::Util"; #use test
+
+use Gears::Util;
 
+subtest 'file_checking' => sub {
+  eval { Gears::Util->file_checking("nonexistent_file.c") };
+  ok $@
+      && like( $@, qr/invalid filepath/ );
+
+  my $exists_file = "$FindBin::Bin/README.md";
+  my $found_file = Gears::Util->file_checking($exists_file);
+  is $found_file, $exists_file;
+};
 
 done_testing;