File tree Expand file tree Collapse file tree 4 files changed +43
-9
lines changed Expand file tree Collapse file tree 4 files changed +43
-9
lines changed Original file line number Diff line number Diff line change
1
+ name : Tests
2
+
3
+ on :
4
+ pull_request :
5
+ push :
6
+ branches :
7
+ - main
8
+
9
+ jobs :
10
+ tests :
11
+ name : " Run tests"
12
+ runs-on : ubuntu-latest
13
+ steps :
14
+ - name : Checkout
15
+ uses : actions/checkout@v4
16
+
17
+ - name : " Install bashunit"
18
+ run : " curl -s https://bashunit.typeddevs.com/install.sh"
19
+
20
+ - name : " Test"
21
+ run : " ./lib/bashunit tests/*_test.sh"
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bash
2
2
3
- read -rp " Which folder you want to cruft ? " FOLDER
3
+ read -rp " Which folder you want to scan ? " FOLDER
4
4
5
5
if [[ ! -d " $FOLDER " ]]; then
6
6
echo " Folder you type is not exists."
@@ -12,10 +12,12 @@ read -rp "How many days files should be unmodified for to be considered cruft? "
12
12
readarray -t FILES < <( find " $FOLDER " -maxdepth 1 -atime +" $DAY " -type f)
13
13
14
14
if [ " ${# FILES[@]} " -eq 0 ]; then
15
- echo " The folder of $FOLDER does not contains any file "
15
+ echo " There is no files matched. "
16
16
exit 1
17
17
fi
18
18
19
19
for FILE in " ${FILES[@]} " ; do
20
20
rm " $FILE " ;
21
21
done
22
+
23
+ exit 0
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bash
2
2
3
3
# Set up a temporary test directory
4
- TEST_DIR=" ./tmp"
4
+ TEST_DIR=" tmp"
5
+ TEST_DIR_NOT_CREATED=" tmp_not_created"
5
6
6
7
function set_up() {
7
8
mkdir -p " $TEST_DIR "
8
9
9
- touch -d " 10 days ago" " $TEST_DIR /file_1.txt"
10
+ touch -d " 2 days ago" " $TEST_DIR /file_1.txt " " $TEST_DIR /file_2 .txt"
10
11
11
12
touch " $TEST_DIR /file_3.txt"
12
13
}
13
14
14
- function teat_down () {
15
+ function tear_down () {
15
16
rm -rf " $TEST_DIR "
16
17
}
17
18
18
19
function test_files_to_be_delete() {
19
- local result
20
- result=$( echo -e " $TEST_DIR \n9" | ./cruft_remover.sh)
20
+ local result=" $( echo -e " $TEST_DIR \n1" | ./cruft_remover.sh) "
21
21
22
- assert_not_contains $result " The folder of $TEST_DIR does not contains any file"
23
- assert_contains " $( ls $TEST_DIR ) " " file_3.txt"
22
+ assert_equals " $( ls $TEST_DIR ) " " file_3.txt"
23
+ }
24
+
25
+ function test_files_cannot_to_be_delete() {
26
+ local result=" $( echo -e " $TEST_DIR \n2" | ./cruft_remover.sh) "
27
+
28
+ assert_equals " $result " " There is no files matched."
29
+ }
30
+
31
+ function test_wrong_dir_to_scan() {
32
+ local result=" $( echo -e " $TEST_DIR_NOT_CREATED " | ./cruft_remover.sh) "
33
+
34
+ assert_equals " $result " " Folder you type is not exists."
24
35
}
You can’t perform that action at this time.
0 commit comments