1#!@SH_PROG@ 2# -*- shell-script -*- 3 4# Test _Dbg_file_canonic 5test_file_file_canonic() 6{ 7 _Dbg_set_basename=0 8 for file in /tmp/foo.bar /a/b/foo.bar foo.bar ; do 9 typeset canonic_file 10 canonic_file=$(_Dbg_file_canonic "$file") 11 assertEquals 'canonic_file should return 0' '0' $? 12 assertEquals 'canonic_file should do nothing' "$file" "$canonic_file" 13 done 14 15 _Dbg_set_basename=1 16 typeset canonic_file 17 for file in /tmp/foo.bar /a/b/foo.bar foo.bar ; do 18 canonic_file=$(_Dbg_file_canonic "$file") 19 assertEquals 'canonic_file should return 0' '0' $? 20 assertEquals 'canonic_file should shorten file' 'foo.bar' "$canonic_file" 21 done 22 canonic_file=$(_Dbg_file_canonic) 23 assertNotEquals 'canonic_file not should return 0' '0' $? 24 # Other tests need _Dbg_set_basename = 0 25 _Dbg_set_basename=0 26} 27 28# Test _Dbg_tilde_expand_filename 29test_file_glob_filename() 30{ 31 typeset filename 32 33 filename='' 34 _Dbg_tilde_expand_filename $shunit_file 35 assertEquals '0' $? 36 filename=${filename##*/} 37 assertEquals 'shunit2' $filename 38 39 _Dbg_tilde_expand_filename ./${srcdir}shunit? 40 assertEquals '0' $? 41 filename=${filename##*/} 42 assertEquals 'shunit2' $filename 43 44 _Dbg_tilde_expand_filename ./${srcdir}[a-s]h*nit? 45 assertEquals '0' $? 46 filename=${filename##*/} 47 assertEquals 'shunit2' $filename 48 49 _Dbg_tilde_expand_filename ${srcdir}abcdefg 50 assertEquals '1' $? 51 filename=${filename##*/} 52 assertEquals 'abcdefg' "$filename" 53 54 if [[ -r ~ ]] ; then 55 _Dbg_tilde_expand_filename '~' 56 assertEquals '0' $? 57 assertEquals ~ "$filename" 58 fi 59 60 _Dbg_tilde_expand_filename ${srcdir}'some embedded spaces' 61 assertEquals '1' $? 62 filename=${filename##*/} 63 assertEquals 'some embedded spaces' "$filename" 64 65} 66 67# Test _Dbg_adjust_filename 68test_file_adjust_filename() 69{ 70 typeset filename 71 _Dbg_set_annotate=0 72 _Dbg_set_basename=0 73 filename=$(_Dbg_adjust_filename abc) 74 assertEquals 'abc' $filename 75 filename=$(_Dbg_adjust_filename /abc) 76 assertEquals '/abc' $filename 77 _Dbg_set_basename=1 78 filename=$(_Dbg_adjust_filename /abc) 79 assertEquals 'abc' $filename 80} 81 82# Test _Dbg_tilde_expand_filename 83test_file_resolve_expand_filename() 84{ 85 filename=$(_Dbg_resolve_expand_filename /) 86 assertEquals '0' $? 87 assertEquals '/' "$filename" 88 filename=$(_Dbg_resolve_expand_filename .) 89 assertEquals '0' $? 90 assertEquals '/' "${filename:0:1}" 91 filename=$(_Dbg_resolve_expand_filename ./fdafdsa) 92 assertEquals '0' $? 93 typeset -i size=${#filename} 94 assertEquals '/fdafdsa' "${filename:$size-8}" 95 assertNotEquals '.' "${filename:$size-1}" 96} 97 98abs_top_srcdir=@abs_top_srcdir@ 99# Make sure $abs_top_srcdir has a trailing slash 100abs_top_srcdir=${abs_top_srcdir%%/}/ 101. ${abs_top_srcdir}test/unit/helper.sh 102 103srcdir=@srcdir@ 104srcdir=${srcdir%%/}/ 105 106. $abs_top_srcdir/init/pre.sh 107. $abs_top_srcdir/lib/filecache.sh 108. $abs_top_srcdir/lib/file.sh 109 110set -- # reset $# so shunit2 doesn't get confused. 111 112[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file} 113