<commit_before>#!/usr/bin/perl -w
#
# script to test the basic functionnalities of icommands.
# icommands location has to be put in the PATH env variable or their PATH will be asked
# at the beginning of the execution of this script.
#
# usage: ./testiCommands.pl
# If an argument is given, the debug mode is activated
#
# Copyright (c), CCIN2P3
# For more information please refer to files in the COPYRIGHT directory.

use strict;
use Cwd;
use Sys::Hostname;
use File::stat;

#-- Initialization

my $debug;
my $entry;
my @failureList;
my $i;
my $input;
my $irodsdefresource;
my $irodshost;
my $irodshome;
my $irodszone;
my $line;
my @list;
my $misc;
my $nfailure;
my $nsuccess;
my $rc;
my @returnref;
my @successlist;
my @summarylist;
my @tmp_tab;
my $username;
my @words;

my $unixuser     = `whoami`;
chomp $unixuser;
my $dir_w        = cwd();
my $myssize;
my $host         = hostname();
if ( $host =~ '.' ) {
	@words = split( /\./, $host );
	$host  = $words[0];
}
my $irodsfile;
my $irodsEnvFile = $ENV{'irodsEnvFile'};
if ($irodsEnvFile) {
    $irodsfile = $irodsEnvFile;
} else {
    $irodsfile    = "$ENV{HOME}/.irods/.irodsEnv";
}
my $ntests       = 0;
my $progname     = $0;

my $outputfile   = "testallrules_" . $host . ".log";

#-- Find current working directory and make consistency path

$outputfile   = $dir_w . '/' . $outputfile;

if ( $progname !~ '/' ) {
	$progname = $dir_w . '/' . $progname;
} else {
	if ( substr( $progname, 0, 2 ) eq './' ) {
		@words    = split( /\//, $progname );
		$i        = $#words;
		$progname = $dir_w . '/' . $words[$i];
	}
	if ( substr( $progname, 0, 1 ) ne '/' ) {
		$progname = $dir_w . '/' . $progname;
	}
}

#-- Take debug level

$debug = shift;
if ( ! $debug ) {
	$debug = 0;
} else {
	$debug = 1;
}

#-- Print debug

if ( $debug ) {
	print( "\n" );
	print( "MAIN: irodsfile        = $irodsfile\n" );
	print( "MAIN: cwd              = $dir_w\n" );
	print( "MAIN: outputfile       = $outputfile\n" );
	print( "MAIN: progname         = $progname\n" );
	print( "\n" );
}

#-- Dump content of $irodsfile to @list

@list = dumpFileContent( $irodsfile );

#-- Loop on content of @list
# The below parsing works in the current environment 
# but there are two shortcomings:
#   1) single quotes are removed, but if there were to be embedded ones,
#      they would be removed too.
#   2) if the name and value are separated by =, the line will not split right.
foreach $line ( @list ) {
 	chomp( $line );
	if ( ! $line ) { next; }
 	if ( $line =~ /irodsUserName/ ) {
		( $misc, $username ) = split( / /, $line );
		$username =~ s/\'//g; #remove all ' chars, if any
		next;
	}
	if ( $line =~ /irodsHome/ ) {
		( $misc, $irodshome ) = split( / /, $line );
		$irodshome =~ s/\'//g; #remove all ' chars, if any
		next;
	}
	if ( $line =~ /irodsZone/ ) {
		( $misc, $irodszone ) = split( / /, $line );
		$irodszone =~ s/\'//g; #remove all ' chars, if any
		next;
	}
	if ( $line =~ /irodsHost/ ) {
		( $misc, $irodshost ) = split( / /, $line );
		$irodshost =~ s/\'//g; #remove all ' chars, if any
		next;
	}
	if ( $line =~ /irodsDefResource/ ) {
		( $misc, $irodsdefresource ) = split( / /, $line );
		$irodsdefresource =~ s/\'//g; #remove all ' chars, if any
	}
}

#-- Print debug

if ( $debug ) {
	print( "MAIN: username         = $username\n" );
	print( "MAIN: irodshome        = $irodshome\n" );
	print( "MAIN: irodszone        = $irodszone\n" );
	print( "MAIN: irodshost        = $irodshost\n" );
	print( "MAIN: irodsdefresource = $irodsdefresource\n" );
}

#-- Environment setup and print to stdout

print( "\nThe results of the test will be written in the file: $outputfile\n\n" );
print( "Warning: you need to be a rodsadmin in order to pass successfully all the tests," );
print( " as some admin commands are being tested." );
print( " If icommands location has not been set into the PATH env variable," );
print( " please give it now, else press return to proceed.\n" );
print( "icommands location path: " );
chomp( $input = <STDIN> );
if ( $input ) { $ENV{'PATH'} .= ":$input"; }
print "Please, enter the password of the iRODS user used for the test: ";
chomp( $input = <STDIN> );
if ( ! $input ) {
	print( "\nYou should give valid pwd.\n\n");
	exit;
} else {
	print( "\n" );
}



#-- Test the icommands and eventually compared the result to what is expected.

runCmd( "iinit $input" );

# prep and cleanup
runCmd( "iadmin mkuser devtestuser rodsuser","","","","iadmin rmuser devtestuser" );
#runCmd( "iadmin mkresc testResc 'unix file system' cache localhost /tmp/$unixuser/testResc I_AM_A_CONTEXT_STRING", "", "", "", "iadmin rmresc testResc" );
runCmd( "iadmin mkresc testResc 'unix file system' cache localhost I_AM_A_CONTEXT_STRING /tmp/$unixuser/testResc", "", "", "", "iadmin rmresc testResc" );
runCmd( "iadmin atrg testgroup testResc", "", "", "", "iadmin rfrg testgroup testResc");
runCmd( "imkdir sub1", "", "", "", "irm -rf sub1" );
runCmd( "imkdir forphymv", "", "", "", "irm -rf forphymv" );
runCmd( "imkdir ruletest", "", "", "", "irm -rf ruletest" );
runCmd( "imkdir test", "", "", "", "irm -rf test" );
runCmd( "imkdir test/phypathreg" );
runCmd( "imkdir ruletest/subforrmcoll" );
runCmd( "iput $progname test/foo1");
runCmd( "icp test/foo1 sub1/foo1");
runCmd( "icp test/foo1 sub1/foo2");
runCmd( "icp test/foo1 sub1/foo3");
runCmd( "icp test/foo1 forphymv/phymvfile");<commit_msg>[#955] last parameter (context string) in the proper order in testallrules.pl<commit_after>#!/usr/bin/perl -w
#
# script to test the basic functionnalities of icommands.
# icommands location has to be put in the PATH env variable or their PATH will be asked
# at the beginning of the execution of this script.
#
# usage: ./testiCommands.pl
# If an argument is given, the debug mode is activated
#
# Copyright (c), CCIN2P3
# For more information please refer to files in the COPYRIGHT directory.

use strict;
use Cwd;
use Sys::Hostname;
use File::stat;

#-- Initialization

my $debug;
my $entry;
my @failureList;
my $i;
my $input;
my $irodsdefresource;
my $irodshost;
my $irodshome;
my $irodszone;
my $line;
my @list;
my $misc;
my $nfailure;
my $nsuccess;
my $rc;
my @returnref;
my @successlist;
my @summarylist;
my @tmp_tab;
my $username;
my @words;

my $unixuser     = `whoami`;
chomp $unixuser;
my $dir_w        = cwd();
my $myssize;
my $host         = hostname();
if ( $host =~ '.' ) {
	@words = split( /\./, $host );
	$host  = $words[0];
}
my $irodsfile;
my $irodsEnvFile = $ENV{'irodsEnvFile'};
if ($irodsEnvFile) {
    $irodsfile = $irodsEnvFile;
} else {
    $irodsfile    = "$ENV{HOME}/.irods/.irodsEnv";
}
my $ntests       = 0;
my $progname     = $0;

my $outputfile   = "testallrules_" . $host . ".log";

#-- Find current working directory and make consistency path

$outputfile   = $dir_w . '/' . $outputfile;

if ( $progname !~ '/' ) {
	$progname = $dir_w . '/' . $progname;
} else {
	if ( substr( $progname, 0, 2 ) eq './' ) {
		@words    = split( /\//, $progname );
		$i        = $#words;
		$progname = $dir_w . '/' . $words[$i];
	}
	if ( substr( $progname, 0, 1 ) ne '/' ) {
		$progname = $dir_w . '/' . $progname;
	}
}

#-- Take debug level

$debug = shift;
if ( ! $debug ) {
	$debug = 0;
} else {
	$debug = 1;
}

#-- Print debug

if ( $debug ) {
	print( "\n" );
	print( "MAIN: irodsfile        = $irodsfile\n" );
	print( "MAIN: cwd              = $dir_w\n" );
	print( "MAIN: outputfile       = $outputfile\n" );
	print( "MAIN: progname         = $progname\n" );
	print( "\n" );
}

#-- Dump content of $irodsfile to @list

@list = dumpFileContent( $irodsfile );

#-- Loop on content of @list
# The below parsing works in the current environment 
# but there are two shortcomings:
#   1) single quotes are removed, but if there were to be embedded ones,
#      they would be removed too.
#   2) if the name and value are separated by =, the line will not split right.
foreach $line ( @list ) {
 	chomp( $line );
	if ( ! $line ) { next; }
 	if ( $line =~ /irodsUserName/ ) {
		( $misc, $username ) = split( / /, $line );
		$username =~ s/\'//g; #remove all ' chars, if any
		next;
	}
	if ( $line =~ /irodsHome/ ) {
		( $misc, $irodshome ) = split( / /, $line );
		$irodshome =~ s/\'//g; #remove all ' chars, if any
		next;
	}
	if ( $line =~ /irodsZone/ ) {
		( $misc, $irodszone ) = split( / /, $line );
		$irodszone =~ s/\'//g; #remove all ' chars, if any
		next;
	}
	if ( $line =~ /irodsHost/ ) {
		( $misc, $irodshost ) = split( / /, $line );
		$irodshost =~ s/\'//g; #remove all ' chars, if any
		next;
	}
	if ( $line =~ /irodsDefResource/ ) {
		( $misc, $irodsdefresource ) = split( / /, $line );
		$irodsdefresource =~ s/\'//g; #remove all ' chars, if any
	}
}

#-- Print debug

if ( $debug ) {
	print( "MAIN: username         = $username\n" );
	print( "MAIN: irodshome        = $irodshome\n" );
	print( "MAIN: irodszone        = $irodszone\n" );
	print( "MAIN: irodshost        = $irodshost\n" );
	print( "MAIN: irodsdefresource = $irodsdefresource\n" );
}

#-- Environment setup and print to stdout

print( "\nThe results of the test will be written in the file: $outputfile\n\n" );
print( "Warning: you need to be a rodsadmin in order to pass successfully all the tests," );
print( " as some admin commands are being tested." );
print( " If icommands location has not been set into the PATH env variable," );
print( " please give it now, else press return to proceed.\n" );
print( "icommands location path: " );
chomp( $input = <STDIN> );
if ( $input ) { $ENV{'PATH'} .= ":$input"; }
print "Please, enter the password of the iRODS user used for the test: ";
chomp( $input = <STDIN> );
if ( ! $input ) {
	print( "\nYou should give valid pwd.\n\n");
	exit;
} else {
	print( "\n" );
}



#-- Test the icommands and eventually compared the result to what is expected.

runCmd( "iinit $input" );

# prep and cleanup
runCmd( "iadmin mkuser devtestuser rodsuser","","","","iadmin rmuser devtestuser" );
runCmd( "iadmin mkresc testResc 'unix file system' cache localhost /tmp/$unixuser/testResc I_AM_A_CONTEXT_STRING", "", "", "", "iadmin rmresc testResc" );
runCmd( "iadmin atrg testgroup testResc", "", "", "", "iadmin rfrg testgroup testResc");
runCmd( "imkdir sub1", "", "", "", "irm -rf sub1" );
runCmd( "imkdir forphymv", "", "", "", "irm -rf forphymv" );
runCmd( "imkdir ruletest", "", "", "", "irm -rf ruletest" );
runCmd( "imkdir test", "", "", "", "irm -rf test" );
runCmd( "imkdir test/phypathreg" );
runCmd( "imkdir ruletest/subforrmcoll" );
runCmd( "iput $progname test/foo1");
runCmd( "icp test/foo1 sub1/foo1");
runCmd( "icp test/foo1 sub1/foo2");
runCmd( "icp test/foo1 sub1/foo3");
runCmd( "icp test/foo1 forphymv/phymvfile");
{'fraction_non_alphanumeric': 0.17647058823529413, 'fraction_numerical': 0.005184766214177979, 'mean_word_length': 3.255515443241075, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6977028', 'n_tokens_mistral': 4143, 'n_tokens_neox': 4019, 'n_words': 1225}