Repository navigation
Expand file tree
/
Copy pathshell-api-selftest.sh
More file actions
874 lines (735 loc) · 21.9 KB
/
Copy pathshell-api-selftest.sh
File metadata and controls
874 lines (735 loc) · 21.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
#!/bin/bash
###############################################################################
#
# Copyright (c) 2024-2026 Michel Mehl. All rights reserved.
#
# -----------------------------------------------------------------------------
#
# Report bugs to michel.mehl@slashetc.fr
#
# -----------------------------------------------------------------------------
#
###############################################################################
trap _cleanup EXIT SIGHUP SIGINT SIGTERM SIGQUIT SIGABRT
__SHELL_API_SELFTEST_DIR__=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
source "${__SHELL_API_SELFTEST_DIR__}/shell-api-core.sh"
source "${__SHELL_API_SELFTEST_DIR__}/shell-api-yaml.sh"
if _loaded "${BASH_SOURCE[0]}" ; then
return 0
fi
Test__resultAll=0
###############################################################################
# UNFORMAL QUICKTESTS TO BE PUT IN ORDER
testPerfTrim()
{
_log "Standard tests"
Test__Str
_log "Perf test Str__trim"
local var="$(find /home/michel/photobook-demos/output -name "*")"
for i in {1..1000};do
Str__trim "$var" var
done
}
testGrepAndGetField()
{
local search="$1"
local idx=$2
local testStr="
Local time: jeu. 2026-08-13 10:37:07 CEST
Universal time: jeu. 2026-08-13 08:37:07 UTC
RTC time: jeu. 2026-08-13 08:37:07
Time zone: Europe/Paris (CEST, +0200)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
Time zone: US/Pacific
System clock synchronized: no
Time zone: Africa/Alger"
local found=()
Str__grepAndGetField "$testStr" "${search}" ":" $idx found
for oneFound in "${found[@]}" ; do
echo "'${oneFound}'"
done
}
testGetField()
{
fields="after:lunch:i:will:go:to:the:swimmingpool"
Str__getField "$fields" ":" "0" testGetFieldRes
echo "'$testGetFieldRes'"
Str__getField "$fields" ":" "1" testGetFieldRes
echo "'$testGetFieldRes'"
Str__getField "$fields" ":" "6" testGetFieldRes
echo "'$testGetFieldRes'"
Str__getField "$fields" ":" "7" testGetFieldRes
echo "'$testGetFieldRes'"
fields="singlefield"
Str__getField "$fields" ":" "0" testGetFieldRes
echo "'$testGetFieldRes'"
Str__getField "$fields" ":" "1" testGetFieldRes
echo "'$testGetFieldRes' should be empty"
fields=""
Str__getField "$fields" ":" "0" testGetFieldRes
echo "'$testGetFieldRes' should be empty"
Str__getField "$fields" ":" "1" testGetFieldRes
echo "'$testGetFieldRes' should be empty"
}
testPerfGrepApi()
{
local useGrep=$1
for i in {1..1000};do
testGrepApi "Time zone" $useGrep >/dev/null
testGrepApi "time" $useGrep >/dev/null
done
}
testGrepApi()
{
local search="$1"
local useGrep=$2
local testStr="
Local time: jeu. 2026-08-13 10:37:07 CEST
Universal time: jeu. 2026-08-13 08:37:07 UTC
RTC time: jeu. 2026-08-13 08:37:07
Time zone: Europe/Paris (CEST, +0200)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
Time zone: US/Pacific
System clock synchronized: no
"
if $useGrep ; then
grep -F "${search}" <<<"$testStr"
else
local found=""
Str__grep "$testStr" "${search}" found
echo "$found"
fi
}
testTimer()
{
timerid=0
elapsed=0
Date__startTimer timerid
sleep 5
Date__elapsedSecondsTimer $timerid elapsed
echo "${elapsed} seconds elapsed"
sleep 3
Date__elapsedSecondsTimer $timerid elapsed
echo "${elapsed} seconds elapsed"
Date__elapsedMinutesTimer $timerid elapsed
echo "${elapsed} minutes elapsed"
exit 0
}
testYamlPerfReadAll() {
declare -A myYAMLDataMap
for i in {1..100};do
YAML__readAll "/home/michel/website2/conf/bookmake.yml" myYAMLDataMap
YAML__dumpAll
done
}
testYamlOneFile() {
echo
echo "---"
echo
if [ $# -eq 2 ] ; then
echo "test file: $2"
testfile="$2"
else
testfile="/tmp/test.yml"
echo "$1" > "$testfile"
fi
declare -A myYAMLDataMap
YAML__readAll "$testfile" myYAMLDataMap
YAML__dumpAll myYAMLDataMap
}
testManyYamlTests() {
#testYamlOneFile "" "/home/michel/website2/conf/bookmake.yml" ; exit 0
testStr="$(cat <<'EOF'
titles:
- [ "1", "Milan", ~ ]
- [ "2", "Rome", "2023-04-23{nbsp}00:00:00" ]
- [ "3", "Pompéi", "2023-04-29{nbsp}00:00:00" ]
EOF
)"
testYamlOneFile "$testStr"
#exit 0
testStr="$(cat <<'EOF'
include:
start-date: ~
end-date: ~
explicit-files:
"mountpilot_sshot_list_1.png" :
chapter: "Examples of list commands for list 1"
title: "Default List (everything but loop devices)"
"mountpilot_sshot_list_2.png" :
chapter: "Examples of list commands for list 2"
title: "List all except loop devices (default behavior)"
EOF
)"
testYamlOneFile "$testStr"
#exit 0
testYArray1='[ 1,2,3,4]# comment with an array [ word, int ]'
echo "result for $testYArray1"
YAML__readAll_decodeArrayValue testYArray1 1 " bidon"
echo "'$testYArray1'"
testYArray1='[ 1,2,3,4]#comment'
echo "result for $testYArray1"
YAML__readAll_decodeArrayValue testYArray1 1 " bidon"
echo "'$testYArray1'"
testYArray1='[ 1,2,3,4] #comment'
echo "result for $testYArray1"
YAML__readAll_decodeArrayValue testYArray1 1 " bidon"
echo "'$testYArray1'"
testYArray1='[ 1,2,3,4]'
echo "result for $testYArray1"
YAML__readAll_decodeArrayValue testYArray1 1 " bidon"
echo "'$testYArray1'"
testYArray2='[ "s1", "s2", "s3" ]'
echo "result for $testYArray2"
YAML__readAll_decodeArrayValue testYArray2 1 " bidon"
echo "'$testYArray2'"
testYArray2='[ "value with space", "s2", " here also spaces at both ends " ]'
echo "result for $testYArray2"
YAML__readAll_decodeArrayValue testYArray2 1 " bidon"
echo "'$testYArray2'"
testYArray3='[ "s1", "s2", "s3"'
echo "result for $testYArray3"
YAML__readAll_decodeArrayValue testYArray3 1 " bidon"
echo "'$testYArray3'"
testYArray4='[ "s1", "s2, "s3" ]'
echo "result for $testYArray4"
YAML__readAll_decodeArrayValue testYArray4 1 " bidon"
echo "'$testYArray4'"
#exit 0
testStr="$(cat <<'EOF'
f0:
- f0_1
- f0_2
field1: - f1_1
- f1_2
f2:
- f2_1 with space
- f2_2 with space too
f3:
f4:
- v1
-v2:12
f4: [ 1,2,3,4]
f5:
[ "s1", "s2", "s3" ]
# Values with quotes
f6:
- "file1 f6"
- "file2 f6"
- "file3 f6"
- "file4 f6"
titles:
- [ "1", "Milan", ~ ]
- [ "2", "Rome", "2023-04-23{nbsp}00:00:00" ]
- [ "3", "Pompéi", "2023-04-29{nbsp}00:00:00" ]
EOF
)"
testYamlOneFile "$testStr"
exit 0
testStr="$(cat <<'EOF'
property0:
property1 : |
1st line of property1
2nd line of property1
third line with more indent
prop2: caramel - a crazy one
p0:
p1 : |
1st line of p1
2nd line of p1
third line with more indent
4th line
property2: |
1st line of property2
2nd line of property2
property3:
joe
tata
EOF
)"
testYamlOneFile "$testStr"
#exit 0
testStr="$(cat <<'EOF'
property1 : |
this is a simple multiline value
second line
EOF
)"
testYamlOneFile "$testStr"
#exit 0
testStr="$(cat <<'EOF'
property1 :
subprop1_1:
value is below
subprop1_2:
subprop1_2_1:
1_2_1 value below too
subprop1_2_2: 1_2_2 value on the same level
EOF
)"
testYamlOneFile "$testStr"
#exit 0
testStr="$(cat <<'EOF'
property1 :
subprop1_1:
subprop1_1_1: zizou
subprop1_2:
subprop1_2_1:
prop2:
subprop2_1:
subprop2_1_1: tata
subprop2_1_2: toto
EOF
)"
testYamlOneFile "$testStr"
exit 0
testStr="$(cat <<'EOF'
property1 :
subprop1_1:
subprop1_1_1: zizou
subprop1_2:
subprop1_2_1:
prop2:
subprop2_1:
subprop2_1_1: tata
subprop2_1_2: toto
prop3:
subprop3_1:
prop4:
subprop4_1: joe
property2 : val2
property3 : val3
property4 :
subprop4_1: subval4_1
subprop4_2: subval4_2
subprop4_3: subval4_3
EOF
)"
testYamlOneFile "$testStr"
exit 0
testStr="$(cat <<'EOF'
property1 :
subprop1_1:
subprop1_1_1:
subprop1_2:
subprop1_2_1:
subprop1_2_2:
subprop1_3:
subprop1_3_1:
subprop1_3_2: toto
property2 : val2
property3 : val3
property4 :
subprop4_1: subval4_1
subprop4_2: subval4_2
subprop4_3: subval4_3
EOF
)"
testYamlOneFile "$testStr"
exit 0
testStr="$(cat <<'EOF'
property1 :
subprop1_1:
subprop1_1_1:
subprop1_1_2:
subprop1_1_3:
property2 : val2
property3 : val3
property4 : val4
subprop4_1: subval4_1
subprop4_2: subval4_2
subprop4_3: subval4_3
EOF
)"
testYamlOneFile "$testStr"
#exit 0
testStr="$(cat <<'EOF'
property1 :
subprop1_1: subval1_1
property2 : val2
property3 : val3
property4 : val4
subprop4_1: subval4_1
EOF
)"
testYamlOneFile "$testStr"
#exit 0
testStr="$(cat <<'EOF'
property1 :
subprop1_1: subval1_1
property2 : val2
property3 : val3
property4 :
subprop4_1: subval4_1
EOF
)"
testYamlOneFile "$testStr"
testStr="$(cat <<'EOF'
property1 : val1
property2 : val2
property3 : val3
property4 : val4
EOF
)"
testYamlOneFile "$testStr"
exit 0
}
testCommonEndString() {
commonTailStr=""
Str__nbCommonEndString "Mounting a block DEvice" "Example of mounting of a block device" commonTailStr
_log_vars commonTailStr
exit 0
}
testAdbAPI() {
adbStr=""
Adb__getVersion adbStr
_log_vars adbStr
Adb__getSDKVersion adbStr
_log_vars adbStr
Adb__getDeviceName adbStr
_log_vars adbStr
Adb__listDevices adbStr
echo "List of devices "${adbStr[@]}""
exit 0
}
testPkgInstallAlternative() {
_log_high "Testing install alternatives exfat-utils|exfatlabel"
Pkg__install "exfatlabel@exfat-utils|exfatlabel" "" apt
_log_high "Testing install alternatives exfatlabel|exfat-utils"
Pkg__install "exfatlabel@exfatlabel|exfat-utils" "" apt
exit 0
}
testDistroEnv() {
# Env__distrover()
distro=""
time Env__distrover 1 distro
time echo "$distro"
time Env__distrover 2 distro
time echo "$distro"
time Env__distrover 3 distro
echo "$distro"
echo "source: $Env__LSB_RELEASE"
exit 0
Test__ProgressBar
exit 0
}
testInputDirPath() {
Test__Input__dirpath
Test__Input__dirpath_forcedinput
Test__Str
Test_URL
Test_File
#exit 0
}
testLogStatus() {
_log_status high "Uploading app..."
sleep 3
_log_status_end ok
_log_status_end fail
exit 0
}
:<<'EOF'
clear -x
Str__fitToLineWidth str 30
echo -n "$str"
Str__justify str 30
echo -n "$str"
str="short string"
Str__justify str 30
echo -n "$str"
str="nospaceThisisobsolete.Onlycommandsaregivenwithdashoptions"
Str__justify str 30
echo -n "$str"
str="This is obsolete. Only commands are given with dash options"
Str__justify str 30
echo -n "$str"
str=" Checkout all head revision or checkout resp. the revision, release tag, file from head revision as specified by argument"
Str__fitToLineWidth str 30
echo -n "$str"
str="short string"
Str__fitToLineWidth str 30
echo -n "$str"
str="
Rearranges a multipline text so that each line is forced to have the specified width by duplicating as much spaces as necessary.
@param [1] inout reference to the input string to be rearranged
@param [2] target line width"
str="ke
"
cnt=0
while [ $cnt -lt 5000 ] ; do
lcount=0
Str__lineCount "$str" lcount
cnt=$(( $cnt + 1))
done
echo $lcount
EOF
# END UNFORMAL QUICKTESTS
###############################################################################
:<<'EOF'
Use this function to display the test result
@param [1] boolean result (eg. value of $?). 0=success, otherwise failure
@param [2...n] list of additional infos in case of failure, typically a message of type "got <value>, whilst expected <other value>"
of the basic form xxxxx://yyyyy
@return mirrors first parameter
EOF
Test__printResult()
{
if [ $1 -eq 0 ] ; then
echo SUCCESS
return 0
else
Test__resultAll=1
echo FAIL
if [ $# -gt 1 ] ; then
shift
local i
#local args=($@)
for i in "$*"
do
echo "'$i'"
done
fi
return 1
fi
return 0
}
# --------------------------------------------------------------------------------------
# File related API
# --------------------------------------------------------------------------------------
Test_File()
{
Test__File_in_out File__ext "\
file.txt txt
composite.file.name.with.dots.zip zip
noext \"\"
f.longextension longextension
.so so
\"\" \"\""
Test__File_in_out File__corename "\
file.txt file
composite.file.name.with.dots.zip composite.file.name.with.dots
noext noext
f.longextension f
.so \"\"
\"\" \"\""
}
Test__File_in_out()
{
local test_input=()
test_input+=($2)
local i=0
local res
local expectedres
local url
while [ $i -lt ${#test_input[@]} ]
do
local file=${test_input[$i]}
i=$(($i+1))
expectedres=${test_input[$i]}
Str__trim "$expectedres" expectedres "\""
local val
eval $1 "$file" val
#echo "$? ${test_res[$i]}"
[ "$val" == "$expectedres" ] && res=0 || res=1
Test__printResult $res "'$1' tests: test fail for value '$file' : got '$val' while '$expectedres' expected."
i=$(($i+1))
done
}
# --------------------------------------------------------------------------------------
# Net API
# --------------------------------------------------------------------------------------
Test_URL()
{
local test_urls=()
test_urls+=(
"https://@drive.google.com/" 1
"https://drive?.google&.com/" 1
"https://drive.google.com/" 0
"https://drive.google.com:80/" 0
"https://drive.google.com:8080/" 0
"https://drive.google.com" 0
"https://drive.google.com:80" 0
"http://drive.google.com" 0
"http://drive.google.com:80" 0
"http://drive.google.com/" 0
"http://drive.google.com:80/" 0
"http://drive.google.com//" 1
"drive.google.com" 0
"drivegoogle.com" 0
"drivegooglecom" 1
"a" 1
"" 1
"https://askubuntu.com/questions/" 1
)
local i=0
local res
local expectedres
local url
while [ $i -lt ${#test_urls[@]} ]
do
url=${test_urls[$i]}
i=$(($i+1))
expectedres=${test_urls[$i]}
Net__isHTTP "$url"
#echo "$? ${test_res[$i]}"
[ $? -eq $expectedres ] && res=0 || res=1
Test__printResult $res "'$url' was not detected as valid"
i=$(($i+1))
done
}
# --------------------------------------------------------------------------------------
# Progress bar test
# --------------------------------------------------------------------------------------
Test__ProgressBar()
{
local maxsteps=50
local i=0
while [ $i -le $maxsteps ] ; do
Term__updateProgressBar "sumo_hang_con" $maxsteps 1
i=$(($i+1))
done
maxsteps=71
i=0
while [ $i -le $maxsteps ] ; do
Term__updateProgressBar "sumo_hang_con2" $maxsteps 1
i=$(($i+1))
done
}
# --------------------------------------------------------------------------------------
# String tests
# --------------------------------------------------------------------------------------
Test__Str_squeeze_testOneString()
{
local res
local ret
$1 "$2" res
ret=$?
[ $ret -eq 0 ] && [ "$res" == "$3" ]
Test__printResult $? "GOT: '$res', EXPECTED: "$3"" "$ret"
}
Test__Str_escape_testOneString()
{
local res
local ret
$1 "$4" "$2" "$3" res
ret=$?
[ $ret -eq 0 ] && [ "$res" == "$5" ]
Test__printResult $? "$res" "$ret"
}
Test__Str_trim_testOneString()
{
local res
local retCode
$1 "$2" res
retCode=$?
#echo "$2 = $3??"
#_log_vars res
[ $retCode -eq 0 ] && [ "$res" == "$3" ]
Test__printResult $? "$res"
}
# MUST BE FORMALIZED
# MANUALL TESTED ONCE: OK
Test__Str_eraseCommonTail()
{
s1="/home/michel/riffian/Data/Data/admin/linux/testapp"
s2="/home/michel/Data/Data/admin/linux/testapp"
Str__eraseCommonTail s1 s2 && _log_vars s1 s2
s1="home/michel/riffian"
s2="admin/linux/testapp"
Str__eraseCommonTail s1 s2 && _log_vars s1 s2
s1="/home/michel/riffian"
s2="/home/michel/riffian"
Str__eraseCommonTail s1 s2 && _log_vars s1 s2
s1="/michel/riffian"
s2="/home/michel/riffian"
Str__eraseCommonTail s1 s2 && _log_vars s1 s2
}
Test__Str()
{
Test__Str_trim_testOneString Str__trim " A sentence with some spaces every where " "A sentence with some spaces every where" 5
Test__Str_trim_testOneString Str__trim "nochange" "nochange" 0
Test__Str_trim_testOneString Str__trim " 1 leading only" "1 leading only" 1
Test__Str_trim_testOneString Str__trim "1 trailing only " "1 trailing only" 1
Test__Str_trim_testOneString Str__trim "" "" 0 # empty string
Test__Str_trim_testOneString Str__trim " " "" 1 # single space
Test__Str_trim_testOneString Str__trimStart " A sentence with some spaces every where " "A sentence with some spaces every where " 3
Test__Str_trim_testOneString Str__trimStart "nochange" "nochange" 0
Test__Str_trim_testOneString Str__trimStart " 1 leading only" "1 leading only" 1
Test__Str_trim_testOneString Str__trimStart "1 trailing only " "1 trailing only " 0
Test__Str_trim_testOneString Str__trimStart "" "" 0 # empty string
Test__Str_trim_testOneString Str__trimStart " " "" 1 # single space
Test__Str_trim_testOneString Str__trimEnd " A sentence with some spaces every where " " A sentence with some spaces every where" 2
Test__Str_trim_testOneString Str__trimEnd "nochange" "nochange" 0
Test__Str_trim_testOneString Str__trimEnd " 1 leading only" " 1 leading only" 0
Test__Str_trim_testOneString Str__trimEnd "1 trailing only " "1 trailing only" 1
Test__Str_trim_testOneString Str__trimEnd "" "" 0 # empty string
Test__Str_trim_testOneString Str__trimEnd " " "" 1 # single space
Test__Str_escape_testOneString Str__escape " " § " A sentence with some spaces every where " "A§sentence§with§some§§spaces§every§§§where" 0
Test__Str_escape_testOneString Str__escape " " § "nochange" "nochange" 0
Test__Str_escape_testOneString Str__escape " " § " 1 leading only" "1§leading§only" 0
Test__Str_escape_testOneString Str__escape " " § "1 trailing only " "1§trailing§only" 0
Test__Str_escape_testOneString Str__escape " " § "" "" 0
Test__Str_escape_testOneString Str__escape " " § " " "" 0
Test__Str_squeeze_testOneString Str__squeeze " A sentence with some spaces every where " " A sentence with some spaces every where " 0
Test__Str_squeeze_testOneString Str__squeeze "nochange" "nochange" 0
Test__Str_squeeze_testOneString Str__squeeze " 1 leading only" " 1 leading only" 0
Test__Str_squeeze_testOneString Str__squeeze " a lot leading" " a lot leading" 0
Test__Str_squeeze_testOneString Str__squeeze "1 trailing only " "1 trailing only " 0
Test__Str_squeeze_testOneString Str__squeeze "a lot trailing " "a lot trailing " 0
Test__Str_squeeze_testOneString Str__squeeze "" "" 0
Test__Str_squeeze_testOneString Str__squeeze " " " " 0
Test__Str_squeeze_testOneString Str__squeeze " e " " e " 0
local test_string="/home/mike/windows/Users/vault/passwords.vera"
local expected="/home/mike/wi...passwords.vera"
local retval
Str__shrinkToMid test_string 30 "..."
if [ "$expected" == "$test_string" ] ; then retval=0; else retval=1; fi
Test__printResult "$retval" "Str__shrinkToMid: Got '$test_string' while '$expected' expected"
#echo "RESULT: '$test_string'"
if [ $Test__resultAll -eq 0 ] ; then
_log "All tests were successful"
else
_log_err "At least one test failed"
fi
}
# --------------------------------------------------------------------------------------
# Input tests
# --------------------------------------------------------------------------------------
# @param [1] command result 0
# @param [2] returned folder
Test__Input__dirpath_checkOutput()
{
local ret=1
if [ $1 -eq 0 ] ; then
if [ -d "$2" ] ; then
rmdir "$2"
echo "'$2' was entered !" >&2
ret=0
else
ret=1
fi
Test__printResult $1
else
echo "aborted!"
Test__printResult 0
ret=0
fi
return $ret
}
Test__Input__dirpath()
{
local dest=""
Input__dirpath "Enter mount point" "dir" 0 dest
Test__Input__dirpath_checkOutput $? "$dest"
}
Test__Input__dirpath_forcedinput()
{
local dest=""
Input__pushForcedInput "yes"
Input__dirpath "Enter mount point" "dir" 0 dest
Test__Input__dirpath_checkOutput $? "$dest"
}