-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_definitions.sh
executable file
·126 lines (106 loc) · 2.6 KB
/
test_definitions.sh
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
#!/bin/sh
output_file="./_test_output"
run_with_parameters_in_the_background () {
echo "./fwa $* > $output_file"
./fwa $* > $output_file &
sleep 1
return 0
}
kill_background_fwa () {
pkill fwa
}
run_with_parameters () {
./fwa $* > $output_file
return $?
}
test_that_it_stops_if_its_unable_to_open_a_file () {
existing_file=`mktemp` || exit 1
run_with_parameters "$existing_file definitely_not_existing_file"
return 0
}
test_that_it_prints_out_usage_information_without_files_to_watch () {
run_with_parameters
grep -i usage $output_file
return $?
}
test_that_it_prints_out_usage_information_if_the_dash_h_option_is_passed_in () {
run_with_parameters "-h"
grep -i usage $output_file
return $?
}
test_that_it_prints_out_usage_information_if_the_help_option_is_passed_in () {
run_with_parameters "--help"
grep -i usage $output_file
return $?
}
test_that_it_prints_out_a_single_files_name_if_it_is_changed () {
changed_file=`mktemp` || exit 1
unchanged_file=`mktemp` || exit 1
run_with_parameters_in_the_background "$unchanged_file $changed_file"
echo "some test" > $changed_file
sleep 1
kill_background_fwa
if grep $unchanged_file $output_file; then
return 1
fi
if grep $changed_file $output_file; then
return 0
fi
return 1
}
test_that_it_prints_out_each_changed_files_name () {
file_1=`mktemp` || exit 1
file_2=`mktemp` || exit 1
run_with_parameters_in_the_background "$file_1 $file_2"
echo "some test" > $file_1
echo "some test" > $file_2
sleep 1
kill_background_fwa
if grep $file_1 $output_file && grep $file_2 $output_file; then
return 0
fi
return 1
}
test_that_it_prints_out_fast_file_changes_only_once () {
file_1=`mktemp` || exit 1
run_with_parameters_in_the_background "$file_1"
echo "some test" > $file_1
echo "some test" > $file_1
sleep 1
kill_background_fwa
number_of_changes=`grep $file_1 $output_file | wc -l`
if [ $number_of_changes -lt 2 ]; then
return 0
fi
return 1
}
test_that_it_continues_to_watch_files_after_deletion_and_recreation () {
file=`mktemp` || exit 1
run_with_parameters_in_the_background "$file"
rm -f $file
touch $file
sleep 1
touch $file
sleep 1
kill_background_fwa
number_of_changes=`grep $file $output_file | wc -l`
if [ $number_of_changes -lt 2 ]; then
return 1
fi
return 0
}
test_that_it_continues_to_watch_files_after_deletion () {
file_1=`mktemp` || exit 1
file_2=`mktemp` || exit 1
run_with_parameters_in_the_background "$file_1 $file_2"
rm -f $file_1
sleep 2
touch $file_2
sleep 1
kill_background_fwa
number_of_changes=`grep $file_2 $output_file | wc -l`
if [ $number_of_changes -lt 1 ]; then
return 1
fi
return 0
}