Skip to content

Commit 1d4e6c5

Browse files
adding test bmtTest function
1 parent 55ee77b commit 1d4e6c5

File tree

17 files changed

+550
-298
lines changed

17 files changed

+550
-298
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ A script to print library meta data is also installed.
100100
| bmtData | btmDataFunc | 601-607 | Data related | [bmtData help file](documentation/bmtData.md)|
101101
| bmtTime | btmTimeFunc | 701-709 | Time related | [bmtTime help file](documentation/bmtTime.md)|
102102
| bmtMisc | bmtMiscFunc | 801-804 | Miscellaneous | [bmtMisc help file](documentation/bmtMisc.md)|
103+
| bmtTest | bmtTestFunc | 901 | Test the library | [bmtTest help file](documentation/bmtTest.md)|
103104

104105
The library contains eight section's, Each section has one file with one function.
105106
Which contains 50 sub-sections in total.
@@ -116,3 +117,7 @@ Example
116117
Output of basic example file in example folder, showing basic usage.
117118

118119
![ScreenShot](https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/master/documentation/screenshot/example.png)
120+
121+
Output report of test section.
122+
123+
![ScreenShot](https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/master/documentation/screenshot/test.png)

documentation/bmtFiles.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
**Section Five, File**
66

7-
* 501 Make and enter a formatted directory
8-
* 502 Check if directory exists and empty
7+
* 501 Check if directory exists and empty
8+
* 502 Make and enter a formatted directory
99
* 503 Directory exists
1010
* 504 File exists
1111
* 505 Device exists
@@ -86,9 +86,9 @@ bmtFilesFunc getfilesizebytes "/foo/foo.txt"
8686

8787
509) Display mime type of input file
8888
Returns 4 If file/directory does not exist. , 3 If file or mimetype command not found in system.
89-
2 if missing arguments.
89+
2 if missing arguments, 0 for success.
9090

9191
```sh
92-
echo "$(bmtFilesFunc getmimetype "$TESTOBJECTS/full.txt")" >> /tmp/mytempfile123.txt
92+
bmtFilesFunc getmimetype "$TESTOBJECTS/full.txt" >> /tmp/mytempfile123.txt
9393
echo $?
9494
```

documentation/bmtPrompt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bmtPromptFunc yesno yes
4949
```
5050
Returns 0 for yes , 2 for no , 50 for bad user option
5151

52-
204) Yes-no prompt [Y/n] where no is default
52+
204) Yes-no prompt [Y/n] where yes is default
5353

5454
Keyword is yesno , returns codes based on user input
5555
second option is no

documentation/bmtTest.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
| Library file | Function | Sections | Content | help file |
2+
| ---- | ---- | ---- | ---- | ---- |
3+
| bmtTest | bmtTestFunc | 901 | Test | bmtTest.md |
4+
5+
**Section nine, Time**
6+
7+
Used to conduct semi-automated testing and test report of library function.
8+

documentation/screenshot/test.png

16 KB
Loading

lib/bmtTest

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
3+
# === HEADER ===
4+
#FileName: bmtTest
5+
#Function: Contains a test function for automated testing library
6+
#library name: bashmultitool
7+
#URL: https://github.com/gavinlyonsrepo/BashMultiTool
8+
9+
# === FUNCTIONS ===
10+
11+
function bmtTestFunc
12+
{
13+
14+
local urlTestDir="$HOME/Documents/Tech/Scripts/BashMultiTool/test/testlog/"
15+
mkdir -p "$urlTestDir"
16+
local TestFile="test"
17+
18+
case "$3" in
19+
START) # Start message
20+
bmtPrintFunc norm "Delete log file if exists"
21+
rm -iv "$urlTestDir""$TestFile.log"
22+
bmtLinuxFunc log "NOTICE" "Run Start" "$TestFile" "$urlTestDir" ;;
23+
END)
24+
# End message
25+
if [ "$3" == "END" ]
26+
then
27+
bmtLinuxFunc log "NOTICE" "Run Over" "$TestFile" "$urlTestDir"
28+
bmtPrintFunc norm "=== End Automatic Tests ==="
29+
bmtPromptFunc anykey " " norm
30+
clear
31+
bmtMiscFunc title 14 226 "#" " BashMultiTool library :: Test Results :: $TestFile.log "
32+
bmtPromptFunc eventstatus "Test Total" "$(grep -c "Test" "$urlTestDir""$TestFile.log" )" b_white
33+
bmtPromptFunc eventstatus "Test Passed" "$(grep -c "PASSED" "$urlTestDir""$TestFile.log" )" b_green
34+
bmtPromptFunc eventstatus "Test Failed" "$(grep -c "FAILED" "$urlTestDir""$TestFile.log" )" b_red
35+
bmtPromptFunc eventstatus "Test Errors" "$(grep -c "ERROR" "$urlTestDir""$TestFile.log" )" b_yellow
36+
bmtPromptFunc line "="
37+
38+
# View File
39+
bmtPromptFunc anykey "and view test log file." norm
40+
cat "$urlTestDir""$TestFile.log"
41+
bmtPromptFunc line "="
42+
bmtPromptFunc anykey "and delete test log file." norm
43+
#remove file?
44+
rm -iv "$urlTestDir""$TestFile.log"
45+
bmtPromptFunc line "="
46+
fi
47+
;;
48+
*)
49+
if [ "$4" == "NOAUTO" ] # non -automatic test
50+
then
51+
local yesnoVar=""
52+
while true; do
53+
bmtPrintFunc norm "Did Test $3 pass? [y/n/q]"
54+
read -r yesnoVar
55+
case $yesnoVar in
56+
[Yy]*) bmtLinuxFunc log "PASSED" "Test $3 Result :: User Check" "$TestFile" "$urlTestDir" && return 0;;
57+
[Nn]*) bmtLinuxFunc log "FAILED" "Test $3 Result :: User Check" "$TestFile" "$urlTestDir" && return 2;;
58+
[Qq]*)
59+
bmtLinuxFunc log "ERROR" "User aborted Test at $3" "$TestFile" "$urlTestDir"
60+
return 3
61+
;;
62+
*) bmtPrintFunc b_yellow "Please answer: (y/Y for yes) OR (n/N for no) OR (q/Q to quit)!";;
63+
esac
64+
done
65+
else
66+
if [ "$1" -eq "$2" ] # Automatic test
67+
then
68+
bmtLinuxFunc log "PASSED" "Test $3 Result :: $1 $2" "$TestFile" "$urlTestDir"
69+
return 0
70+
else
71+
bmtLinuxFunc log "FAILED" "Test $3 Result :: $1 $2" "$TestFile" "$urlTestDir"
72+
return 2
73+
fi
74+
fi
75+
;;
76+
esac
77+
}
78+

test/testObjects/dummyfile.foofoo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

test/testTest.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# === HEADER ===
4+
5+
#Name: testTest.sh
6+
#Description: File to run Automatic tests on library bashmultitool
7+
#URL: https://github.com/gavinlyonsrepo/BashMultiTool
8+
9+
# === MAIN CODE ===
10+
clear
11+
printf "%s\n" "=== Start Automatic Tests === "
12+
printf "%s\n" "=== Start Print Tests === " # Section 1
13+
./testprint.sh
14+
printf "%s\n" "=== Start Prompt Tests === " # Section 2
15+
./testprompt.sh
16+
printf "|\n%s\n" "=== Start Network Tests === " # Section 3
17+
./testnetwork.sh
18+
printf "\n%s\n" "=== Start Linux Tests === " # Section 4
19+
./testlinux.sh
20+
printf "\n%s\n" "=== Start Files Tests === " # Section 5
21+
./testfile.sh
22+
printf "\n%s\n" "=== Start Data Tests === " # Section 6
23+
./testdata.sh
24+
printf "\n%s\n" "=== Start Time Tests === " # Section 7
25+
./testtime.sh
26+
printf "\n%s\n" "=== Start Misc Tests === " # Section 8
27+
./testmisc.sh
28+
printf "\n"
29+
# === EOF ===

test/testdata.sh

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,63 +20,69 @@ done
2020
function Test_Func
2121
{
2222
echo "Error handling check"
23-
bmtDataFunc foo
24-
echo " "
23+
bmtDataFunc foofoo
24+
bmtTestFunc "$?" 255 "60E-a"
25+
bmtDataFunc
26+
bmtTestFunc "$?" 255 "60E-b"
2527

26-
# intcheck
27-
echo "601"
28-
echo "Enter an integer"
28+
# intcheck 601
29+
printf "\n%s\n" "601-a Enter an integer"
2930
read -r ID
3031
bmtDataFunc intcheck "$ID"
31-
echo "$?"
32-
echo " "
32+
bmtTestFunc "$?" 0 "601-a"
33+
34+
printf "\n%s\n" "601-b Enter a NON integer"
35+
read -r ID
36+
bmtDataFunc intcheck "$ID"
37+
bmtTestFunc "$?" 2 "601-b"
38+
39+
## alphanumeric 602
40+
printf "\n%s\n" "602-a Enter an alpha numeric string"
41+
read -r ID1
42+
bmtDataFunc alphanumcheck "$ID1"
43+
bmtTestFunc "$?" 0 "602-a"
3344

34-
## alphanumeric check 2
35-
echo "602"
36-
echo "Enter an alpha numeric string"
45+
printf "\n%s\n" "602-b Enter a NON alpha numeric string"
3746
read -r ID1
3847
bmtDataFunc alphanumcheck "$ID1"
39-
echo "$?"
40-
echo " "
48+
bmtTestFunc "$?" 2 "602-b"
4149

42-
## alphanuc check 3
43-
echo "603"
44-
echo "Enter an alpha string"
50+
## alpha check 603
51+
printf "\n%s\n" "603-a Enter an alphabetical string"
52+
read -r ID2
53+
bmtDataFunc alphacheck "$ID2"
54+
bmtTestFunc "$?" 0 "603-a"
55+
56+
printf "\n%s\n" "603-b Enter an NON alphabetical string"
4557
read -r ID2
4658
bmtDataFunc alphacheck "$ID2"
47-
echo "$?"
48-
echo " "
59+
bmtTestFunc "$?" 2 "603-b"
4960

50-
## lowercase 4
51-
echo "604"
52-
echo "lowercasetest"
61+
# lowercase
62+
printf "\n%s\n" "604 lowercase test"
5363
result=$(bmtDataFunc lowercase "TEST") # or result=`myfunc`
54-
echo "$result"
55-
echo " "
64+
printf "%s\n" "$result"
65+
bmtTestFunc 1 1 "604-a" "NOAUTO"
5666

57-
##uppercase 5
58-
echo "605"
59-
echo "uppercasetest"
67+
#uppercase
68+
printf "\n%s\n" "605 uppercase test"
6069
result1=$(bmtDataFunc uppercase "test")
61-
echo "$result1"
62-
echo " "
70+
printf "%s\n" "$result1"
71+
bmtTestFunc 1 1 "605-a" "NOAUTO"
6372

64-
## trim 6
65-
echo "606"
66-
echo "trim test"
73+
# trim
74+
printf "\n%s\n" "606 trim test"
6775
mytrim=" test "
6876
result2=$(bmtDataFunc trim "$mytrim")
69-
echo "$result2"
70-
echo " "
77+
printf "%s\n" "$result2"
78+
bmtTestFunc 1 1 "606-a" "NOAUTO"
7179

72-
## string length 7
73-
echo "607 string length test"
80+
# string length
81+
printf "\n%s\n" "607 string length test"
7482
bmtDataFunc strlen "test string 123" # 15
75-
echo $?
76-
echo " "
83+
bmtTestFunc "$?" 15 "607-a"
7784
bmtDataFunc strlen "" #report 250 error
78-
echo $?
79-
echo " "
85+
bmtTestFunc "$?" 250 "607-b"
8086
}
8187

8288
Test_Func

0 commit comments

Comments
 (0)