sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

test-main.sh (2785B)


      1 # source script for ble.sh interactive sessions -*- mode: sh; mode: sh-bash -*-
      2 
      3 ble-import lib/core-test
      4 
      5 ble/test/start-section 'ble/main' 19
      6 
      7 # ble/util/{put,print}
      8 (
      9   ble/test ble/util/put a     stdout=a
     10   ble/test ble/util/print a   stdout=a
     11   ble/test 'ble/util/put "a b"'   stdout='a b'
     12   ble/test 'ble/util/print "a b"' stdout='a b'
     13   ble/test 'ble/util/put "a b"; ble/util/put "c d"' \
     14            stdout='a bc d'
     15   ble/test 'ble/util/print "a b"; ble/util/print "c d"' \
     16            stdout='a b' \
     17            stdout='c d'
     18 )
     19 
     20 # ble/bin#has
     21 (
     22   function ble/test/dummy-1 { true; }
     23   function ble/test/dummy-2 { true; }
     24   function ble/test/dummy-3 { true; }
     25   ble/test ble/bin#has ble/test/dummy-1
     26   ble/test ble/bin#has ble/test/dummy-{1..3}
     27   ble/test ble/bin#has ble/test/dummy-0 exit=1
     28   ble/test ble/bin#has ble/test/dummy-{0..2} exit=1
     29 )
     30 
     31 # ble/util/readlink
     32 (
     33   if [[ $OSTYPE == msys* ]]; then
     34     export MSYS=${MSYS:+$MSYS }winsymlinks
     35   fi
     36 
     37   ble/bin#freeze-utility-path readlink ls
     38   function ble/test:readlink.impl1 {
     39     ret=$1
     40     ble/util/readlink/.resolve-loop
     41   }
     42   function ble/test:readlink.impl2 {
     43     ret=$1
     44     ble/function#push ble/bin/readlink
     45     ble/util/readlink/.resolve-loop
     46     ble/function#pop ble/bin/readlink
     47   }
     48 
     49   ble/test/chdir
     50   cd -P .
     51 
     52   command mkdir -p ab/cd/ef
     53   command touch ab/cd/ef/file.txt
     54   command ln -s ef/file.txt ab/cd/link1
     55   command ln -s ab link.d
     56   command ln -s link.d/cd/link1 f.txt
     57   ble/test '
     58     ble/util/readlink f.txt
     59     [[ $ret != /* ]] && ret=${PWD%/}/$ret' \
     60     ret="${PWD%/}/ab/cd/ef/file.txt"
     61 
     62   # loop symbolic links
     63   command touch loop1.sh
     64   command ln -s loop1.sh loop0.sh
     65   command ln -s loop1.sh loop3.sh
     66   command rm loop1.sh
     67   command ln -s loop3.sh loop2.sh
     68   command ln -s loop2.sh loop1.sh
     69   for impl in impl1 impl2; do
     70     ble/test "ble/test:readlink.$impl loop0.sh" ret='loop1.sh'
     71   done
     72 
     73   # resolve physical directory
     74   mkdir -p phys.dir
     75   touch phys.dir/1.txt
     76   ln -s ../../../phys.dir ab/cd/ef/phys.link
     77   ln -s ab/cd/ef/phys.link phys.link
     78   local pwd=$PWD xpath=
     79   ble/test code:'
     80     path=phys.link/1.txt
     81     ble/util/readlink/.resolve-physical-directory
     82     declare -p path PWD >&2
     83     [[ $path == */phys.dir/1.txt && $PWD == "$pwd" ]]'
     84 
     85   ble/test/rmdir
     86 )
     87 
     88 # ble/base/create-*-directory
     89 (
     90   ble/test '[[ -d $_ble_base ]]'
     91   ble/test '[[ -d $_ble_base_run ]]'
     92   ble/test '[[ -d $_ble_base_cache ]]'
     93 )
     94 
     95 (
     96   qnl="\$'\n'"
     97   value=$'\nxxx is a function\nhello\nyyy is a function\n'
     98   pattern=$'\n+([][{}:[:alnum:]]) is a function\n'
     99   shopt -s extglob
    100   ble/test '[[ ${value//$pattern/'"$qnl"'} == '"$qnl"'hello'"$qnl"' ]]'
    101   shopt -u extglob
    102   ble/test '[[ ${value//$pattern/'"$qnl"'} != '"$qnl"'hello'"$qnl"' ]]'
    103 )
    104 
    105 # ble-reload
    106 # ble-update
    107 # ble-attach
    108 # ble-detach
    109 
    110 ble/test/end-section