Last active
October 28, 2018 08:35
Revisions
-
photonxp revised this gist
Oct 28, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/bin/bash source ./testf.bashlib test1(){ echo "hello world" -
photonxp revised this gist
Oct 28, 2018 . 1 changed file with 192 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,192 @@ #!/bin/bash # ####test_demo_testf.bash # #!/bin/bash # # # Usage: # # ./test_demo_testf.bash # # # Use the -o to override the check on the test dir # # ./test_demo_testf.bash -o # # source ./testf.bash # # test1(){ # echo "hello" # } # # test2(){ # echo "world" # } # # opt="$1" # run_tests "test1" "test2" echo_start(){ echo "$1 =============================" } get_bwd(){ # bwd: base working dir # cwd: current working dir cwd=$(realpath .) : ${bwd=$cwd} } init_time_log(){ fpath_log="$bwd"/time.log if [ -f $fpath_log ] then if [ "-o" != "$opt" ] then echo "Cannot create file:: File $fpath_log exists. Exit." exit 1 fi rm $fpath_log fi touch $fpath_log } log_datetime(){ datef=`date '+%Y%m%d.%H%M%S'` echo "$1$datef" >> $fpath_log } init_dir(){ dpath_test="$bwd"/test9 if [ -e $dpath_test ] then if [ "-o" != "$opt" ] then echo "Cannot create dir:: Dir (or file) $dpath_test exists. Exit." exit 1 fi rm -r $dpath_test fi mkdir $dpath_test cd $dpath_test } init_script_dir(){ # to be overwritten by the calling script init_dir } init_script_extra(){ # to be overwritten by the calling script : } finish_script_extra(){ # to be overwritten by the calling script : } init_script(){ echo_start "Start script $0" get_bwd init_time_log log_datetime "Start script $0 : " init_script_dir init_script_extra } finish_script(){ finish_script_extra echo_start "Finish script $0" log_datetime "Finish script $0 : " } init_test_extra(){ # to be overwritten by the calling script : } finish_test_extra(){ # to be overwritten by the calling script : } init_test(){ echo_start "Start $1 : " log_datetime "Start $1 : " init_test_extra } finish_test(){ finish_test_extra log_datetime "Finish $1 : " } run_tests(){ init_script for test in "$@" do init_test "$test" $test finish_test "$test" done finish_script } get_first_n_words_by_space(){ line="$1" n="$2" echo $(printf "$line" | cut -d " " -f 1-"$n") } assert_equal_str(){ expected="$1" actual="$2" if [ "$expected" == "$actual" ] then echo Pass return 0 else echo "Fail: $expected != $actual" return 1 fi } assert_equal_num(){ expected="$1" actual="$2" if [[ "y" == "y$expected" && "y"=="y$actual" ]] then echo "Fail: arg1:expected is '', arg2:actual is ''" return 1 fi if [ "y" == "y$expected" ] then echo "Fail: arg1:expected is ''" return 1 fi if [ "y" == "y$actual" ] then echo "Fail: arg2:actual is ''" return 1 fi if [ $expected -eq $actual ] then echo Pass else echo "Fail: $expected != $actual" return 0 fi } test1(){ # call the tested script : } -
photonxp revised this gist
Oct 28, 2018 . 1 changed file with 0 additions and 192 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,192 +0,0 @@ -
photonxp renamed this gist
Oct 28, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
photonxp revised this gist
Oct 26, 2018 . 1 changed file with 42 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,8 +27,15 @@ echo_start(){ echo "$1 =============================" } get_bwd(){ # bwd: base working dir # cwd: current working dir cwd=$(realpath .) : ${bwd=$cwd} } init_time_log(){ fpath_log="$bwd"/time.log if [ -f $fpath_log ] then if [ "-o" != "$opt" ] @@ -49,7 +56,7 @@ log_datetime(){ } init_dir(){ dpath_test="$bwd"/test9 if [ -e $dpath_test ] then if [ "-o" != "$opt" ] @@ -62,26 +69,57 @@ init_dir(){ fi mkdir $dpath_test cd $dpath_test } init_script_dir(){ # to be overwritten by the calling script init_dir } init_script_extra(){ # to be overwritten by the calling script : } finish_script_extra(){ # to be overwritten by the calling script : } init_script(){ echo_start "Start script $0" get_bwd init_time_log log_datetime "Start script $0 : " init_script_dir init_script_extra } finish_script(){ finish_script_extra echo_start "Finish script $0" log_datetime "Finish script $0 : " } init_test_extra(){ # to be overwritten by the calling script : } finish_test_extra(){ # to be overwritten by the calling script : } init_test(){ echo_start "Start $1 : " log_datetime "Start $1 : " init_test_extra } finish_test(){ finish_test_extra log_datetime "Finish $1 : " } -
photonxp revised this gist
Oct 24, 2018 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -110,8 +110,10 @@ assert_equal_str(){ if [ "$expected" == "$actual" ] then echo Pass return 0 else echo "Fail: $expected != $actual" return 1 fi } -
photonxp revised this gist
Oct 24, 2018 . 2 changed files with 32 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -44,7 +44,18 @@ test_assert_equal_str(){ test_assert_equal_num(){ assert_equal_num 1 1 assert_equal_num "1" "1" rslt=$(assert_equal_num "" "") n_words=$(get_first_n_words_by_space "$rslt" 1) assert_equal_str "Fail:" "$n_words" rslt=$(assert_equal_num 1 "") n_words=$(get_first_n_words_by_space "$rslt" 1) assert_equal_str "Fail:" "$n_words" rslt=$(assert_equal_num "" 1) n_words=$(get_first_n_words_by_space "$rslt" 1) assert_equal_str "Fail:" "$n_words" rslt=$(assert_equal_num 1 2) n_words=$(get_first_n_words_by_space "$rslt" 1) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -118,11 +118,31 @@ assert_equal_str(){ assert_equal_num(){ expected="$1" actual="$2" if [[ "y" == "y$expected" && "y"=="y$actual" ]] then echo "Fail: arg1:expected is '', arg2:actual is ''" return 1 fi if [ "y" == "y$expected" ] then echo "Fail: arg1:expected is ''" return 1 fi if [ "y" == "y$actual" ] then echo "Fail: arg2:actual is ''" return 1 fi if [ $expected -eq $actual ] then echo Pass else echo "Fail: $expected != $actual" return 0 fi } -
photonxp revised this gist
Oct 24, 2018 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,18 +14,19 @@ test_init_dir_unexist(){ } test_init_dir_exist_no_op(){ opt="" [ ! -e ./test9 ] && mkdir ./test9 rslt=$(init_dir) n_words=$(get_first_n_words_by_space "$rslt" 3) assert_equal_str "Cannot create dir::" "$n_words" opt="-o" } test_init_dir_exist_op(){ [ ! -e ./test9 ] && mkdir ./test9 opt="-o" rslt=$(init_dir) assert_equal_str "" "$rslt" } test_assert_equal_str(){ @@ -59,7 +60,7 @@ opt="$1" #run_tests test_assert_equal_num tests1="test1 test_init_dir_unexist test_init_dir_exist_no_op test_init_dir_exist_op" tests2="test_assert_equal_str test_assert_equal_num" tests="$tests1 $tests2" run_tests $(echo $tests) -
photonxp revised this gist
Oct 24, 2018 . 2 changed files with 42 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,9 +28,38 @@ test_init_dir_exist_op(){ opt="" } test_assert_equal_str(){ assert_equal_str "a" "a" assert_equal_str 1 1 assert_equal_str "" "" assert_equal_str '' "" assert_equal_str '' rslt=$(assert_equal_str "a" "b") n_words=$(get_first_n_words_by_space "$rslt" 1) assert_equal_str "Fail:" "$n_words" } test_assert_equal_num(){ assert_equal_num 1 1 assert_equal_num "1" "1" assert_equal_num "" "" rslt=$(assert_equal_num 1 2) n_words=$(get_first_n_words_by_space "$rslt" 1) assert_equal_str "Fail:" "$n_words" rslt=$(assert_equal_num "a" "a") n_words=$(get_first_n_words_by_space "$rslt" 1) assert_equal_str "Fail:" "$n_words" } set -- -o opt="$1" #run_tests test_assert_equal_num tests1="test1 test_init_dir_unexist test_init_dir_exist_op test_init_dir_exist_no_op" tests2="test_assert_equal_str test_assert_equal_num" tests="$tests1 $tests2" run_tests $(echo $tests) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -115,6 +115,17 @@ assert_equal_str(){ fi } assert_equal_num(){ expected="$1" actual="$2" if [ $expected -eq $actual ] then echo Pass else echo "Fail: $expected != $actual" fi } test1(){ # call the tested script : -
photonxp revised this gist
Oct 24, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ # # Usage: # # ./test_demo_testf.bash # # # Use the -o to override the check on the test dir # # ./test_demo_testf.bash -o # # source ./testf.bash -
photonxp revised this gist
Oct 24, 2018 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,12 @@ # ####test_demo_testf.bash # #!/bin/bash # # # Usage: # # ./test_demo_testf.bash # # # Use the -o to override the check on test dir # # ./test_demo_testf.bash -o # # source ./testf.bash # # test1(){ -
photonxp revised this gist
Oct 24, 2018 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,7 +27,7 @@ init_time_log(){ then if [ "-o" != "$opt" ] then echo "Cannot create file:: File $fpath_log exists. Exit." exit 1 fi @@ -43,18 +43,19 @@ log_datetime(){ } init_dir(){ dpath_test=./test9 if [ -e $dpath_test ] then if [ "-o" != "$opt" ] then echo "Cannot create dir:: Dir (or file) $dpath_test exists. Exit." exit 1 fi rm -r $dpath_test fi mkdir $dpath_test } init_script(){ -
photonxp revised this gist
Oct 24, 2018 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,12 @@ init_time_log(){ fpath_log=./time.log if [ -f $fpath_log ] then if [ "-o" != "$opt" ] then echo "Cannot create file:: File time.log exists. Exit." exit 1 fi rm $fpath_log fi -
photonxp revised this gist
Oct 24, 2018 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -47,10 +47,9 @@ init_dir(){ fi rm -r ./test9 fi mkdir ./test9 } init_script(){ -
photonxp revised this gist
Oct 24, 2018 . 2 changed files with 79 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ #!/bin/bash source ./testf.bash test1(){ echo "hello world" } test_init_dir_unexist(){ [ -e ./test9 ] && rm -r ./test9 init_dir rslt="$(ls -d ./test9)" assert_equal_str "./test9" "$rslt" } test_init_dir_exist_no_op(){ [ ! -e ./test9 ] && mkdir ./test9 rslt=$(init_dir) n_words=$(get_first_n_words_by_space "$rslt" 3) assert_equal_str "Cannot create dir::" "$n_words" } test_init_dir_exist_op(){ [ ! -e ./test9 ] && mkdir ./test9 opt="-o" rslt=$(init_dir) assert_equal_str "" "$rslt" opt="" } set -- -o opt="$1" #run_tests test_init_dir_exist tests="test1 test_init_dir_unexist test_init_dir_exist_op test_init_dir_exist_no_op" run_tests $(echo $tests) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/bin/bash # ####test_demo_testf.bash # #!/bin/bash # # source ./testf.bash @@ -13,12 +13,19 @@ # echo "world" # } # # opt="$1" # run_tests "test1" "test2" echo_start(){ echo "$1 =============================" } init_time_log(){ fpath_log=./time.log if [ -f $fpath_log ] then # if ! -o, exit rm $fpath_log fi @@ -30,21 +37,34 @@ log_datetime(){ echo "$1$datef" >> $fpath_log } init_dir(){ if [ -e ./test9 ] then if [ "-o" != "$opt" ] then echo "Cannot create dir:: Dir (or file) test9 exists. Exit." exit 1 fi rm -r ./test9 mkdir ./test9 else mkdir ./test9 fi } init_script(){ echo_start "Start script $0" init_time_log log_datetime "Start script $0 : " init_dir } finish_script(){ echo_start "Finish script $0" log_datetime "Finish script $0 : " } init_test(){ echo_start "Start $1 : " log_datetime "Start $1 : " @@ -67,9 +87,24 @@ run_tests(){ finish_script } get_first_n_words_by_space(){ line="$1" n="$2" echo $(printf "$line" | cut -d " " -f 1-"$n") } assert_equal_str(){ expected="$1" actual="$2" if [ "$expected" == "$actual" ] then echo Pass else echo "Fail: $expected != $actual" fi } test1(){ # call the tested script : } -
photonxp revised this gist
Oct 23, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -59,9 +59,9 @@ run_tests(){ for test in "$@" do init_test "$test" $test finish_test "$test" done finish_script -
photonxp revised this gist
Oct 23, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ #!/bin/bash # ####test_testf.bash # #!/bin/bash # # source ./testf.bash -
photonxp revised this gist
Oct 23, 2018 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,18 @@ #!/bin/bash # #!/bin/bash # # source ./testf.bash # # test1(){ # echo "hello" # } # # test2(){ # echo "world" # } # # run_tests "test1" "test2" init_time_log(){ fpath_log=./time.log -
photonxp created this gist
Oct 22, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ #!/bin/bash # ####test_testf.bash # #!/bin/bash # # source ./testf.bash # # test1(){ # echo "hello, world" # } # # run_tests "test1" init_time_log(){ fpath_log=./time.log if [ -f $fpath_log ] then rm $fpath_log fi touch $fpath_log } log_datetime(){ datef=`date '+%Y%m%d.%H%M%S'` echo "$1$datef" >> $fpath_log } init_script(){ echo_start "Start script $0" init_time_log log_datetime "Start script $0 : " } finish_script(){ echo_start "Finish script $0" log_datetime "Finish script $0 : " } echo_start(){ echo "$1 =============================" } init_test(){ echo_start "Start $1 : " log_datetime "Start $1 : " } finish_test(){ log_datetime "Finish $1 : " } run_tests(){ init_script for test in "$@" do init "$test" $test finish "$test" done finish_script } test1(){ # call the tested script : } #run_tests "test1"