NetWare scripts tweak from Ananth Kesari.
[p5sagit/p5-mst-13.2.git] / NetWare / t / NWScripts.pl
CommitLineData
2986a63f 1
2
3print "\nGenerating automated scripts for NetWare...\n\n\n";
4
5
6use File::Basename;
7use File::Copy;
8
9chdir '/perl/scripts/';
10$DirName = "t";
11
2986a63f 12# These scripts have problems (either abend or hang) as of now (11 May 2001).
13# So, they are commented out in the corresponding auto scripts, io.pl and lib.pl
9b8395f0 14@ScriptsNotUsed = ("t/io/argv.t", "t/io/openpid.t", "t/lib/filehandle.t", "t/lib/warnings.t");\r
2986a63f 15
225a5dca 16opendir(DIR, $DirName);
17@Dirs = readdir(DIR);
18close(DIR);
19foreach $DirItem(@Dirs)
20{
21 $DirItem1 = $DirName."/".$DirItem;
22 push @DirNames, $DirItem1; # All items under $DirName folder is copied into an array.
2986a63f 23
225a5dca 24 if(-d $DirItem1)
25 { # If an item is a folder, then open it further.
2986a63f 26
225a5dca 27 # Intemediary automated script like base.pl, lib.pl, cmd.pl etc.
28 $IntAutoScript = "t/".$DirItem.".pl";
2986a63f 29
225a5dca 30 # Open once in write mode since later files are opened in append mode,
31 # and if there already exists a file with the same name, all further opens
32 # will append to that file!!
33 open(FHW, "> $IntAutoScript") or die "Unable to open the file, $IntAutoScript for writing.\n";
34 seek(FHW, 0, 0); # seek to the beginning of the file.
35 close FHW; # close the file.
36 }
37}
2986a63f 38
39
225a5dca 40print "Generating t/nwauto.pl ...\n\n\n";
41
42open(FHWA, "> t/nwauto.pl") or die "Unable to open the file, t/nwauto.pl for writing.\n";
43seek(FHWA, 0, 0); # seek to the beginning of the file.
44flock(FHWA, LOCK_EX); # Lock the file for safety purposes.
45
46$version = sprintf("%vd",$^V);
47print FHWA "\n\nprint \"Automated Unit Testing of Perl$version for NetWare\\n\\n\\n\"\;\n\n\n";
2986a63f 48
2986a63f 49
50foreach $FileName(@DirNames)
51{
225a5dca 52 $index = 0;
2986a63f 53 if(-d $FileName)
225a5dca 54 { # If an item is a folder, then open it further.
2986a63f 55
225a5dca 56 $dir = dirname($FileName); # Get the folder name
2986a63f 57
225a5dca 58 foreach $DirItem1(@Dirs)
59 {
60 $DirItem2 = $DirItem1;
61 if($FileName =~ m/$DirItem2/)
62 {
63 $DirItem = $DirItem1;
2986a63f 64
225a5dca 65 # Intemediary automated script like base.pl, lib.pl, cmd.pl etc.
66 $IntAutoScript = "t/".$DirItem.".pl";
67 }
68 }
2986a63f 69
2986a63f 70 # Write into the intermediary auto script.
225a5dca 71 open(FHW, ">> $IntAutoScript") or die "Unable to open the file, $IntAutoScript for appending.\n";
72 seek(FHW, 0, 2); # seek to the end of the file.
2986a63f 73 flock(FHW, LOCK_EX); # Lock the file for safety purposes.
74
225a5dca 75 $pos = tell(FHW);
76 if($pos <= 0)
77 {
78 print "Generating $IntAutoScript...\n";
79 print FHW "\n\nprint \"Testing $DirItem folder:\\n\\n\\n\"\;\n\n\n";
80 }
2986a63f 81
225a5dca 82 opendir(SUBDIR, $FileName);
83 @SubDirs = readdir(SUBDIR);
84 close(SUBDIR);
2986a63f 85 foreach $SubFileName(@SubDirs)
86 {
225a5dca 87 $SubFileName = $FileName."/".$SubFileName;
2986a63f 88 if(-d $SubFileName)
89 {
225a5dca 90 push @DirNames, $SubFileName; # If sub-folder, push it into the array.
2986a63f 91 }
92 else
93 {
2986a63f 94 &Process_File($SubFileName); # If file, process it.
95 }
2986a63f 96
225a5dca 97 $index++;
98 }
2986a63f 99
100 flock(FHW, LOCK_UN); # unlock the file.
101 close FHW; # close the file.
225a5dca 102
103 if($index <= 0)
104 {
105 # The folder is empty and delete the corresponding '.pl' file.
106 unlink($IntAutoScript);
107 print "Deleted $IntAutoScript since it corresponded to an empty folder.\n";
108 }
109 else
110 {
111 if($pos <= 0)
112 { # This logic to make sure that it is written only once.
113 # Only if something is written into the intermediary auto script,
114 # only then make an entry of the intermediary auto script in nwauto.pl
115 print FHWA "print \`perl $IntAutoScript\`\;\n";
116 print FHWA "print \"\\n\\n\\n\"\;\n\n";
117 }
118 }
119 }
120 else
121 {
122 if(-f $FileName)
123 {
124 $dir = dirname($FileName); # Get the folder name
125 $base = basename($FileName); # Get the base name
126 ($base, $dir, $ext) = fileparse($FileName, '\..*'); # Get the extension of the file passed.
127
128 # Do the processing only if the file has '.t' extension.
129 if($ext eq '.t')
130 {
131 print FHWA "print \`perl $FileName\`\;\n";
132 print FHWA "print \"\\n\\n\\n\"\;\n\n";
133 }
134 }
2986a63f 135 }
136}
137
225a5dca 138
139## Below adds the ending comments into all the intermediary auto scripts:
140
141opendir(DIR, $DirName);
142@Dirs = readdir(DIR);
2986a63f 143close(DIR);
225a5dca 144foreach $DirItem(@Dirs)
145{
146 $index = 0;
147
148 $FileName = $DirName."/".$DirItem;
149 if(-d $FileName)
150 { # If an item is a folder, then open it further.
2986a63f 151
225a5dca 152 opendir(SUBDIR, $FileName);
153 @SubDirs = readdir(SUBDIR);
154 close(SUBDIR);
2986a63f 155
225a5dca 156 # To not to write into the file if the corresponding folder was empty.
157 foreach $SubDir(@SubDirs)
158 {
159 $index++;
160 }
161
162 if($index > 0)
163 {
164 # The folder not empty.
165
166 # Intemediary automated script like base.pl, lib.pl, cmd.pl etc.
167 $IntAutoScript = "t/".$DirItem.".pl";
168
169 # Write into the intermediary auto script.
170 open(FHW, ">> $IntAutoScript") or die "Unable to open the file, $IntAutoScript for appending.\n";
171 seek(FHW, 0, 2); # seek to the end of the file.
172 flock(FHW, LOCK_EX); # Lock the file for safety purposes.
173
174 # Write into the intermediary auto script.
175 print FHW "\nprint \"Testing of $DirItem folder done!\\n\\n\"\;\n\n";
176
177 flock(FHW, LOCK_UN); # unlock the file.
178 close FHW; # close the file.
179 }
180 }
181}
182
183
184# Write into nwauto.pl
185print FHWA "\nprint \"Automated Unit Testing of Perl$version for NetWare done!\\n\\n\"\;\n\n";
2986a63f 186
187flock(FHWA, LOCK_UN); # unlock the file.
188close FHWA; # close the file.
189
225a5dca 190print "\n\nGeneration of t/nwauto.pl Done!\n\n";
2986a63f 191
225a5dca 192print "\nGeneration of automated scripts for NetWare DONE!\n";
2986a63f 193
2986a63f 194
195
196
197# Process the file.
198sub Process_File
199{
200 local($FileToProcess) = @_; # File name.
201 local($Script) = 0;
202 local($HeadCut) = 0;
203
225a5dca 204 ## For example:
2986a63f 205 ## If the value of $FileToProcess is '/perl/scripts/t/pragma/warnings.t', then
206 ## $dir1 = '/perl/scripts/t/pragma/'
207 ## $base1 = 'warnings'
208 ## $ext1 = '.t'
225a5dca 209 $dir1 = dirname($FileToProcess); # Get the folder name
210 $base1 = basename($FileToProcess); # Get the base name
211 ($base1, $dir1, $ext1) = fileparse($FileToProcess, '\..*'); # Get the extension of the file passed.
2986a63f 212
213 # Do the processing only if the file has '.t' extension.
214 if($ext1 eq '.t')
215 {
216 foreach $Script(@ScriptsNotUsed)
217 {
225a5dca 218 # The variables are converted to lower case before they are compared.
219 # This is done to remove the case-sensitive comparison done by 'eq'.
220 $Script1 = lc($Script);
221 $FileToProcess1 = lc($FileToProcess);
222 if($Script1 eq $FileToProcess1)
2986a63f 223 {
224 $HeadCut = 1;
225 }
226 }
227
228 if($HeadCut)
229 {
230 # Write into the intermediary auto script.
231 print FHW "=head\n";
232 }
233
234 # Write into the intermediary auto script.
235 print FHW "print \"Testing $base1"."$ext1:\\n\\n\"\;\n";
236 print FHW "print \`perl $FileToProcess\`\;\n"; # Write the changed array into the file.
237 print FHW "print \"\\n\\n\\n\"\;\n";
238
239 if($HeadCut)
240 {
241 # Write into the intermediary auto script.
242 print FHW "=cut\n";
243 }
244
245 $HeadCut = 0;
246 print FHW "\n";
247 }
248}
249