-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen_coverage
More file actions
executable file
·49 lines (41 loc) · 1.33 KB
/
open_coverage
File metadata and controls
executable file
·49 lines (41 loc) · 1.33 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
#!/usr/bin/env bash
if [[ -z "$1" ]]; then
echo "Usage: open_coverage <file_path|module_name>"
echo ""
echo "Examples:"
echo " open_coverage lib/my_app/users.ex"
echo " open_coverage MyApp.Users"
echo " open_coverage test/my_app/users_test.exs"
echo " open_coverage MyApp.UsersTest"
exit 1
fi
input="$1"
module_name=""
# Detect if input is a file path or module name
if [[ "$input" == *.ex ]] || [[ "$input" == *.exs ]]; then
# It's a file path - extract module name
if [[ ! -f "$input" ]]; then
echo "Error: File not found: $input"
exit 1
fi
# Extract module name from defmodule declaration
module_name=$(grep -m1 "defmodule" "$input" | sed -E 's/.*defmodule[[:space:]]+([A-Za-z0-9_.]+).*/\1/')
else
# It's a module name - use directly
module_name="$input"
fi
if [[ -z "$module_name" ]]; then
echo "Error: Could not determine module name from input"
exit 1
fi
# Remove Test suffix if present (for test modules/files)
module_name=$(echo "$module_name" | sed -E 's/Test$//')
# Construct the coverage file path
coverage_file="cover/Elixir.${module_name}.html"
if [[ ! -f "$coverage_file" ]]; then
echo "Error: Coverage file not found: $coverage_file"
echo "Make sure you've run: mix test --cover"
exit 1
fi
echo "Opening: $coverage_file"
open "$coverage_file"