openenvutils/commandshell/shell/test/scripts/aliastest.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 init()
       
    17     {
       
    18     let totalno=0;
       
    19     let passno=0;
       
    20     let failno=0;
       
    21     }
       
    22 
       
    23 test_alias2()
       
    24 {
       
    25 let totalno=totalno+1
       
    26 echo "Test $totalno: alias with no argument to display set aliases"
       
    27 alias var='somecmd'
       
    28 res=`alias`
       
    29 ret=$?
       
    30 if [ $ret = 0 ]
       
    31 then
       
    32 	if [ -z $res ]
       
    33 	then
       
    34 		echo "FAIL: Expected alias list of nonzero length, but returned zero-length"
       
    35         let failno=failno+1
       
    36 	else
       
    37 		echo "PASS"
       
    38         let passno=passno+1		
       
    39 	fi
       
    40 else
       
    41  	echo "FAIL: Expected return value 0, but  returned $ret"
       
    42  	let failno=failno+1
       
    43 fi
       
    44 }
       
    45 
       
    46 test_alias3()
       
    47 {
       
    48 let totalno=totalno+1
       
    49 echo "Test $totalno: alias with more than alias settings"
       
    50 alias a=z b=y
       
    51 ret=$?
       
    52 if [ $ret = 0 ]
       
    53 then
       
    54   	echo "PASS"
       
    55   	let passno=passno+1
       
    56   	unalias a b
       
    57 else
       
    58  	echo "FAIL: Expected return value 0, but  returned $ret"
       
    59  	let failno=failno+1
       
    60 fi
       
    61 }
       
    62 
       
    63 test_alias4()
       
    64 {
       
    65 let totalno=totalno+1
       
    66 echo "Test $totalno: alias with nonexistant alias"
       
    67 alias notanalias
       
    68 ret=$?
       
    69 if [ $ret = 1 ]
       
    70 then
       
    71   	echo "PASS"
       
    72   	let passno=passno+1
       
    73 else
       
    74  	echo "FAIL: Expected return value 1, but  returned $ret"
       
    75  	let failno=failno+1
       
    76 fi
       
    77 }
       
    78 
       
    79 test_alias5()
       
    80 {
       
    81 let totalno=totalno+1
       
    82 echo "Test $totalno: alias with -g option to test a global alias"
       
    83 alias -g M='P.I.P.S enables Symbian'
       
    84 ret=$?
       
    85 if [ $ret = 0 ]
       
    86 then
       
    87 	print M > a.txt
       
    88 	ret=$?
       
    89 	rm a.txt
       
    90 	if [ $ret = 0 ]
       
    91     then
       
    92         echo "PASS"
       
    93         let passno=passno+1
       
    94     else
       
    95         echo "FAIL: Expected return value 0, but  returned $ret ls failed"
       
    96         let failno=failno+1
       
    97     fi
       
    98 else
       
    99 	echo "FAIL: Expected return value 0, but  returned $ret alias failed"
       
   100  	let failno=failno+1
       
   101 fi
       
   102 }
       
   103 
       
   104 test_alias6()
       
   105 {
       
   106 let totalno=totalno+1
       
   107 echo "Test $totalno: alias with -m and a pattern as argument to get all alias listed with that pattern inside"
       
   108 alias ab=xy
       
   109 res=`alias -m "ab"`
       
   110 ret=$?
       
   111 if [ $ret = 0 ]
       
   112 then
       
   113   	if [ $res = "ab=xy" ]
       
   114   	then
       
   115 	    echo "PASS"
       
   116         let passno=passno+1
       
   117   	else
       
   118         echo "FAIL: Expected ab=xy, but  returned $res"
       
   119         let failno=failno+1
       
   120   	fi
       
   121   	unalias ab
       
   122 else
       
   123  	echo "FAIL: Expected return value 0, but  returned $ret"
       
   124  	let failno=failno+1
       
   125 fi
       
   126 }
       
   127 
       
   128 
       
   129 
       
   130 test_alias7()
       
   131 {
       
   132 let totalno=totalno+1
       
   133 echo "Test $totalno: alias with -s option and a file suffix as an alias and a command as its value, so that something.suffix will be replaced as command something.suffix"
       
   134 alias -s txt=echo
       
   135 ret=$?
       
   136 res=`result.txt`
       
   137 if [ $ret = 0 ]
       
   138 then
       
   139   	if [ $res = "result.txt" ]
       
   140   	then
       
   141         echo "PASS"
       
   142         let passno=passno+1
       
   143   	else
       
   144         echo "FAIL: Expected result.txt, but  returned $res"
       
   145         let failno=failno+1
       
   146   	fi
       
   147   	unalias -s txt 
       
   148 else
       
   149 	echo "FAIL: Expected return value 0, but  returned $ret"
       
   150 	let failno=failno+1
       
   151 fi
       
   152 }
       
   153 
       
   154 test_alias8()
       
   155 {
       
   156 let totalno=totalno+1
       
   157 echo "Test $totalno: alias with -L option to list all aliases except suffix aliases"
       
   158 alias -L
       
   159 ret=$?
       
   160 if [ $ret = 0 ]
       
   161 then
       
   162 	echo "PASS"
       
   163   	let passno=passno+1
       
   164 else
       
   165  	echo "FAIL: Expected return value 0, but  returned $ret"
       
   166  	let failno=failno+1
       
   167 fi
       
   168 }
       
   169 
       
   170 test_alias9()
       
   171 {
       
   172 let totalno=totalno+1
       
   173 echo "Test $totalno: alias with -L option to display a nonalias"
       
   174 alias -L noaliasbythisname
       
   175 ret=$?
       
   176 if [ $ret = 1 ]
       
   177 then
       
   178 	echo "PASS"
       
   179   	let passno=passno+1
       
   180 else
       
   181  	echo "FAIL: Expected return value 1, but  returned $ret"
       
   182  	let failno=failno+1
       
   183 fi
       
   184 }
       
   185 
       
   186 test_alias10()
       
   187 {
       
   188 let totalno=totalno+1
       
   189 echo "Test $totalno: alias with -g option to print global aliases"
       
   190 alias -g globalalias=pwd
       
   191 aliaslist=(`alias -g`)
       
   192 ret=$?
       
   193 if [ $ret = 0 ]
       
   194 then
       
   195 	len=${#aliaslist[*]}
       
   196     let i=0
       
   197     while [ $i -le $len  ]
       
   198     do
       
   199         if [ $aliaslist[$i] = "globalalias=pwd" ]
       
   200         then
       
   201             echo "PASS"
       
   202             let passno=passno+1
       
   203             return
       
   204         fi
       
   205         let i=i+1
       
   206     done
       
   207     echo "FAIL: Expected globalalias=pwd, but not found"
       
   208     let failno=failno+1
       
   209 else
       
   210  	echo "FAIL: Expected return value 0, but  returned $ret"
       
   211  	let failno=failno+1
       
   212 fi
       
   213 }
       
   214 
       
   215 test_alias11()
       
   216 {
       
   217 let totalno=totalno+1
       
   218 echo "Test $totalno: alias with +g option to print global aliases name only - no value"
       
   219 alias -g globalalias=pwd
       
   220 aliaslist=(`alias +g`)
       
   221 ret=$?
       
   222 if [ $ret = 0 ]
       
   223 then
       
   224 	len=${#aliaslist[*]}
       
   225     let i=0
       
   226     while [ $i -le $len  ]
       
   227     do
       
   228         if [ $aliaslist[$i] = "globalalias" ]
       
   229         then
       
   230             echo "PASS"
       
   231             let passno=passno+1
       
   232             return
       
   233         fi
       
   234         let i=i+1
       
   235     done
       
   236     echo "FAIL: globalalias not found"
       
   237     let failno=failno+1	
       
   238 else
       
   239  	echo "FAIL: Expected return value 0, but  returned $ret"
       
   240  	let failno=failno+1
       
   241 fi
       
   242 }
       
   243 
       
   244 
       
   245 test_alias12()
       
   246 {
       
   247 let totalno=totalno+1
       
   248 echo "Test $totalno: alias with -r option to create a regular alias"
       
   249 alias -r regularalias=pwd
       
   250 ret=$?
       
   251 cwd=`regularalias`
       
   252 if [ $ret = 0 ]
       
   253 then
       
   254     if [ $PWD = $cwd ]
       
   255     then
       
   256         echo "PASS"
       
   257         let passno=passno+1
       
   258     else
       
   259         echo "FAIL: Expected $PWD, but  returned $cwd"
       
   260         let failno=failno+1
       
   261     fi
       
   262 	unalias regularalias 
       
   263 else
       
   264  	echo "FAIL: Expected return value 0, but  returned $ret"
       
   265 	let failno=failno+1
       
   266 fi
       
   267 }
       
   268 
       
   269 test_alias13()
       
   270 {
       
   271 let totalno=totalno+1
       
   272 echo "Test $totalno: alias with -r option to list regular aliases"
       
   273 alias -r regularalias=pwd
       
   274 aliaslist=(`alias -r`)
       
   275 ret=$?
       
   276 if [ $ret = 0 ]
       
   277 then
       
   278 	len=${#aliaslist[*]} 
       
   279 	let i=0
       
   280     while [ $i -le $len  ]
       
   281 	do
       
   282 		if [ $aliaslist[$i] = "regularalias=pwd" ]
       
   283     	then
       
   284         	echo "PASS"
       
   285         	let passno=passno+1
       
   286 			unalias regularalias
       
   287 			return
       
   288     	fi
       
   289 		let i=i+1
       
   290 	done
       
   291     echo "FAIL: Expected regularalias=pwd, but not found"
       
   292     let failno=failno+1	
       
   293 else
       
   294  	echo "FAIL: Expected return value 0, but  returned $ret"
       
   295  	let failno=failno+1
       
   296 fi
       
   297 }
       
   298 
       
   299 test_alias14()
       
   300 {
       
   301 let totalno=totalno+1
       
   302 echo "Test $totalno: alias with +r option to list regular aliases(names only)"
       
   303 alias -r regularalias=pwd
       
   304 aliaslist=(`alias +r`)
       
   305 ret=$?
       
   306 if [ $ret = 0 ]
       
   307 then
       
   308     len=${#aliaslist[*]}
       
   309     let i=0
       
   310     while [ $i -le $len  ]
       
   311     do
       
   312         if [ $aliaslist[$i] = "regularalias" ]
       
   313         then
       
   314             echo "PASS"
       
   315             let passno=passno+1
       
   316             unalias regularalias
       
   317             return
       
   318         fi
       
   319         let i=i+1
       
   320     done
       
   321     echo "FAIL: Expected regularalias, but not found"
       
   322     let failno=failno+1
       
   323 else
       
   324  	echo "FAIL: Expected return value 0, but  returned $ret"
       
   325  	let failno=failno+1
       
   326 fi
       
   327 }
       
   328 
       
   329 test_alias15()
       
   330 {
       
   331 let totalno=totalno+1
       
   332 echo "Test $totalno: alias with +m and a pattern as argument to get the alias name listed with that pattern inside"
       
   333 alias ab=xy
       
   334 res=`alias +m "ab"`
       
   335 ret=$?
       
   336 if [ $ret = 0 ]
       
   337 then
       
   338   	if [ $res = "ab" ]
       
   339   	then
       
   340         echo "PASS"
       
   341         let passno=passno+1
       
   342   	else
       
   343         echo "FAIL: Expected ab, but  returned $res"
       
   344         let failno=failno+1
       
   345   	fi
       
   346   	unalias ab
       
   347 else
       
   348  	echo "FAIL: Expected return value 0, but  returned $ret"
       
   349  	let failno=failno+1
       
   350 fi
       
   351 }
       
   352 
       
   353 
       
   354 test_alias16()
       
   355 {
       
   356 let totalno=totalno+1
       
   357 echo "Test $totalno: alias with -s option to display the suffix aliases"
       
   358 alias -s txt=echo
       
   359 ret=$?
       
   360 aliaslist=(`alias -s`)
       
   361 if [ $ret = 0 ]
       
   362 then
       
   363 	len=${#aliaslist[*]}
       
   364     let i=0
       
   365     while [ $i -le $len  ]
       
   366     do
       
   367         if [ $aliaslist[$i] = "txt=echo" ]
       
   368         then
       
   369             echo "PASS"
       
   370             let passno=passno+1
       
   371             unalias -s txt 
       
   372             return
       
   373         fi
       
   374         let i=i+1
       
   375     done
       
   376     echo "FAIL: Expected txt=echo, but not found"
       
   377     let failno=failno+1
       
   378 else
       
   379  	echo "FAIL: Expected return value 0, but  returned $ret"
       
   380  	let failno=failno+1
       
   381 fi
       
   382 }
       
   383 
       
   384 test_alias17()
       
   385 {
       
   386 let totalno=totalno+1
       
   387 echo "Test $totalno: alias with +s option to display the suffix alias names"
       
   388 alias -s txt=echo
       
   389 ret=$?
       
   390 aliaslist=(`alias +s`)
       
   391 if [ $ret = 0 ]
       
   392 then
       
   393     len=${#aliaslist[*]}
       
   394     let i=0
       
   395     while [ $i -le $len  ]
       
   396     do
       
   397         if [ $aliaslist[$i] = "txt" ]
       
   398         then
       
   399             echo "PASS"
       
   400             let passno=passno+1
       
   401             unalias -s txt
       
   402             return
       
   403         fi
       
   404         let i=i+1
       
   405     done
       
   406     echo "FAIL: Expected txt, but not found"
       
   407     let failno=failno+1
       
   408 else
       
   409  	echo "FAIL: Expected return value 0, but  returned $ret"
       
   410  	let failno=failno+1
       
   411 fi
       
   412 }
       
   413 
       
   414 
       
   415 test_alias18()
       
   416 {
       
   417 let totalno=totalno+1
       
   418 echo "Test $totalno: alias with +L option to list all aliase names except suffix aliases"
       
   419 alias +L
       
   420 ret=$?
       
   421 if [ $ret = 0 ]
       
   422 then
       
   423   	echo "PASS"
       
   424   	let passno=passno+1
       
   425 else
       
   426  	echo "FAIL: Expected return value 0, but  returned $ret"
       
   427  	let failno=failno+1
       
   428 fi
       
   429 }
       
   430 
       
   431 # define an alias to another alias with that value.
       
   432 test_alias19()
       
   433 {
       
   434 let totalno=totalno+1
       
   435 echo "Test $totalno: alias with a variable name and a command as argument"
       
   436 alias workdir1="pwd"
       
   437 alias workdir2="workdir1"
       
   438 alias workdir3="workdir2"
       
   439 ret=$?
       
   440 if [ $ret = 0 ]
       
   441 then
       
   442      if [ `pwd` = `workdir3` ]
       
   443      then
       
   444           echo "PASS"
       
   445           let passno=passno+1
       
   446      else
       
   447           echo "FAIL: Expected \"`pwd`\", returned \"`workdir`\""
       
   448           let failno=failno+1
       
   449      fi
       
   450 else
       
   451      echo "FAIL: Expected return value 0, but  returned $ret"
       
   452      let failno=failno+1
       
   453 fi
       
   454 }
       
   455 
       
   456 report()
       
   457     {
       
   458     echo "#############################################################################"
       
   459     echo "Total tests : $totalno"
       
   460     echo "Passed      : $passno"
       
   461     echo "Failed      : $failno"
       
   462     echo "#############################################################################"
       
   463     }
       
   464 
       
   465 
       
   466 init
       
   467 test_alias2
       
   468 test_alias3
       
   469 test_alias4
       
   470 test_alias5
       
   471 test_alias6
       
   472 test_alias7
       
   473 test_alias8
       
   474 test_alias9
       
   475 test_alias10
       
   476 test_alias11
       
   477 test_alias12
       
   478 test_alias13
       
   479 test_alias14
       
   480 test_alias15
       
   481 test_alias16
       
   482 test_alias17
       
   483 test_alias18
       
   484 test_alias19
       
   485 report