jdk/test/java/nio/file/Files/walkFileTree/walk_file_tree.sh
changeset 17553 4ea383c26563
parent 17552 241d13ccb08b
parent 17289 4dec41b3c5e3
child 17554 eca763ef7c5e
equal deleted inserted replaced
17552:241d13ccb08b 17553:4ea383c26563
     1 #
       
     2 # Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
       
     3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4 #
       
     5 # This code is free software; you can redistribute it and/or modify it
       
     6 # under the terms of the GNU General Public License version 2 only, as
       
     7 # published by the Free Software Foundation.
       
     8 #
       
     9 # This code is distributed in the hope that it will be useful, but WITHOUT
       
    10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12 # version 2 for more details (a copy is included in the LICENSE file that
       
    13 # accompanied this code).
       
    14 #
       
    15 # You should have received a copy of the GNU General Public License version
       
    16 # 2 along with this work; if not, write to the Free Software Foundation,
       
    17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18 #
       
    19 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20 # or visit www.oracle.com if you need additional information or have any
       
    21 # questions.
       
    22 #
       
    23 
       
    24 # @test
       
    25 # @bug 4313887 6907737
       
    26 # @summary Unit test for walkFileTree method
       
    27 # @build CreateFileTree PrintFileTree SkipSiblings TerminateWalk MaxDepth
       
    28 # @run shell walk_file_tree.sh
       
    29 
       
    30 # if TESTJAVA isn't set then we assume an interactive run.
       
    31 
       
    32 if [ -z "$TESTJAVA" ]; then
       
    33     TESTSRC=.
       
    34     TESTCLASSES=.
       
    35     JAVA=java
       
    36 else
       
    37     JAVA="${TESTJAVA}/bin/java"
       
    38 fi
       
    39 
       
    40 OS=`uname -s`
       
    41 case "$OS" in
       
    42     Windows_* | CYGWIN* )
       
    43         echo "This test does not run on Windows" 
       
    44         exit 0
       
    45         ;;
       
    46     * )
       
    47         CLASSPATH=${TESTCLASSES}:${TESTSRC}
       
    48         ;;
       
    49 esac
       
    50 export CLASSPATH
       
    51 
       
    52 # create the file tree
       
    53 ROOT=`$JAVA CreateFileTree`
       
    54 if [ $? != 0 ]; then exit 1; fi
       
    55 
       
    56 failures=0
       
    57 
       
    58 # print the file tree and compare output with find(1)
       
    59 $JAVA ${TESTVMOPTS} PrintFileTree "$ROOT" > out1
       
    60 find "$ROOT" > out2
       
    61 diff out1 out2
       
    62 if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
       
    63 
       
    64 # repeat test following links. Some versions of find(1) output
       
    65 # cycles (sym links to ancestor directories), other versions do
       
    66 # not. For that reason we run PrintFileTree with the -printCycles
       
    67 # option when the output without this option differs to find(1).
       
    68 find "$ROOT" -follow > out1
       
    69 $JAVA ${TESTVMOPTS} PrintFileTree -follow "$ROOT" > out2
       
    70 diff out1 out2
       
    71 if [ $? != 0 ];
       
    72   then 
       
    73     # re-run printing cycles to stdout
       
    74     $JAVA ${TESTVMOPTS} PrintFileTree -follow -printCycles "$ROOT" > out2
       
    75     diff out1 out2
       
    76     if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
       
    77   fi
       
    78 
       
    79 # test SKIP_SIBLINGS
       
    80 $JAVA ${TESTVMOPTS} SkipSiblings "$ROOT"
       
    81 if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
       
    82 
       
    83 # test TERMINATE
       
    84 $JAVA ${TESTVMOPTS} TerminateWalk "$ROOT"
       
    85 if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
       
    86 
       
    87 # test maxDepth
       
    88 $JAVA ${TESTVMOPTS} MaxDepth "$ROOT"
       
    89 if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
       
    90 
       
    91 # clean-up
       
    92 rm -r "$ROOT"
       
    93 
       
    94 echo ''
       
    95 if [ $failures -gt 0 ];
       
    96   then echo "$failures test(s) failed";
       
    97   else echo "Test passed"; fi
       
    98 exit $failures