-
Notifications
You must be signed in to change notification settings - Fork 27
/
coverage.sh
executable file
·49 lines (38 loc) · 1.16 KB
/
coverage.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
#!/usr/bin/env bash
SRC_DIR="./src"
TEST_DIR="./test"
COVERAGE_DIR="./coverage"
# Function to create the coverage directory
create_coverage_dir() {
mkdir -p "$COVERAGE_DIR"
}
# Function to run kcov with bats tests
run_kcov() {
local test_file; test_file="$1"
local src_file; src_file="$2"
local coverage_file; coverage_file="$COVERAGE_DIR/$(basename "$test_file" .bats).coverage"
if ! kcov --bash-dont-parse-binary-dir --include-path="$SRC_DIR" "$coverage_file" bats -t "$test_file"; then
printf "Error: kcov failed for %s\n" "$test_file" >&2
return 1
fi
}
# Main function
main() {
create_coverage_dir
local test_file; test_file="$TEST_DIR/test_smartmon.bats"
local src_file; src_file="$SRC_DIR/smartmon.sh"
if [[ ! -f "$test_file" ]]; then
printf "Error: Test file %s does not exist\n" "$test_file" >&2
return 1
fi
if [[ ! -f "$src_file" ]]; then
printf "Error: Source file %s does not exist\n" "$src_file" >&2
return 1
fi
if ! run_kcov "$test_file" "$src_file"; then
printf "Error: Failed to run kcov for %s\n" "$test_file" >&2
return 1
fi
printf "Coverage report generated in %s\n" "$COVERAGE_DIR"
}
main "$@"