-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex_integration_coveralls.ex
101 lines (87 loc) · 2.84 KB
/
ex_integration_coveralls.ex
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
defmodule ExIntegrationCoveralls do
@moduledoc """
Documentation for `ExIntegrationCoveralls`.
"""
alias ExIntegrationCoveralls.Cover
alias ExIntegrationCoveralls.Stats
alias ExIntegrationCoveralls.CoverageCiPoster
def execute(compiled_beam_dir_path) do
Cover.compile(compiled_beam_dir_path)
end
def exit do
Cover.stop()
end
def reset_coverage_data do
Cover.reset()
end
@doc """
Get an overall integration test coverage rate of an OTP application
## Parameters
- compile_time_source_lib_abs_path: source code project abs path in compile-time machine.
- source_lib_absolute_path: source code project abs path in run-time machine.
"""
def get_total_coverage(
compile_time_source_lib_abs_path \\ File.cwd!(),
source_code_abs_path \\ File.cwd!()
) do
stats =
Cover.modules(source_code_abs_path)
|> Stats.report(compile_time_source_lib_abs_path, source_code_abs_path)
|> Stats.transform_cov()
Map.get(stats, :coverage)
end
@doc """
Get an overall integration test coverage analysis report of an OTP application
## Parameters
- compile_time_source_lib_abs_path: source code project abs path in compile-time machine.
- source_lib_absolute_path: source code project abs path in run-time machine.
## Examples
%{
coverage: 50,
files: [
%Stats.Source{
coverage: 50,
filename: "test/fixtures/test.ex",
hits: 1,
misses: 1,
sloc: 2,
source: [
%Stats.Line{coverage: 0, source: "defmodule Test do"},
%Stats.Line{coverage: 1, source: " def test do"},
%Stats.Line{coverage: nil, source: " end"},
%Stats.Line{coverage: nil, source: "end"}
]
}
],
hits: 1,
misses: 1,
sloc: 2
}
"""
def get_coverage_report(
compile_time_source_lib_abs_path \\ File.cwd!(),
source_code_abs_path \\ File.cwd!()
) do
stats =
Cover.modules(source_code_abs_path)
|> Stats.report(compile_time_source_lib_abs_path, source_code_abs_path)
|> Stats.transform_cov()
stats
end
@doc """
Post coverage stats to User-Domain Cover CI Service.
## Parameters
- url: CI receive stats address
- extends_post_params: use to transform stats which CI service can acceptable form
- compile_time_source_lib_abs_path: source code project abs path in compile-time machine.
- source_lib_absolute_path: source code project abs path in run-time machine.
"""
def post_cov_stats_to_ud_ci(
url,
extends_post_params,
compile_time_source_lib_abs_path \\ File.cwd!(),
source_code_abs_path \\ File.cwd!()
) do
CoverageCiPoster.post_stats_to_cover_ci(url, extends_post_params, compile_time_source_lib_abs_path, source_code_abs_path)
end
end