summaryrefslogtreecommitdiff
path: root/.local/src/blesh/lib/test-main.sh
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2022-05-22 00:37:40 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2022-05-22 00:37:40 +0530
commitc3362aefa2e762211409923cfff065541bebf9e7 (patch)
treee48e225190fc0bb1a2db18ae2510a89a6f0d8653 /.local/src/blesh/lib/test-main.sh
parent4df17a688ba54d710a1d46ee47cb65b5c9e75764 (diff)
ble.sh & z4h addition
Diffstat (limited to '.local/src/blesh/lib/test-main.sh')
-rw-r--r--.local/src/blesh/lib/test-main.sh79
1 files changed, 79 insertions, 0 deletions
diff --git a/.local/src/blesh/lib/test-main.sh b/.local/src/blesh/lib/test-main.sh
new file mode 100644
index 0000000..dc6cb57
--- /dev/null
+++ b/.local/src/blesh/lib/test-main.sh
@@ -0,0 +1,79 @@
+# this script is a part of blesh (https://github.com/akinomyoga/ble.sh) under BSD-3-Clause license
+ble-import lib/core-test
+ble/test/start-section 'ble/main' 19
+(
+ ble/test ble/util/put a stdout=a
+ ble/test ble/util/print a stdout=a
+ ble/test 'ble/util/put "a b"' stdout='a b'
+ ble/test 'ble/util/print "a b"' stdout='a b'
+ ble/test 'ble/util/put "a b"; ble/util/put "c d"' \
+ stdout='a bc d'
+ ble/test 'ble/util/print "a b"; ble/util/print "c d"' \
+ stdout='a b' \
+ stdout='c d'
+)
+(
+ function ble/test/dummy-1 { true; }
+ function ble/test/dummy-2 { true; }
+ function ble/test/dummy-3 { true; }
+ ble/test ble/bin#has ble/test/dummy-1
+ ble/test ble/bin#has ble/test/dummy-{1..3}
+ ble/test ble/bin#has ble/test/dummy-0 exit=1
+ ble/test ble/bin#has ble/test/dummy-{0..2} exit=1
+)
+(
+ ble/bin/.freeze-utility-path readlink ls
+ function ble/test:readlink.impl1 {
+ ret=$1
+ ble/util/readlink/.resolve-loop
+ }
+ function ble/test:readlink.impl2 {
+ ret=$1
+ ble/function#push ble/bin/readlink
+ ble/util/readlink/.resolve-loop
+ ble/function#pop ble/bin/readlink
+ }
+ ble/test/chdir
+ mkdir -p ab/cd/ef
+ touch ab/cd/ef/file.txt
+ ln -s ef/file.txt ab/cd/link1
+ ln -s ab link.d
+ ln -s link.d/cd/link1 f.txt
+ ble/test '
+ ble/util/readlink f.txt
+ [[ $ret != /* ]] && ret=${PWD%/}/$ret' \
+ ret="${PWD%/}/ab/cd/ef/file.txt"
+ ln -s loop1.sh loop0.sh
+ ln -s loop2.sh loop1.sh
+ ln -s loop3.sh loop2.sh
+ ln -s loop1.sh loop3.sh
+ for impl in impl1 impl2; do
+ ble/test "ble/test:readlink.$impl loop0.sh" ret='loop1.sh'
+ done
+ mkdir -p phys.dir
+ touch phys.dir/1.txt
+ ln -s ../../../phys.dir ab/cd/ef/phys.link
+ ln -s ab/cd/ef/phys.link phys.link
+ local pwd=$PWD xpath=
+ ble/test code:'
+ path=phys.link/1.txt
+ ble/util/readlink/.resolve-physical-directory
+ declare -p path PWD >&2
+ [[ $path == */phys.dir/1.txt && $PWD == "$pwd" ]]'
+ ble/test/rmdir
+)
+(
+ ble/test '[[ -d $_ble_base ]]'
+ ble/test '[[ -d $_ble_base_run ]]'
+ ble/test '[[ -d $_ble_base_cache ]]'
+)
+(
+ qnl="\$'\n'"
+ value=$'\nxxx is a function\nhello\nyyy is a function\n'
+ pattern=$'\n+([][{}:[:alnum:]]) is a function\n'
+ shopt -s extglob
+ ble/test '[[ ${value//$pattern/'"$qnl"'} == '"$qnl"'hello'"$qnl"' ]]'
+ shopt -u extglob
+ ble/test '[[ ${value//$pattern/'"$qnl"'} != '"$qnl"'hello'"$qnl"' ]]'
+)
+ble/test/end-section