openenvutils/commandshell/shell/test/scripts/sanity_auto.sh
changeset 0 2e3d3ce01487
child 1 0fdb7f6b0309
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of the License "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 #
       
    15 
       
    16 #!/home/guest/vinodp/local/bin/zsh
       
    17 ###################################
       
    18 # Test cases for internal commands#
       
    19 ###################################
       
    20 
       
    21 #Inititalise counters for Total tests, passes, fails.
       
    22 preamble()
       
    23 {
       
    24 if [ ! -d chdirtest ] 
       
    25 then
       
    26 	mkdir chdirtest
       
    27 fi
       
    28 if [ ! -d cdtest ]
       
    29 then
       
    30 	mkdir cdtest
       
    31 fi
       
    32 if [ ! -d pushdtest ]
       
    33 then
       
    34     mkdir pushdtest
       
    35 fi
       
    36 if [ ! -d popdtest ]
       
    37 then
       
    38     mkdir popdtest
       
    39 fi
       
    40 if [ ! -d dirstest ]
       
    41 then
       
    42     mkdir dirstest
       
    43 fi
       
    44 }
       
    45 
       
    46 init()
       
    47 {
       
    48 let totalno=0;
       
    49 let passno=0;
       
    50 let failno=0;
       
    51 }
       
    52 
       
    53 #Start test cases
       
    54 #pwd command print the absolute pathname of the current working directory
       
    55 test_pwd1()
       
    56 {
       
    57 let totalno=totalno+1
       
    58 echo "Test $totalno: pwd with no argument"
       
    59 cwd=`pwd`
       
    60 ret=$?
       
    61 if [ $ret = 0 ]
       
    62 	then
       
    63 	if [ $PWD = $cwd ]
       
    64 	then
       
    65 		echo "PASS"
       
    66 		let passno=passno+1
       
    67 	else
       
    68 		echo "FAIL: Expected $PWD, returned $cwd"
       
    69 		let failno=failno+1
       
    70 	fi
       
    71 else
       
    72 	echo "FAIL: Expected return value 0, but  returned $ret"
       
    73 	let failno=failno+1
       
    74 fi
       
    75 }
       
    76 
       
    77 # echo command Write each arg on the standard output, with a space separating each one
       
    78 test_echo1()
       
    79 {
       
    80 let totalno=totalno+1
       
    81 echo "Test $totalno: echo with a string as argument"
       
    82 echostr=`echo "This is a test string"`
       
    83 ret=$?
       
    84 if [ $ret = 0 ]
       
    85 then
       
    86 	if [ $echostr = "This is a test string" ]
       
    87 	then
       
    88 		echo "PASS"
       
    89 		let passno=passno+1 
       
    90 	else
       
    91 		echo "FAIL: Expected \"This is a test string\", returned \"$echostr\""
       
    92 		let failno=failno+1
       
    93 	fi
       
    94 else
       
    95 	echo "FAIL: Expected return value 0, but  returned $ret"
       
    96 	let failno=failno+1
       
    97 fi
       
    98 }
       
    99 
       
   100 # With no flags the arguments are printed on the standard output as described by echo
       
   101 test_print1()
       
   102 {
       
   103 let totalno=totalno+1
       
   104 echo "Test $totalno: print with a string and a variable as argument"
       
   105 let var=1+2
       
   106 printstr=`print "This is a value of a variable: $var"`
       
   107 ret=$?
       
   108 if [ $ret = 0 ]
       
   109 then
       
   110 	 if [ $printstr = "This is a value of a variable: 3" ]
       
   111 	 then
       
   112 		  echo "PASS"
       
   113 		  let passno=passno+1
       
   114 	 else
       
   115 		  echo "FAIL: Expected \"This is a value of a variable: 3\", returned \"$printstr\""
       
   116 		  let failno=failno+1
       
   117 	 fi
       
   118 else
       
   119 	 echo "FAIL: Expected return value 0, but  returned $ret"
       
   120 	 let failno=failno+1
       
   121 fi
       
   122 }
       
   123 
       
   124 
       
   125 # Print the arguments according to the format specification. Formatting rules are the same as used in C
       
   126 test_printf1()
       
   127 {
       
   128 let totalno=totalno+1
       
   129 echo "Test $totalno: printf with a string and a variable as argument"
       
   130 let var=1+2
       
   131 printfstr=`printf "This is a value of a variable: $var"`
       
   132 ret=$?
       
   133 if [ $ret = 0 ]
       
   134 then
       
   135 	 if [ $printfstr = "This is a value of a variable: 3" ]
       
   136 	 then
       
   137 		  echo "PASS"
       
   138 		  let passno=passno+1
       
   139 	 else
       
   140 		  echo "FAIL: Expected \"This is a value of a variable: 3\", returned \"$printfstr\""
       
   141 		  let failno=failno+1
       
   142 	 fi
       
   143 else
       
   144 	 echo "FAIL: Expected return value 0, but  returned $ret"
       
   145 	 let failno=failno+1
       
   146 fi
       
   147 }
       
   148 
       
   149 # Read one line and break it into fields using the characters 
       
   150 test_read1()
       
   151 {
       
   152 let totalno=totalno+1
       
   153 echo "Test $totalno: read a value into the argument"
       
   154 echo Hello > readtest.txt
       
   155 read readvar < readtest.txt
       
   156 ret=$?
       
   157 if [ $ret = 0 ]
       
   158 then
       
   159 	 if [ $readvar = "Hello" ]
       
   160 	 then
       
   161 		  echo "PASS"
       
   162 		  let passno=passno+1
       
   163 	 else
       
   164 		  echo "FAIL: Expected \"Hello\", read \"$readvar\""
       
   165 		  let failno=failno+1
       
   166 	 fi
       
   167 else
       
   168 	 echo "FAIL: Expected return value 0, but  returned $ret"
       
   169 	 let failno=failno+1
       
   170 fi
       
   171 }
       
   172 
       
   173 
       
   174 # change the current directory to arg
       
   175 test_chdir1()
       
   176 {
       
   177 let totalno=totalno+1
       
   178 echo "Test $totalno: chdir with one argument"
       
   179 if [ -d chdirtest ] 
       
   180 then
       
   181 	 oldcwd=`pwd`
       
   182 	 chdir chdirtest
       
   183 	 ret=$?
       
   184 	 if [ $ret = 0 ]
       
   185 	 then
       
   186 		  if [ $PWD = $oldcwd\chdirtest ]
       
   187 		  then
       
   188 			   echo "PASS"
       
   189 			   let passno=passno+1
       
   190 		  else
       
   191 			   echo "FAIL: Expected \"$PWD\", returned \"$oldcwd\chdirtest\""
       
   192 			   let failno=failno+1
       
   193 			   cd ..
       
   194 			   return
       
   195 		  fi
       
   196 	 else
       
   197 		  echo "FAIL: Expected return value 0, but  returned $ret"
       
   198 		  let failno=failno+1
       
   199 		  cd..
       
   200 	      return
       
   201 	 fi
       
   202 	 chdir ..
       
   203 else
       
   204 	 echo "FAIL:chdirtest dir does not exist"
       
   205 	 let failno=failno+1
       
   206 fi
       
   207 }
       
   208 
       
   209 # change the current directory to arg
       
   210 test_cd1()
       
   211 {
       
   212 let totalno=totalno+1
       
   213 echo "Test $totalno: cd with one argument"
       
   214 if [ -d cdtest ]
       
   215 then
       
   216 	 oldcwd=`pwd`
       
   217 	 cd cdtest
       
   218 	 ret=$?
       
   219 	 if [ $ret = 0 ]
       
   220 	 then
       
   221 		  if [ $PWD = $oldcwd\cdtest ]
       
   222 		  then
       
   223 			   echo "PASS"
       
   224 			   let passno=passno+1
       
   225 		  else
       
   226 			   echo "FAIL: Expected \"$PWD\", returned \"$oldcwd\\cdtest\""
       
   227 			   let failno=failno+1
       
   228 		  fi
       
   229 	 else
       
   230 		  echo "FAIL: Expected return value 0, but  returned $ret"
       
   231 		  let failno=failno+1
       
   232 	 fi
       
   233 	 cd ..
       
   234 else
       
   235 	 echo "FAIL:cdtest dir missing"
       
   236 	 let failno=failno+1
       
   237 fi
       
   238 }
       
   239 
       
   240 
       
   241 # Change the current directory, and push the old current directory onto the directory stack
       
   242 test_pushd1()
       
   243 {
       
   244 let totalno=totalno+1
       
   245 echo "Test $totalno: pushd with directory name as argument"
       
   246 if [ -d pushdtest ]
       
   247 then
       
   248 	 oldcwd=`pwd`
       
   249 	 pushd pushdtest
       
   250 	 ret=$?
       
   251 	 if [ $ret = 0 ]
       
   252 	 then
       
   253 		  if [ $PWD = ${oldcwd}\pushdtest ]
       
   254 		  then
       
   255 			   echo "PASS"
       
   256 			   let passno=passno+1
       
   257 		  else
       
   258 			   echo "FAIL: Expected \"$PWD\", returned \"${oldcwd}\pushdtest\""
       
   259 			   let failno=failno+1
       
   260 		  fi
       
   261 	 else
       
   262 		  echo "FAIL: Expected return value 0, but  returned $ret"
       
   263 		  let failno=failno+1
       
   264  	fi
       
   265 	popd
       
   266 else
       
   267 	 echo  "FAIL: Dir pushdtest does not exist."
       
   268 	 let failno=failno+1
       
   269 fi
       
   270 }
       
   271 
       
   272 
       
   273 
       
   274 # Remove an entry from the directory stack, and perform a cd to the new top directory
       
   275 test_popd1()
       
   276 {
       
   277 let totalno=totalno+1
       
   278 echo "Test $totalno: popd with no argument"
       
   279 if [ -d popdtest ]
       
   280 then
       
   281  	oldcwd=`pwd`
       
   282 	pushd popdtest
       
   283  	popd
       
   284 	if [ $ret = 0 ]
       
   285 	then 
       
   286 		  if [ $PWD = $oldcwd ]
       
   287 		  then
       
   288 			   echo "PASS"
       
   289 			   let passno=passno+1  
       
   290 		  else
       
   291 			   echo "FAIL: popd failed: Expected \"$oldcwd\", returned  \"$PWD\""
       
   292                let failno=failno+1
       
   293   		  fi
       
   294 	else
       
   295   		echo "FAIL: Popd failed: Expected return value 0, but  returned $ret"
       
   296 	  	let failno=failno+1
       
   297 	fi
       
   298 else
       
   299  	echo "FAIL: dir popdtest doenot exist."
       
   300  	let failno=failno+1
       
   301 fi
       
   302 }
       
   303 
       
   304 
       
   305 # With no arguments, print the contents of the directory stack
       
   306 test_dirs1()
       
   307 {
       
   308 let totalno=totalno+1
       
   309 echo "Test $totalno: dirs with -l option set"
       
   310 if [ -d dirstest ]
       
   311 then
       
   312 	oldcwd=`pwd`
       
   313 	pushd dirstest
       
   314 	ret=$?
       
   315 	if [ $ret = 0 ]
       
   316 	then
       
   317 		dirsarray=(`dirs -l`)
       
   318 		ret=$?
       
   319         if [ $ret != 0 ]
       
   320 		then
       
   321 			echo "FAIL: dirs gave nonzero return value: $ret"
       
   322 			let failno=failno+1
       
   323 			popd
       
   324 			return		
       
   325 		else
       
   326 			len=${#dirsarray[*]} #Number of elements in stack
       
   327 			if [ $len != 2 ]
       
   328 			then 
       
   329 				echo "FAIL: dirs failed: Expected 2, but is ${len}"
       
   330 				let failno=failno+1
       
   331 				popd
       
   332 				return
       
   333 			else
       
   334 				if [ ${dirsarray[1]} != ${oldcwd}\dirstest ] || [ ${dirsarray[2]} != ${oldcwd} ]   
       
   335 				then
       
   336 					echo "FAIL: dirs failed: Expected \"${oldcwd}\dirstest\" as the first string, but is \"${dirsarray[1]}\" or expected \"${oldcwd}\" as the second string, but is \"${dirsarray[2]}\""
       
   337 					let failno=failno+1
       
   338 					popd
       
   339 					return
       
   340   				fi
       
   341 			fi
       
   342 		fi
       
   343 	else
       
   344 		echo "FAIL: Pushd failed: Expected return value 0, but  returned $ret"
       
   345 		let failno=failno+1
       
   346 	fi
       
   347  	popd
       
   348 	dirsstr=`dirs -l`
       
   349 	dirsarray=($dirsstr)
       
   350 	if [ $ret = 0 ]
       
   351 	then
       
   352 		if [ ${dirsarray[1]} = $oldcwd ]
       
   353 		then
       
   354  			echo "PASS"
       
   355 			let passno=passno+1
       
   356 		else
       
   357 			echo "FAIL: dirs failed: Expected \"$oldcwd\", returned  \"${dirsarray[1]}\""
       
   358 			let failno=failno+1
       
   359 		fi
       
   360 	else
       
   361 		echo "FAIL: Popd failed: Expected return value 0, but  returned $ret"
       
   362 		let failno=failno+1
       
   363 	fi
       
   364 	dirstr=`dirs`
       
   365 else
       
   366 	echo "FAIL: Dir dirstest does not exist"
       
   367 	let failno=failno+1
       
   368 fi
       
   369 }
       
   370 
       
   371 
       
   372 # For each name with a corresponding value, define an alias with that value.
       
   373 test_alias1()
       
   374 {
       
   375 let totalno=totalno+1
       
   376 echo "Test $totalno: alias with a variable name and a command as argument"
       
   377 alias workdir="pwd"
       
   378 ret=$?
       
   379 if [ $ret = 0 ]
       
   380 then
       
   381 	 if [ `pwd` = `workdir` ]
       
   382 	 then
       
   383 		  echo "PASS"
       
   384 		  let passno=passno+1
       
   385 	 else
       
   386 		  echo "FAIL: Expected \"`pwd`\", returned \"`workdir`\""
       
   387 		  let failno=failno+1
       
   388 	 fi
       
   389 	 unalias workdir
       
   390 else
       
   391 	 echo "FAIL: Expected return value 0, but  returned $ret"
       
   392 	 let failno=failno+1
       
   393 fi
       
   394 }
       
   395 
       
   396 
       
   397 # causes unhash to remove regular or global aliases
       
   398 test_unalias1()
       
   399 {
       
   400 let totalno=totalno+1
       
   401 echo "Test $totalno: unalias with an existing alias name as argument"
       
   402 alias workdir="pwd"
       
   403 unalias workdir
       
   404 ret=$?
       
   405 if [ $ret = 0 ]
       
   406 then
       
   407 	workdir
       
   408     ret=$?
       
   409 	if [ $ret != 127 ]
       
   410 	then
       
   411 		echo "FAIL: Expected cmd not found(127), returned $ret"
       
   412 		let failno=failno+1
       
   413 	else
       
   414 		echo "PASS"
       
   415 		let passno=passno+1
       
   416 	fi
       
   417 else
       
   418 	 echo "FAIL: Expected return value 0, but  returned $ret"
       
   419 	 let failno=failno+1
       
   420 fi
       
   421 }
       
   422 
       
   423 
       
   424 # set positional parameters
       
   425 # @internal test function
       
   426 util_set1()
       
   427 {
       
   428 arg1=$1;arg2=$2;arg3=$3
       
   429 old=(`echo $@`)
       
   430 set a b c # Values directly to positional parameters
       
   431 if [ $1 = a ] && [ $2 = b ] && [ $3 = c ]
       
   432 then
       
   433 	 ret=0
       
   434 else
       
   435 	 ret=1
       
   436 	 return $ret
       
   437 fi
       
   438 echo "First set returned $ret"
       
   439 set $old # Value from array to possitional parameters
       
   440 if [ $1 = $arg1 ] && [ $2 = $arg2 ] && [ $3 = $arg3 ]
       
   441 then
       
   442 	 ret=0
       
   443 else
       
   444 	 ret=1
       
   445 fi
       
   446 echo "second set returned $ret"
       
   447 return $ret
       
   448 }
       
   449 
       
   450 # Set the options for the shell and/or set the positional parameters, or declare and set an array
       
   451 test_set1()
       
   452 {
       
   453 let totalno=totalno+1
       
   454 echo "Test $totalno: set command to set positional parameters"
       
   455 util_set1 x y z
       
   456 ret=$?
       
   457 if [ $ret = 0 ]
       
   458 then
       
   459 	echo "PASS"
       
   460 	let passno=passno+1
       
   461 else
       
   462 	echo "FAIL: Expected 0, returned $ret"
       
   463 	let failno=failno+1
       
   464 fi
       
   465 }
       
   466 
       
   467 
       
   468 # Each named parameter is unset
       
   469 test_unset1()
       
   470 {
       
   471 let totalno=totalno+1
       
   472 echo "Test $totalno: unset command to unset array name"
       
   473 unsetarray=(1 2 3)
       
   474 unset unsetarray
       
   475 ret=$?
       
   476 if [ $ret = 0 ]
       
   477 then
       
   478 	if [ ${unsetarray[1]} ] || [ ${unsetarray[2]} ] || [ ${unsetarray[3]} ]
       
   479 	then
       
   480 	   	echo "FAIL: Expected empty strings as array elements, but were $unsetarray[1], $unsetarray[2], $unsetarray[3]"
       
   481        	let failno=failno+1
       
   482 	else
       
   483 		echo "PASS"
       
   484 		let passno=passno+1
       
   485 	fi
       
   486 else
       
   487 	echo "FAIL: Expected return value 0, returned $ret"
       
   488 	let failno=failno+1
       
   489 fi
       
   490 }
       
   491 
       
   492 # For each name, indicate how it would be interpreted if used as a command name.
       
   493 test_which1()
       
   494 {
       
   495 let totalno=totalno+1
       
   496 echo "Test $totalno: which with internal command name as argument"
       
   497 which pwd
       
   498 ret=$?
       
   499 if [ $ret = 0 ]
       
   500 then
       
   501 	echo "PASS"
       
   502 	let passno=passno+1
       
   503 else
       
   504 	echo "FAIL: Expected return value 0, returned $ret"
       
   505     let failno=failno+1
       
   506 fi
       
   507 }
       
   508 
       
   509 
       
   510 # Read the arguments as input to the shell and execute the resulting command in the current shell process
       
   511 test_eval1()
       
   512 {
       
   513 let totalno=totalno+1
       
   514 echo "Test $totalno: eval to run a command"
       
   515 evalvar=pwd
       
   516 outputvar=`eval $evalvar`
       
   517 ret=$?
       
   518 if [ $ret = 0 ]
       
   519 then
       
   520 	if [ $PWD = $outputvar ]
       
   521     then
       
   522 		echo "PASS"
       
   523     	let passno=passno+1
       
   524 	else
       
   525 		echo "FAIL: Expected $PWD, returned $outputvar"
       
   526     	let failno=failno+1
       
   527 	fi
       
   528 else
       
   529     echo "FAIL: Expected return value 0, returned $ret"
       
   530     let failno=failno+1
       
   531 fi
       
   532 }
       
   533 
       
   534 
       
   535 # Redirect the output of the first command to the file
       
   536 test_redirectionop1()
       
   537 {
       
   538 let totalno=totalno+1
       
   539 echo "Test $totalno: > operator to redirect the output of a command to a  file"
       
   540 pwd > redirectedfile
       
   541 ret=$?
       
   542 if [ $ret = 0 ]
       
   543 then
       
   544 	#Read in raw mode (-r) to allow reading '\'
       
   545 	read -r redirectedvar < redirectedfile
       
   546     if [ $PWD = $redirectedvar ]
       
   547     then
       
   548         echo "PASS"
       
   549         let passno=passno+1
       
   550     else
       
   551         echo "FAIL: Expected \"$PWD\", returned \"$redirectedvar\""
       
   552         let failno=failno+1
       
   553     fi
       
   554 else
       
   555     echo "FAIL: Expected return value 0, returned $ret"
       
   556     let failno=failno+1
       
   557 fi
       
   558 }
       
   559 
       
   560 
       
   561 
       
   562 # Convert the result to lower case whenever the parameter is expanded.
       
   563 test_typeset1()
       
   564 {
       
   565 let totalno=totalno+1
       
   566 echo "Test $totalno: typeset to set a variable to have always value in lower case"
       
   567 typeset -l var=VAL
       
   568 ret=$?
       
   569 if [ $ret = 0 ]
       
   570 then
       
   571     if [ $var = val ]
       
   572     then
       
   573         echo "PASS"
       
   574         let passno=passno+1
       
   575     else
       
   576         echo "FAIL: Expected \"val\", returned \"$var\""
       
   577         let failno=failno+1
       
   578     fi
       
   579 else
       
   580     echo "FAIL: Expected return value 0, returned $ret"
       
   581     let failno=failno+1
       
   582 fi
       
   583 }
       
   584 
       
   585 
       
   586 
       
   587 # For each name, indicate how it would be interpreted if used as a command name. 
       
   588 test_whence1()
       
   589 {
       
   590 let totalno=totalno+1
       
   591 echo "Test $totalno: whence to display the path of a bad command"
       
   592 res=`whence tweak`
       
   593 ret=$?
       
   594 if [ $ret = 1 ] && [ $res =  ]
       
   595 then
       
   596     echo "PASS"
       
   597     let passno=passno+1
       
   598 else
       
   599     echo "FAIL: Expected 1 and returned $ret or expected empty string and returned $res"
       
   600     let failno=failno+1
       
   601 fi
       
   602 }
       
   603 
       
   604 
       
   605 # not supported, to be removed
       
   606 test_hash1()
       
   607 {
       
   608 let totalno=totalno+1
       
   609 echo "Test $totalno: hash to store the path of a command in hash table"
       
   610 hash pwd=pwd
       
   611 ret=$?
       
   612 if [ $ret != 0 ]
       
   613 then
       
   614   	echo "FAIL: Expected 0, but returned $ret"
       
   615 	let failno=failno+1
       
   616 	return
       
   617 fi
       
   618 res=`hash -v pwd`
       
   619 ret=$?
       
   620 if [ $ret = 0 ] && [ $res = "pwd=pwd" ]
       
   621 then
       
   622     echo "PASS"
       
   623     let passno=passno+1
       
   624 else
       
   625     echo "FAIL: Expected 0 and returned $ret or expected \"pwd=pwd\" string and returned $res"
       
   626     let failno=failno+1
       
   627 fi
       
   628 }
       
   629 
       
   630 
       
   631 util_autoloaded_function()
       
   632 {
       
   633 echo hello
       
   634 }
       
   635 
       
   636 # autoload a function into cache so that can be loaded next time fast
       
   637 test_autoload1()
       
   638 {
       
   639 let totalno=totalno+1
       
   640 echo "Test $totalno: autoload to load a function"
       
   641 autoload util_autoloaded_function 
       
   642 ret=$?
       
   643 if [ $ret = 0 ]
       
   644 then
       
   645 	res=`util_autoloaded_function`
       
   646 	if [ $res = hello ]
       
   647 	then
       
   648    		echo "PASS"
       
   649 	   	let passno=passno+1
       
   650    		unfunction util_autoloaded_function
       
   651 	else
       
   652 		echo "FAIL: Expected hello, returned $res"
       
   653     	let failno=failno+1
       
   654 	fi
       
   655 else
       
   656    	echo "FAIL: Expected 0, returned $ret"
       
   657    	let failno=failno+1
       
   658 fi
       
   659 }
       
   660 
       
   661 
       
   662 
       
   663 
       
   664 # Execute the bult-in command given as argument
       
   665 test_builtin1()
       
   666 {
       
   667 let totalno=totalno+1
       
   668 echo "Test $totalno: builtin with pwd as argument"
       
   669 cwd=`builtin pwd`
       
   670 ret=$?
       
   671 unhash -f pwd
       
   672 if [ $ret = 0 ]
       
   673 then
       
   674 	 if [ $PWD = $cwd ]
       
   675 	 then
       
   676 		   echo "PASS"
       
   677 		   let passno=passno+1
       
   678 	 else
       
   679 		   echo "FAIL: Expected $PWD, returned $cwd"
       
   680 		   let failno=failno+1
       
   681 	 fi
       
   682 else
       
   683 	 echo "FAIL: Expected return value 0, but  returned $ret"
       
   684 	 let failno=failno+1
       
   685 fi
       
   686 }
       
   687 
       
   688 
       
   689 # Execute the simple command preference being to external command
       
   690 test_command1()
       
   691 {
       
   692 let totalno=totalno+1
       
   693 echo "Test $totalno: command with pwd as argument"
       
   694 cwd=`command pwd`
       
   695 ret=$?
       
   696 if [ $ret = 0 ]
       
   697 then
       
   698 	 if [ $cwd = hello ] # hello is printed to the console by the external command.
       
   699 	 then
       
   700 		   echo "PASS"
       
   701 		   let passno=passno+1
       
   702 	 else
       
   703 		   echo "FAIL: Expected $PWD, returned $cwd"
       
   704 		   let failno=failno+1
       
   705 	 fi
       
   706 else
       
   707 	 echo "FAIL: Expected return value 0, but  returned $ret"
       
   708 	 let failno=failno+1
       
   709 fi
       
   710 }
       
   711 
       
   712 # To be removed
       
   713 test_exec1()
       
   714 {
       
   715 let totalno=totalno+1
       
   716 echo "Test $totalno: exec with no argument"
       
   717 exec
       
   718 ret=$?
       
   719 if [ $ret = 127 ]
       
   720 then
       
   721  	  echo "PASS"
       
   722 	  let passno=passno+1
       
   723 else
       
   724 	  echo "FAIL: Expected 127, returned $ret"
       
   725 	  let failno=failno+1
       
   726 fi
       
   727 }
       
   728 
       
   729 # Prevents expanding of alias
       
   730 test_noglob1()
       
   731 {
       
   732 let totalno=totalno+1
       
   733 echo "Test $totalno: noglob to prevent expanding alias"
       
   734 alias foo='echo an alias for foo'
       
   735 noglob foo
       
   736 ret=$?
       
   737 if [ $ret = 127 ]
       
   738 then
       
   739    	echo "PASS"
       
   740    	let passno=passno+1
       
   741 else
       
   742    	echo "FAIL: Expected 127, returned $ret"
       
   743     let failno=failno+1
       
   744 fi
       
   745 }
       
   746 
       
   747 
       
   748 # Open square bracket on command prompt should return 1
       
   749 test_open_sq_bkt()
       
   750 {
       
   751 let totalno=totalno+1
       
   752 echo "Test $totalno: ["
       
   753 [
       
   754 ret=$?
       
   755 if [ $ret = 1 ]
       
   756 then
       
   757    	echo "PASS"
       
   758    	let passno=passno+1
       
   759 else
       
   760     echo "FAIL: Expected 1, returned $ret"
       
   761     let failno=failno+1
       
   762 fi
       
   763 }
       
   764 
       
   765 # A dot(.) on command prompt should return 1
       
   766 test_dot()
       
   767 {
       
   768 let totalno=totalno+1
       
   769 echo "Test $totalno: ."
       
   770 .
       
   771 ret=$?
       
   772 if [ $ret = 1 ]
       
   773 then
       
   774    	echo "PASS"
       
   775    	let passno=passno+1
       
   776 else
       
   777    	echo "FAIL: Expected 1, returned $ret"
       
   778     let failno=failno+1
       
   779 fi
       
   780 }
       
   781 
       
   782 # A colon on a command prompt should return 0
       
   783 test_colon()
       
   784 {
       
   785 let totalno=totalno+1
       
   786 echo "Test $totalno: :"
       
   787 :
       
   788 ret=$?
       
   789 if [ $ret = 0 ]
       
   790 then
       
   791    	echo "PASS"
       
   792    	let passno=passno+1
       
   793 else
       
   794    	echo "FAIL: Expected 0, returned $ret"
       
   795    	let failno=failno+1
       
   796 fi
       
   797 }
       
   798 
       
   799 # No job control support. To be removed
       
   800 test_send_job_to_bg()
       
   801 {
       
   802 let totalno=totalno+1
       
   803 echo "Test $totalno: pwd with argument &"
       
   804 pwd &
       
   805 ret=$?
       
   806 if [ $ret = 0 ]
       
   807 then
       
   808    	echo "PASS"
       
   809    	let passno=passno+1
       
   810 else
       
   811    	echo "FAIL: Expected 0, returned $ret"
       
   812    	let failno=failno+1
       
   813 fi
       
   814 }
       
   815 
       
   816 # No job control. To be removed
       
   817 test_bg1()
       
   818 {
       
   819 let totalno=totalno+1
       
   820 echo "Test $totalno: bg without any argument"
       
   821 bg
       
   822 ret=$?
       
   823 if [ $ret = 127 ]
       
   824 then
       
   825    	echo "PASS"
       
   826    	let passno=passno+1
       
   827 else
       
   828    	echo "FAIL: Expected 0, returned $ret"
       
   829    	let failno=failno+1
       
   830 fi
       
   831 }
       
   832 
       
   833 # Test break command inside awhile loop
       
   834 test_break1()
       
   835 {
       
   836 let totalno=totalno+1
       
   837 echo "Test $totalno: break"
       
   838 let var=1
       
   839 while [ 1 ]
       
   840 do
       
   841 	break
       
   842 	let var=2
       
   843 done
       
   844 ret=$?
       
   845 if [ $ret = 0 ]&&[ $var = 1 ]
       
   846 then
       
   847    	echo "PASS"
       
   848    	let passno=passno+1
       
   849 else
       
   850 	echo "FAIL: Expected return value 0, returned $ret or expected var value 1, returned $var"
       
   851    	let failno=failno+1
       
   852 fi
       
   853 }
       
   854 
       
   855 test_continue1()
       
   856 {
       
   857 let totalno=totalno+1
       
   858 echo "Test $totalno: continue within while loop" 
       
   859 let var=1
       
   860 while [ $var = 1 ]
       
   861 do
       
   862 	if [ $var = 1 ]
       
   863 	then
       
   864 		let var=2			
       
   865 		continue
       
   866 	fi
       
   867     let var=3
       
   868 done
       
   869 if [ $var = 2 ]
       
   870 then
       
   871    	echo "PASS"
       
   872    	let passno=passno+1
       
   873 else
       
   874    	echo "FAIL: Expected value 2, returned $var"
       
   875    	let failno=failno+1
       
   876 fi
       
   877 }
       
   878 
       
   879 test_declare1()
       
   880 {
       
   881 let totalno=totalno+1
       
   882 echo "Test $totalno: declare with -i option"
       
   883 declare -i var=1.23
       
   884 ret=$?
       
   885 if [ $ret = 0 ]
       
   886 then
       
   887    	if [ $var = 1 ]
       
   888    	then
       
   889 		echo "PASS"
       
   890 	   	let passno=passno+1
       
   891 	else
       
   892 		echo "FAIL: Expected 1, returned $var"
       
   893 	   	let failno=failno+1
       
   894 	fi
       
   895 else
       
   896    	echo "FAIL: Expected 0, returned $ret"
       
   897    	let failno=failno+1
       
   898 fi
       
   899 }
       
   900 
       
   901 test_disable1()
       
   902 {
       
   903 let totalno=totalno+1
       
   904 echo "Test $totalno: disable without argument"
       
   905 disable
       
   906 ret=$?
       
   907 if [ $ret = 0 ]
       
   908 then
       
   909    	echo "PASS"
       
   910    	let passno=passno+1
       
   911 else
       
   912    	echo "FAIL: Expected 0, returned $ret"
       
   913    	let failno=failno+1
       
   914 fi
       
   915 }
       
   916 
       
   917 test_disown1()
       
   918 {
       
   919 let totalno=totalno+1
       
   920 echo "Test $totalno: disown without argument"
       
   921 disown
       
   922 ret=$?
       
   923 if [ $ret = 1 ]
       
   924 then
       
   925    	echo "PASS"
       
   926    	let passno=passno+1
       
   927 else
       
   928    	echo "FAIL: Expected 1, returned $ret"
       
   929    	let failno=failno+1
       
   930 fi
       
   931 }
       
   932 
       
   933 test_emulate1()
       
   934 {
       
   935 let totalno=totalno+1
       
   936 echo "Test $totalno: emulate with -L sh argument to set options default to sh emulation mode"
       
   937 emulate -L sh
       
   938 ret=$?
       
   939 if [ $ret = 0 ]
       
   940 then
       
   941 	res=(`setopt`)
       
   942    	if [ $res = banghist ]
       
   943 	then
       
   944 		echo "PASS"
       
   945    		let passno=passno+1
       
   946 	else
       
   947 		echo "FAIL: Expected banghist, returned $res"
       
   948 		let failno=failno+1
       
   949 	fi
       
   950 else
       
   951    	echo "FAIL: Expected 0, returned $ret"
       
   952    	let failno=failno+1
       
   953 fi
       
   954 }
       
   955 
       
   956 test_export1()
       
   957 {
       
   958 let totalno=totalno+1
       
   959 echo "Test $totalno: export with a variable=value as argument"
       
   960 export val=1
       
   961 ret=$?
       
   962 if [ $ret = 0 ]
       
   963 then
       
   964    	if [ $val = 1 ]
       
   965    	then
       
   966    	 	echo "PASS"
       
   967    	 	let passno=passno+1
       
   968    	else
       
   969  		echo "FAIL: Expected 1, returned $val"
       
   970     	let failno=failno+1
       
   971    	fi
       
   972 else
       
   973    	echo "FAIL: Expected 0, returned $ret"
       
   974    	let failno=failno+1
       
   975 fi
       
   976 }
       
   977 
       
   978 test_false1()
       
   979 {
       
   980 let totalno=totalno+1
       
   981 echo "Test $totalno: false with no argument"
       
   982 false
       
   983 ret=$?
       
   984 if [ $ret = 1 ]
       
   985 then
       
   986    	echo "PASS"
       
   987    	let passno=passno+1
       
   988 else
       
   989    	echo "FAIL: Expected 1, returned $ret"
       
   990    	let failno=failno+1
       
   991 fi
       
   992 }
       
   993 
       
   994 test_fc1()
       
   995 {
       
   996 let totalno=totalno+1
       
   997 echo "Test $totalno: fc with -ln -1 argument"
       
   998 fc -ln -1
       
   999 ret=$?
       
  1000 if [ $ret = 0 ]
       
  1001 then
       
  1002     echo "PASS"
       
  1003     let passno=passno+1
       
  1004 else
       
  1005    	echo "FAIL: Expected 0, returned $ret"
       
  1006    	let failno=failno+1
       
  1007 fi
       
  1008 }
       
  1009 
       
  1010 test_fg1()
       
  1011 {
       
  1012 let totalno=totalno+1
       
  1013 echo "Test $totalno: fg with no argument"
       
  1014 fg
       
  1015 ret=$?
       
  1016 if [ $ret = 1 ]
       
  1017 then
       
  1018     echo "PASS"
       
  1019     let passno=passno+1
       
  1020 else
       
  1021    	echo "FAIL: Expected 1, returned $ret"
       
  1022    	let failno=failno+1
       
  1023 fi
       
  1024 }
       
  1025 
       
  1026 test_float1()
       
  1027 {
       
  1028 let totalno=totalno+1
       
  1029 echo "Test $totalno: float with var=integer value argument"
       
  1030 float var=1
       
  1031 ret=$?
       
  1032 if [ $ret = 0 ]
       
  1033 then	
       
  1034 	if [ $var = 1.000000000e+00 ]
       
  1035 	then
       
  1036 		echo "PASS"
       
  1037 	    let passno=passno+1
       
  1038 	else
       
  1039 		echo "FAIL: Expected 1.000000000e+00, returned $var"
       
  1040    		let failno=failno+1
       
  1041 	fi
       
  1042 else
       
  1043    	echo "FAIL: Expected 0, returned $ret"
       
  1044    	let failno=failno+1
       
  1045 fi
       
  1046 }
       
  1047 
       
  1048 
       
  1049 
       
  1050 util_functions()
       
  1051 {
       
  1052 echo hello
       
  1053 }
       
  1054 
       
  1055 test_functions1()
       
  1056 {
       
  1057 let totalno=totalno+1
       
  1058 echo "Test $totalno: functions with one function name as argument"
       
  1059 res=(`functions util_functions`)
       
  1060 ret=$?
       
  1061 if [ $ret = 0 ]
       
  1062 then
       
  1063 	if [ $res[1] = util_functions ] && [ $res[2] = "()" ] 
       
  1064     then
       
  1065 		echo "PASS"
       
  1066     	let passno=passno+1
       
  1067 	else
       
  1068 		echo "FAIL: Expected util_functions definition, but not returned."
       
  1069 		let failno=failno+1
       
  1070 	fi
       
  1071 else
       
  1072    	echo "FAIL: Expected 0, returned $ret"
       
  1073    	let failno=failno+1
       
  1074 fi
       
  1075 }
       
  1076 
       
  1077 # getln read the top value from the buffer stack and put it in the shell parameter name
       
  1078 test_getln1()
       
  1079 {
       
  1080 let totalno=totalno+1
       
  1081 echo "Test $totalno: getln with 2 variable arguments"
       
  1082 pushln first second
       
  1083 getln a b
       
  1084 ret=$?
       
  1085 if [ $ret = 0 ]
       
  1086 then
       
  1087 	if [ $a = first ] && [ $b = second ]
       
  1088 	then
       
  1089     	echo "PASS"
       
  1090     	let passno=passno+1
       
  1091 	else
       
  1092 		echo "FAIL: Expected first and second, returned $a and $b"
       
  1093    		let failno=failno+1
       
  1094 	fi
       
  1095 else
       
  1096    	echo "FAIL: Expected 0, returned $ret"
       
  1097    	let failno=failno+1
       
  1098 fi
       
  1099 }
       
  1100 
       
  1101 # @internal test function
       
  1102 util_getopts()
       
  1103 {
       
  1104 aflag=
       
  1105 bflag=
       
  1106 while getopts ab: name
       
  1107 do
       
  1108     case $name in
       
  1109     a)    aflag=1;;
       
  1110     b)    bflag=1
       
  1111           bval="$OPTARG";;
       
  1112     *)   printf "Usage: %s: [-a] [-b value] args\n" $0
       
  1113           return 2;;
       
  1114     esac
       
  1115 done
       
  1116 if [ ! -z "$aflag" ] && [ ! -z "$bflag" ] && [ $bval = 1 ]
       
  1117 then
       
  1118     shift $(($OPTIND - 1))
       
  1119     if [ $1 = 2 ] && [ $2 = 3 ]
       
  1120 	then
       
  1121 		return 0
       
  1122 	else
       
  1123 		return 1
       
  1124 	fi
       
  1125 else
       
  1126     return 1
       
  1127 fi
       
  1128 }
       
  1129 
       
  1130 # getopts command will parse the arguments and can be used to enforce options
       
  1131 test_getopts1()
       
  1132 {
       
  1133 let totalno=totalno+1
       
  1134 echo "Test $totalno: getopts with arguments to parse options and values instead of positional parameters"
       
  1135 util_getopts -a -b 1 2 3
       
  1136 ret=$?
       
  1137 if [ $ret = 0 ]
       
  1138 then
       
  1139     echo "PASS"
       
  1140     let passno=passno+1
       
  1141 else
       
  1142    	echo "FAIL: Expected 0, returned $ret"
       
  1143    	let failno=failno+1	
       
  1144 fi
       
  1145 }
       
  1146 
       
  1147 test_integer1()
       
  1148 {
       
  1149 let totalno=totalno+1
       
  1150 echo "Test $totalno: integer with var=float value argument"
       
  1151 integer var=1.23
       
  1152 ret=$?
       
  1153 if [ $ret = 0 ]
       
  1154 then	
       
  1155     if [ $var = 1 ]
       
  1156     then	
       
  1157         echo "PASS"
       
  1158         let passno=passno+1
       
  1159     else
       
  1160         echo "FAIL: Expected 1, returned $var"
       
  1161         let failno=failno+1
       
  1162     fi
       
  1163 else
       
  1164    	echo "FAIL: Expected 0, returned $ret"
       
  1165    	let failno=failno+1
       
  1166 fi
       
  1167 }
       
  1168 
       
  1169 test_jobs1()
       
  1170 {
       
  1171 let totalno=totalno+1
       
  1172 echo "Test $totalno: jobs to display current jobs"
       
  1173 jobs
       
  1174 ret=$?
       
  1175 if [ $ret = 127 ]
       
  1176 then
       
  1177    	echo "PASS"
       
  1178    	let passno=passno+1
       
  1179 else
       
  1180    	echo "FAIL: Expected 127, returned $ret"
       
  1181    	let failno=failno+1
       
  1182 fi
       
  1183 }
       
  1184 
       
  1185 # Negative test to check whether it returns 127 or not.
       
  1186 test_kill1()
       
  1187 {
       
  1188 let totalno=totalno+1
       
  1189 echo "Test $totalno: kill -l to display all the signals"
       
  1190 kill 100
       
  1191 ret=$?
       
  1192 if [ $ret = 127 ]
       
  1193 then
       
  1194    	echo "PASS"
       
  1195    	let passno=passno+1
       
  1196 else
       
  1197    	echo "FAIL: Expected 127, returned $ret"
       
  1198    	let failno=failno+1
       
  1199 fi
       
  1200 }
       
  1201 
       
  1202 # @internal test function
       
  1203 util_local1()
       
  1204 {
       
  1205 yy=1
       
  1206 local xx=2
       
  1207 }
       
  1208 
       
  1209 # local variables are accessible only in the block of its definition.
       
  1210 test_local1()
       
  1211 {
       
  1212 let totalno=totalno+1
       
  1213 echo "Test $totalno: local declare variables local to function"
       
  1214 util_local1
       
  1215 if [ -z "$xx" ] && [ ! -z "$yy"  ]
       
  1216 then
       
  1217    	echo "PASS"
       
  1218    	let passno=passno+1
       
  1219 else
       
  1220    	echo "FAIL: Expected 1 and empty string, returned $yy and $xx"
       
  1221    	let failno=failno+1
       
  1222 fi
       
  1223 }
       
  1224 
       
  1225 
       
  1226 test_rehash1()
       
  1227 {
       
  1228 let totalno=totalno+1
       
  1229 echo "Test $totalno: rehash function empty the current hash table"
       
  1230 rehash
       
  1231 res=$?
       
  1232 if [ $res = 127 ]
       
  1233 then
       
  1234     echo "PASS"
       
  1235     let passno=passno+1
       
  1236 else
       
  1237    	echo "FAIL: Expected 127, returned $res"
       
  1238    	let failno=failno+1
       
  1239 fi
       
  1240 }
       
  1241 
       
  1242 # @internal test function
       
  1243 util_shift()
       
  1244 {
       
  1245 arg1=$2
       
  1246 shift
       
  1247 if [ $1 = $arg1 ]
       
  1248 then
       
  1249     return 0
       
  1250 else
       
  1251     return 1
       
  1252 fi
       
  1253 }
       
  1254 
       
  1255 # shift command shifts the positional parameters one position left
       
  1256 test_shift1()
       
  1257 {
       
  1258 let totalno=totalno+1
       
  1259 echo "Test $totalno: shift to shift the positional argument left once"
       
  1260 util_shift 10 20
       
  1261 res=$?
       
  1262 if [ $res = 0 ]
       
  1263 then
       
  1264     echo "PASS"
       
  1265     let passno=passno+1
       
  1266 else
       
  1267    	echo "FAIL: Expected 0, returned $res"
       
  1268    	let failno=failno+1
       
  1269 fi
       
  1270 }
       
  1271 
       
  1272 # source command is used to execute existing script file
       
  1273 test_source1()
       
  1274 {
       
  1275 let totalno=totalno+1
       
  1276 echo "Test $totalno: source to execute existing script file"
       
  1277 if [ -f util_source.sh ]
       
  1278 then
       
  1279 	source util_source.sh
       
  1280 	ret=$?
       
  1281 	if [ $ret = 100 ]
       
  1282 	then
       
  1283 		echo "PASS"
       
  1284     	let passno=passno+1
       
  1285 	else
       
  1286 		echo "FAIL: Expected 100, returned $res"
       
  1287 		let failno=failno+1
       
  1288 	fi
       
  1289 else
       
  1290    	echo "FAIL: util_source.sh does not exist in the current directory"
       
  1291    	let failno=failno+1
       
  1292 fi
       
  1293 }
       
  1294 
       
  1295 test_true1()
       
  1296 {
       
  1297 let totalno=totalno+1
       
  1298 echo "Test $totalno: true with no argument"
       
  1299 true
       
  1300 ret=$?
       
  1301 if [ $ret = 0 ]
       
  1302 then
       
  1303    	echo "PASS"
       
  1304    	let passno=passno+1
       
  1305 else
       
  1306    	echo "FAIL: Expected 0, returned $ret"
       
  1307    	let failno=failno+1
       
  1308 fi
       
  1309 }
       
  1310 
       
  1311 test_ttyctl1()
       
  1312 {
       
  1313 let totalno=totalno+1
       
  1314 echo "Test $totalno: ttyctl with no argument to know the frozen status of tty"
       
  1315 ttyctl
       
  1316 ret=$?
       
  1317 if [ $ret = 127 ]
       
  1318 then	
       
  1319    	echo "PASS"
       
  1320    	let passno=passno+1
       
  1321 else
       
  1322    	echo "FAIL: Expected 127, returned $ret"
       
  1323    	let failno=failno+1
       
  1324 fi
       
  1325 }
       
  1326 
       
  1327 
       
  1328 
       
  1329 test_trap1()
       
  1330 {
       
  1331 let totalno=totalno+1
       
  1332 echo "Test $totalno: trap to print the line number of command last executed"
       
  1333 trap 'print $LINENO' DEBUG
       
  1334 ret=$?
       
  1335 if [ $ret = 0 ]
       
  1336 then
       
  1337    	echo "PASS"
       
  1338    	let passno=passno+1
       
  1339 	trap -
       
  1340 else
       
  1341    	echo "FAIL: Expected 0, returned $ret"
       
  1342    	let failno=failno+1
       
  1343 fi
       
  1344 }
       
  1345 
       
  1346 test_type1()
       
  1347 {
       
  1348 let totalno=totalno+1
       
  1349 echo "Test $totalno: type to display the type of the identifier"
       
  1350 alias test_al=1
       
  1351 res=`type test_al`
       
  1352 ret=$?
       
  1353 if [ $ret = 0 ]
       
  1354 then
       
  1355 	unalias test_al
       
  1356 	if [ $res = "test_al is an alias for 1" ]
       
  1357 	then
       
  1358    		echo "PASS"
       
  1359    		let passno=passno+1	
       
  1360 	else
       
  1361 		echo "FAIL: Expected \"test_al is an alias for 1\", returned $res"
       
  1362    		let failno=failno+1		
       
  1363 	fi
       
  1364 else
       
  1365    	echo "FAIL: Expected 0, returned $ret"
       
  1366    	let failno=failno+1
       
  1367 fi
       
  1368 }
       
  1369 
       
  1370 test_umask1()
       
  1371 {
       
  1372 let totalno=totalno+1
       
  1373 echo "Test $totalno: umask to get the current value of file creation mask"
       
  1374 res=`umask`
       
  1375 ret=$?
       
  1376 if [ $ret = 127 ]
       
  1377 then
       
  1378     echo "PASS"
       
  1379     let passno=passno+1	
       
  1380 else
       
  1381    	echo "FAIL: Expected 0, returned $ret"
       
  1382    	let failno=failno+1
       
  1383 fi
       
  1384 }
       
  1385 
       
  1386 # @internal test function
       
  1387 util_unhash()
       
  1388 {
       
  1389 return
       
  1390 }
       
  1391 
       
  1392 test_unhash1()
       
  1393 {
       
  1394 let totalno=totalno+1
       
  1395 echo "Test $totalno: unhash to remove function from hash table"
       
  1396 util_unhash
       
  1397 ret=$?
       
  1398 if [ $ret = 0 ]
       
  1399 then
       
  1400 	unhash -f util_unhash
       
  1401 	ret=$?
       
  1402 	if [ $ret = 0 ]
       
  1403 	then
       
  1404 		util_unhash
       
  1405 		ret=$?
       
  1406 		if [ $ret = 127 ]
       
  1407 		then
       
  1408 			echo "PASS"
       
  1409    			let passno=passno+1
       
  1410 		else
       
  1411 			echo "FAIL: Expected 127, returned $ret"	
       
  1412 			let failno=failno+1	
       
  1413 		fi
       
  1414 	else
       
  1415 		echo "FAIL: Expected 0, returned $ret"
       
  1416 		let failno=failno+1
       
  1417 	fi
       
  1418 else
       
  1419    	echo "FAIL: Expected 0, returned $ret"
       
  1420    	let failno=failno+1
       
  1421 fi
       
  1422 }
       
  1423 
       
  1424 test_where1()
       
  1425 {
       
  1426 let totalno=totalno+1
       
  1427 echo "Test $totalno: where to display the path of a command"
       
  1428 res=`where unset`
       
  1429 ret=$?
       
  1430 if [ $ret = 0 ]
       
  1431 then
       
  1432 	if [ $res = "unset: shell built-in command" ]
       
  1433 	then
       
  1434    		echo "PASS"
       
  1435 	    let passno=passno+1
       
  1436 	else
       
  1437 		echo "FAIL: Expected \"unset: shell built-in command\", returned $res"
       
  1438    		let failno=failno+1
       
  1439 	fi
       
  1440 else
       
  1441    	echo "FAIL: Expected 0, returned $ret"
       
  1442    	let failno=failno+1
       
  1443 fi
       
  1444 }
       
  1445 
       
  1446 test_zmodload1()
       
  1447 {
       
  1448 let totalno=totalno+1
       
  1449 echo "Test $totalno: zmodload to display the path of loaded modules"
       
  1450 res=(`zmodload`)
       
  1451 ret=$?
       
  1452 if [ $ret = 127 ]
       
  1453 then	
       
  1454     echo "PASS"
       
  1455     let passno=passno+1
       
  1456 else
       
  1457    	echo "FAIL: Expected 127, returned $ret"
       
  1458    	let failno=failno+1
       
  1459 fi
       
  1460 }
       
  1461 
       
  1462 test_cdablevars1()
       
  1463 {
       
  1464 let totalno=totalno+1
       
  1465 echo "Test $totalno: setopt cdablevars to enable cd to variable values=directory name"
       
  1466 setopt cdablevars
       
  1467 ret=$?
       
  1468 if [ $ret = 0 ]
       
  1469 then
       
  1470 	foo=c:\cdtest
       
  1471 	cd foo
       
  1472 	res=`pwd`
       
  1473     if [ $res = "c:\cdtest" ]
       
  1474     then
       
  1475         echo "PASS"
       
  1476         let passno=passno+1
       
  1477 		cd ..
       
  1478     else
       
  1479         echo "FAIL: Expected \"c:\cdtest\", returned $res"
       
  1480         let failno=failno+1
       
  1481     fi
       
  1482 	unsetopt cdablevars
       
  1483 else
       
  1484    	echo "FAIL: Expected 0, returned $ret"
       
  1485    	let failno=failno+1
       
  1486 fi
       
  1487 }
       
  1488 
       
  1489 
       
  1490 # Pipe to redirect the output of one command to input of another
       
  1491 test_pipe1()
       
  1492 {
       
  1493 let totalno=totalno+1
       
  1494 echo "Test $totalno: pipe test to give the output of one command to another"
       
  1495 echo "Hello" | read var
       
  1496 ret=$?
       
  1497 if [ $ret = 0 ]
       
  1498 then
       
  1499 	if [ $var = "Hello" ]
       
  1500 	then
       
  1501    		echo "PASS"
       
  1502 		let passno=passno+1
       
  1503 	else
       
  1504 		echo "FAIL: Expected Hello, returned $var"
       
  1505 		let failno=failno+1
       
  1506 	fi
       
  1507 else
       
  1508    	echo "FAIL: Expected 0, returned $ret"
       
  1509    	let failno=failno+1
       
  1510 fi
       
  1511 }
       
  1512 
       
  1513 
       
  1514 
       
  1515 test_precommand_modifier_hiphen1()
       
  1516 {
       
  1517 let totalno=totalno+1
       
  1518 echo "Test $totalno: Precommand modifier hiphen"
       
  1519 var1=`pwd`
       
  1520 var2=`- pwd`
       
  1521 ret=$?
       
  1522 if [ $ret = 0 ]
       
  1523 then	
       
  1524     if [ $var1 =  $var2 ]
       
  1525     then
       
  1526         echo "PASS"
       
  1527         let passno=passno+1
       
  1528     else
       
  1529         echo "FAIL: Expected $var1, returned $var2"
       
  1530         let failno=failno+1
       
  1531     fi
       
  1532 else
       
  1533    	echo "FAIL: Expected 0, returned $ret"
       
  1534    	let failno=failno+1
       
  1535 fi
       
  1536 }
       
  1537 
       
  1538 # for looping construct to iterate for specified values in the list
       
  1539 test_for1()
       
  1540 {
       
  1541 let totalno=totalno+1
       
  1542 echo "Test $totalno: Test for loop"
       
  1543 let total=0
       
  1544 for i in 1 2 3
       
  1545 do
       
  1546 	let total=total+1
       
  1547 done
       
  1548 if [ $total = 3 ]
       
  1549 then
       
  1550    	echo "PASS"
       
  1551    	let passno=passno+1
       
  1552 else
       
  1553    	echo "FAIL: Expected 3, returned $total"
       
  1554    	let failno=failno+1
       
  1555 fi
       
  1556 }
       
  1557 
       
  1558 
       
  1559 test_until1()
       
  1560 {
       
  1561 let totalno=totalno+1
       
  1562 echo "Test $totalno: Test until loop"
       
  1563 let total=3
       
  1564 until total=1
       
  1565 do
       
  1566     let total=total-1
       
  1567 done
       
  1568 if [ $total = 1 ]
       
  1569 then
       
  1570    	echo "PASS"
       
  1571    	let passno=passno+1
       
  1572 else
       
  1573   	echo "FAIL: Expected 1, returned $total"
       
  1574    	let failno=failno+1
       
  1575 fi
       
  1576 }
       
  1577 
       
  1578 
       
  1579 test_repeat1()
       
  1580 {
       
  1581 let totalno=totalno+1
       
  1582 echo "Test $totalno: Test repeat loop"
       
  1583 let total=0
       
  1584 repeat 10 let total=total+1
       
  1585 if [ $total = 10 ]
       
  1586 then
       
  1587    	echo "PASS"
       
  1588    	let passno=passno+1
       
  1589 else
       
  1590    	echo "FAIL: Expected 1, returned $total"
       
  1591    	let failno=failno+1
       
  1592 fi
       
  1593 }
       
  1594 
       
  1595 test_case1()
       
  1596 {
       
  1597 let totalno=totalno+1
       
  1598 echo "Test $totalno: Test case construct"
       
  1599 char=a
       
  1600 case $char in
       
  1601 	'a')
       
  1602 		echo "PASS"
       
  1603     	let passno=passno+1	
       
  1604 		;;
       
  1605 	*)
       
  1606 		echo "FAIL: Expected a, returned $char"
       
  1607     	let failno=failno+1	
       
  1608 		;;
       
  1609 	esac
       
  1610 }
       
  1611 
       
  1612 
       
  1613 # @internal test function
       
  1614 util_longbadcmd1()
       
  1615 {
       
  1616 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
       
  1617 return $?
       
  1618 }
       
  1619 
       
  1620 test_longbadcmd1()
       
  1621 {
       
  1622 let totalno=totalno+1
       
  1623 echo "Test $totalno: Test case construct"
       
  1624 util_longbadcmd1
       
  1625 res=$?
       
  1626 if [ $res = 127 ]
       
  1627 then
       
  1628    	echo "PASS"
       
  1629    	let passno=passno+1
       
  1630 else
       
  1631    	echo "FAIL: Expected 127, returned $res"
       
  1632    	let failno=failno+1
       
  1633 fi
       
  1634 }
       
  1635 
       
  1636 
       
  1637 report()
       
  1638 {
       
  1639 echo "#############################################################################"
       
  1640 echo "Total tests : $totalno"
       
  1641 echo "Passed      : $passno"
       
  1642 echo "Failed      : $failno"
       
  1643 echo "#############################################################################"
       
  1644 }
       
  1645 
       
  1646 postamble()
       
  1647 {
       
  1648 rm readtest.txt
       
  1649 rmdir chdirtest
       
  1650 rmdir cdtest
       
  1651 rmdir pushdtest
       
  1652 rmdir popdtest
       
  1653 rmdir dirstest
       
  1654 rm redirectedfile
       
  1655 }
       
  1656 
       
  1657 #Function calls
       
  1658 preamble
       
  1659 init
       
  1660 test_pwd1
       
  1661 test_echo1
       
  1662 test_print1
       
  1663 # test_printf1
       
  1664 test_read1
       
  1665 test_chdir1
       
  1666 test_cd1
       
  1667 test_pushd1
       
  1668 test_popd1
       
  1669 test_dirs1
       
  1670 test_alias1
       
  1671 # test_unalias1
       
  1672 test_set1
       
  1673 test_unset1
       
  1674 test_which1
       
  1675 test_eval1
       
  1676 test_redirectionop1
       
  1677 test_typeset1
       
  1678 # test_whence1
       
  1679 #test_hash1
       
  1680 test_autoload1
       
  1681 
       
  1682 # @internal test function - replacement for builtin pwd
       
  1683 pwd()
       
  1684 {
       
  1685 echo hello
       
  1686 }
       
  1687 
       
  1688 test_builtin1
       
  1689 # test_command1
       
  1690 # test_exec1
       
  1691 # test_noglob1
       
  1692 test_open_sq_bkt
       
  1693 test_dot
       
  1694 test_colon
       
  1695 # test_send_job_to_bg
       
  1696 #test_bg1
       
  1697 test_break1
       
  1698 test_continue1
       
  1699 test_declare1
       
  1700 #test_disable1
       
  1701 #test_disown1
       
  1702 test_emulate1
       
  1703 test_export1
       
  1704 test_false1
       
  1705 test_fc1
       
  1706 #test_fg1
       
  1707 test_float1
       
  1708 test_functions1
       
  1709 test_getln1
       
  1710 test_getopts1
       
  1711 test_integer1
       
  1712 #test_jobs1
       
  1713 #test_kill1
       
  1714 test_local1
       
  1715 #test_rehash1
       
  1716 test_shift1
       
  1717 test_source1
       
  1718 test_true1
       
  1719 #test_ttyctl1
       
  1720 #test_trap1
       
  1721 test_type1
       
  1722 #test_umask1
       
  1723 #test_unhash1
       
  1724 test_where1
       
  1725 #test_zmodload1
       
  1726 # test_cdablevars1 # manual test
       
  1727 # test_pipe1
       
  1728 test_precommand_modifier_hiphen1
       
  1729 test_for1
       
  1730 test_until1
       
  1731 test_repeat1
       
  1732 test_case1
       
  1733 # test_longbadcmd1
       
  1734 postamble
       
  1735 report