dslinux/user/perl/NetWare/t NWModify.pl NWScripts.pl Readme.txt

cayenne dslinux_cayenne at user.in-berlin.de
Mon Dec 4 17:58:59 CET 2006


Update of /cvsroot/dslinux/dslinux/user/perl/NetWare/t
In directory antilope:/tmp/cvs-serv17422/NetWare/t

Added Files:
	NWModify.pl NWScripts.pl Readme.txt 
Log Message:
Adding fresh perl source to HEAD to branch from

--- NEW FILE: NWModify.pl ---


print "\nModifying the '.t' files...\n\n";

use File::Basename;
use File::Copy;

## Change the below line to the folder you want to process
$DirName = "/perl/scripts/t";

$FilesTotal = 0;
$FilesRead = 0;
$FilesModified = 0;

opendir(DIR, $DirName);
@Dirs = readdir(DIR);

foreach $DirItem(@Dirs)
{
	$DirItem = $DirName."/".$DirItem;
	push @DirNames, $DirItem;	# All items under  $DirName  folder is copied into an array.
}

foreach $FileName(@DirNames)
{
	if(-d $FileName)
	{	# If an item is a folder, then open it further.

		opendir(SUBDIR, $FileName);
		@SubDirs = readdir(SUBDIR);
		close(SUBDIR);

		foreach $SubFileName(@SubDirs)
		{
			if(-f $SubFileName)
			{
				&Process_File($SubFileName);	# If file, process it.
			}
			else
			{
				$SubFileName = $FileName."/".$SubFileName;
				push @DirNames, $SubFileName;	# If sub-folder, push it into the array.
			}
		}
	}
	else
	{
		if(-f $FileName)
		{
			&Process_File($FileName);	# If file, process it.
		}
	}
}

close(DIR);

print "\n\n\nTotal number of files present = $FilesTotal\n";
print "Total number of '.t' files read = $FilesRead\n";
print "Total number of '.t' files modified = $FilesModified\n\n";




# Process the file.
sub Process_File
{
	local($FileToProcess) = @_;		# File name.
	local($Modified) = 0;

	if(!(-w $FileToProcess)) {
		# If the file is a read-only file, then change its mode to read-write.
		chmod(0777, $FileToProcess);
	}

	## For example:
	## If the value of $FileToProcess is '/perl/scripts/t/pragma/warnings.t', then
		## $dir = '/perl/scripts/t/pragma/'
		## $base = 'warnings'
		## $ext = '.t'
	$dir = dirname($FileToProcess);		# Get the folder name
	$base = basename($FileToProcess);	# Get the base name
	($base, $dir, $ext) = fileparse($FileToProcess, '\..*');	# Get the extension of the file passed.


	# Do the processing only if the file has '.t' extension.
	if($ext eq '.t') {

		open(FH, "+< $FileToProcess") or die "Unable to open the file,  $FileToProcess  for reading and writing.\n";
		@ARRAY = <FH>;	# Get the contents of the file into an array.

		foreach $Line(@ARRAY)	# Get each line of the file.
		{
			if($Line =~ m/\@INC = /)
			{	# If the line contains the string (@INC = ), then replace it

				# Replace "@INC = " with "unshift @INC, "
				$Line =~ s/\@INC = /unshift \@INC, /;

				$Modified = 1;
			}

			if($Line =~ m/push \@INC, /)
			{	# If the line contains the string (push @INC, ), then replace it

				# Replace "push @INC, " with "unshift @INC, "
				$Line =~ s/push \@INC, /unshift \@INC, /;

				$Modified = 1;
			}
		}

		seek(FH, 0, 0);		# Seek to the beginning.
		print FH @ARRAY;	# Write the changed array into the file.
		close FH;			# close the file.

		$FilesRead++;	# One more file read.

		if($Modified) {
			print "Modified the file,  $FileToProcess\n";
			$Modified = 0;

			$FilesModified++;	# One more file modified.
		}
	}

	$FilesTotal++;	# One more file present.
}


--- NEW FILE: Readme.txt ---


		Automated Testing of Perl5 Interpreter for NetWare.



A set of Standard Unit Test Scripts to test all the functionalities of 
Perl5 Interpreter are available along with the CPAN download. They are 
all located under 't' folder. These include sub-folders under 't' such 
as: 'base', 'cmd', 'comp', 'io', lib', 'op', 'pod', 'pragma' and 'run'. 
Each of these sub-folders contain few test scripts ('.t' files) under 
them.

Executing these test scripts on NetWare can be automated as per the 
following:

1. Generate automated scripts like 'base.pl', 'cmd.pl', 'comp.pl', 'io.pl',
'lib.pl', 'op.pl', 'pod.pl', 'pragma.pl', 'run.pl' that execute all the
test scripts ('.t' files) under the corresponding folder.

For example, 'base.pl' to test all the scripts 
              under 'sys:\perl\scripts\t\base' folder,
             'comp.pl' to test all the scripts 
              under 'sys:\perl\scripts\t\comp' folder and so on.

2. Generate an automated script, 'nwauto.pl' that executes all the above 
mentioned '.pl' automated scripts, thus in turn executing all the '.t' 
scripts.

The script, 'NWScripts.pl' available under the 'NetWare\t' folder of the 
CPAN download, is written to generate these automated scripts when 
executed on a NetWare server. It generates 'base.pl', 'cmd.pl', 'comp.pl',
'io.pl', 'lib.pl', 'op.pl', 'pod.pl', 'pragma.pl', 'run.pl' and also 
'nwauto.pl' by including all the corresponding '.t' scripts in them in 
backtick operators.

For example, all the scripts that are under 't\base' folder will be 
entered in 'base.pl' and so on. 'nwauto.pl' includes all these '.pl' 
scripts like 'base.pl', 'comp.pl' etc.


Perform the following steps to execute the automated scripts:

1. Map your NetWare server to "i:"

2. After complete build (building both interpreter and all extensions)
of Perl for NetWare, execute "nmake nwinstall" in the 'NetWare' folder
of the CPAN download. This installs all the library files, perl modules,
the '.pl' files under 'NetWare\t' folder and all the '.t' scripts
under 't' folder, all in appropriate folders onto your server.

3. Execute the command  "perl t\NWModify.pl"  on the console command 
prompt of your server. This script replaces

     "@INC = " with "unshift @INC, "  and
     "push @INC, " with "unshift @INC, "

from all the scripts under 'sys:\perl\scripts\t' folder.

This is done to include the correct path for libraries into the scripts 
when executed on NetWare. If this is not done, some of the scripts will 
not get executed since they cannot locate the corresponding libraries.

4. Execute the command  "perl t\NWScripts.pl"  on the console command 
prompt to generate the automated scripts mentioned above 
under the 'sys:\perl\scripts\t' folder.

5. Execute the command  "perl t\nwauto.pl"  on the server console command 
prompt. This runs all the standard test scripts. If you desire to 
redirect or save the results into a file, say 'nwauto.txt', then the 
console command to execute is:  "perl t\nwauto.pl > nwauto.txt".

6. If you wish to execute only a certain set of scripts, then run the 
corresponding '.pl' file. For example, if you wish to execute only the 
'lib' scripts, then execute 'lib.pl' through the server console command, 
"perl t\lib.pl'. To redirect the results into a file, the console command
 is, "perl t\lib.pl > lib.txt".



Known Issues:

The following scripts are commented out in the corresponding autoscript:

1. 'openpid.t' in 'sys:\perl\scripts\t\io.pl' script
   Reason:
     This either hangs or abends the server when executing through auto 
     scripts. When run individually, the script execution goes through 
     fine.

2. 'argv.t' in 'sys:\perl\scripts\t\io.pl' script
   Reason:
     This either hangs or abends the server when executing through auto 
     scripts. When run individually, the script execution goes through 
     fine.

3. 'filehandle.t' in 'sys:\perl\scripts\t\lib.pl' script
   Reason:
     This hangs in the last test case where it uses FileHandle::Pipe 
     whether run individually or through an auto script.


--- NEW FILE: NWScripts.pl ---


print "\nGenerating automated scripts for NetWare...\n\n\n";


use File::Basename;
use File::Copy;

chdir '/perl/scripts/';
$DirName = "t";

# These scripts have problems (either abend or hang) as of now (11 May 2001).
# So, they are commented out in the corresponding auto scripts, io.pl and lib.pl
@ScriptsNotUsed = ("t/io/openpid.t", "t/lib/filehandle.t", "t/lib/memoize/t/expire_module_t.t", "t/lib/NEXT/t/next.t", "t/lib/Math/BigInt/t/require.t", "t/ext/B/t/debug.t", "t/lib/IPC/Open3.t", "t/ext/B/t/showlex.t", "t/op/subst_wamp.t", "t/uni/upper.t", "t/lib/Net/t/ftp.t", "t/op/sort.t", "t/ext/POSIX/t/posix.t", "t/lib/CPAN/t/loadme.t", "t/lib/CPAN/t/vcmp.t");

opendir(DIR, $DirName);
@Dirs = readdir(DIR);
close(DIR);
foreach $DirItem(@Dirs)
{
	$DirItem1 = $DirName."/".$DirItem;
	push @DirNames, $DirItem1;	# All items under  $DirName  folder is copied into an array.

	if(-d $DirItem1)
	{	# If an item is a folder, then open it further.

		# Intemediary automated script like base.pl, lib.pl, cmd.pl etc.
		$IntAutoScript = "t/".$DirItem.".pl";

		# Open once in write mode since later files are opened in append mode,
		# and if there already exists a file with the same name, all further opens
		# will append to that file!!
		open(FHW, "> $IntAutoScript") or die "Unable to open the file,  $IntAutoScript  for writing.\n";
		seek(FHW, 0, 0);	# seek to the beginning of the file.
		close FHW;			# close the file.
	}
}


print "Generating  t/nwauto.pl ...\n\n\n";

open(FHWA, "> t/nwauto.pl") or die "Unable to open the file,  t/nwauto.pl  for writing.\n";
seek(FHWA, 0, 0);	# seek to the beginning of the file.

$version = sprintf("%vd",$^V);
print FHWA "\n\nprint \"Automated Unit Testing of Perl$version for NetWare\\n\\n\\n\"\;\n\n\n";


foreach $FileName(@DirNames)
{
	$index = 0;
	if(-d $FileName)
	{	# If an item is a folder, then open it further.

		$dir = dirname($FileName);		# Get the folder name

		foreach $DirItem1(@Dirs)
		{
			$DirItem2 = $DirItem1;
			if($FileName =~ m/$DirItem2/)
			{
				$DirItem = $DirItem1;

				# Intemediary automated script like base.pl, lib.pl, cmd.pl etc.
				$IntAutoScript = "t/".$DirItem.".pl";
			}
		}

		# Write into the intermediary auto script.
		open(FHW, ">> $IntAutoScript") or die "Unable to open the file,  $IntAutoScript  for appending.\n";
		seek(FHW, 0, 2);	# seek to the end of the file.

		$pos = tell(FHW);
		if($pos <= 0)
		{
			print "Generating  $IntAutoScript...\n";
			print FHW "\n\nprint \"Testing  $DirItem  folder:\\n\\n\\n\"\;\n\n\n";
		}

		opendir(SUBDIR, $FileName);
		@SubDirs = readdir(SUBDIR);
		close(SUBDIR);
		foreach $SubFileName(@SubDirs)
		{
			$SubFileName = $FileName."/".$SubFileName;
			if(-d $SubFileName)
			{
				push @DirNames, $SubFileName;	# If sub-folder, push it into the array.
			}
			else
			{
				&Process_File($SubFileName);	# If file, process it.
			}

			$index++;
		}

		close FHW;			# close the file.

		if($index <= 0)
		{
			# The folder is empty and delete the corresponding '.pl' file.
			unlink($IntAutoScript);
			print "Deleted  $IntAutoScript  since it corresponded to an empty folder.\n";
		}
		else
		{
			if($pos <= 0)
			{	# This logic to make sure that it is written only once.
				# Only if something is written into the intermediary auto script,
				# only then make an entry of the intermediary auto script in  nwauto.pl
				print FHWA "print \`perl $IntAutoScript\`\;\n";
				print FHWA "print \"\\n\\n\\n\"\;\n\n";
			}
		}
	}
	else
	{
		if(-f $FileName)
		{
			$dir = dirname($FileName);		# Get the folder name
			$base = basename($FileName);	# Get the base name
			($base, $dir, $ext) = fileparse($FileName, '\..*');	# Get the extension of the file passed.
			
			# Do the processing only if the file has '.t' extension.
			if($ext eq '.t')
			{
				print FHWA "print \`perl $FileName\`\;\n";
				print FHWA "print \"\\n\\n\\n\"\;\n\n";
			}
		}
	}
}


## Below adds the ending comments into all the intermediary auto scripts:

opendir(DIR, $DirName);
@Dirs = readdir(DIR);
close(DIR);
foreach $DirItem(@Dirs)
{
	$index = 0;

	$FileName = $DirName."/".$DirItem;
	if(-d $FileName)
	{	# If an item is a folder, then open it further.

		opendir(SUBDIR, $FileName);
		@SubDirs = readdir(SUBDIR);
		close(SUBDIR);

		# To not to write into the file if the corresponding folder was empty.
		foreach $SubDir(@SubDirs)
		{
			$index++;
		}

		if($index > 0)
		{
			# The folder not empty.

			# Intemediary automated script like base.pl, lib.pl, cmd.pl etc.
			$IntAutoScript = "t/".$DirItem.".pl";

			# Write into the intermediary auto script.
			open(FHW, ">> $IntAutoScript") or die "Unable to open the file,  $IntAutoScript  for appending.\n";
			seek(FHW, 0, 2);	# seek to the end of the file.

			# Write into the intermediary auto script.
			print FHW "\nprint \"Testing of  $DirItem  folder done!\\n\\n\"\;\n\n";

			close FHW;			# close the file.
		}
	}
}


# Write into  nwauto.pl
print FHWA "\nprint \"Automated Unit Testing of Perl$version for NetWare done!\\n\\n\"\;\n\n";

close FHWA;			# close the file.

print "\n\nGeneration of  t/nwauto.pl  Done!\n\n";

print "\nGeneration of automated scripts for NetWare DONE!\n";




# Process the file.
sub Process_File
{
	local($FileToProcess) = @_;		# File name.
	local($Script) = 0;
	local($HeadCut) = 0;

	## For example:
	## If the value of $FileToProcess is '/perl/scripts/t/pragma/warnings.t', then
		## $dir1 = '/perl/scripts/t/pragma/'
		## $base1 = 'warnings'
		## $ext1 = '.t'
	$dir1 = dirname($FileToProcess);	# Get the folder name
	$base1 = basename($FileToProcess);	# Get the base name
	($base1, $dir1, $ext1) = fileparse($FileToProcess, '\..*');	# Get the extension of the file passed.

	# Do the processing only if the file has '.t' extension.
	if($ext1 eq '.t')
	{
		foreach $Script(@ScriptsNotUsed)
		{
			# The variables are converted to lower case before they are compared.
			# This is done to remove the case-sensitive comparison done by 'eq'.
			$Script1 = lc($Script);
			$FileToProcess1 = lc($FileToProcess);
			if($Script1 eq $FileToProcess1)
			{
				$HeadCut = 1;
			}
		}

		if($HeadCut)
		{
			# Write into the intermediary auto script.
			print FHW "=head\n";
		}

		# Write into the intermediary auto script.
		print FHW "print \"Testing  $base1"."$ext1:\\n\\n\"\;\n";
		print FHW "print \`perl $FileToProcess\`\;\n";	# Write the changed array into the file.
		print FHW "print \"\\n\\n\\n\"\;\n";

		if($HeadCut)
		{
			# Write into the intermediary auto script.
			print FHW "=cut\n";
		}

		$HeadCut = 0;
		print FHW "\n";
	}
}





More information about the dslinux-commit mailing list