← Back to team overview

mvhub-dev team mailing list archive

[Merge] lp:~himabindu-sanagavarapu/mvhub/header_doc_t into lp:mvhub

 

hsanagavarapu has proposed merging lp:~himabindu-sanagavarapu/mvhub/header_doc_t into lp:mvhub.

Requested reviews:
  MVHub devs with commit rights (mvhub-commit)


This brach has header_doc.t test script.It will return false if particular file does not have header.
-- 
https://code.launchpad.net/~himabindu-sanagavarapu/mvhub/header_doc_t/+merge/33945
Your team MVHub Developers is subscribed to branch lp:mvhub.
=== added file 'app-mvhub/t/header_doc.t'
--- app-mvhub/t/header_doc.t	1970-01-01 00:00:00 +0000
+++ app-mvhub/t/header_doc.t	2010-08-27 18:42:43 +0000
@@ -0,0 +1,58 @@
+#!/usr/bin/perl 
+
+use constant MAX_LINES_TO_SEARCH => 16;
+use strict;
+use warnings;
+
+use MVHub::Utils::Setup;
+
+use TestHelper;
+use Test::More;
+
+my @keywords = qw(LICENSE COPYRIGHT CONTACT PROJECT PURPOSE);
+my @files    = get_files("'*'");
+
+my $lines_to_search;
+my @first_15_lines;
+my $test_message;
+my $file_type;
+
+sub _search_string_in_file {
+    my $string = $_[0];
+    my @contents = @{$_[1]};
+
+    my $regex    = qr/$string/;
+    return scalar grep { $_ =~ $regex } @contents;
+}
+
+foreach my $file (@files) {
+    $file_type = `file $file | grep -i text`;
+
+    if ($file_type) {
+        $lines_to_search = 1;
+        @first_15_lines = ();
+
+        open( FILE, '<', $file ) or die "failed to open $file error: $!";
+
+        foreach my $line (<FILE>) {
+	    push @first_15_lines, $line;
+#	    $first_15_lines[@first_15_lines] = $line;
+            $lines_to_search++;
+            if ( $lines_to_search == MAX_LINES_TO_SEARCH ) {
+                last;
+            }
+        }
+	close(FILE);
+
+        foreach my $required_keyword (@keywords) {
+            $test_message = "$file doesnot contains $required_keyword \n";
+	     ok( _search_string_in_file(
+                    $required_keyword, \@first_15_lines
+                ),
+                $test_message
+            );
+        }
+    }
+}
+done_testing();
+


Follow ups