Skip to content

Commit

Permalink
option to warn only on zero cov
Browse files Browse the repository at this point in the history
  • Loading branch information
illabo committed Oct 24, 2020
1 parent eeb10b7 commit a565274
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions .xcccr.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ FilterPaths = ["Tests","UITests","Constants.swift"] # If a path contains one o
FilterPattern = "[\\S\\s]*secret\\.json$" # Go flavored regex (non-PCRE!). Please check https://golang.org/pkg/regexp/ for more info. When used in config escape characters should be escaped twice for config parsing (unfortunately). Please note that if regex is used targets filtering has no effect.
InvertFilter = false # Set `false` to disallow targets and paths in filters. Set `true` to allow only targets and paths in filters. Default `false`.
IncludeMasked = false # Skip recalculating coverage, just read from xccov report regardless masked (filtered) targets and paths. Default `false`.
ZeroWarnOnly = false # Don't error on 0% coverage, produce warning only.
MeterLOC = false # Set `false` for coverage percent and `true` for number of LOCs e.g. 42/13 (now/was). Default `false`.
Tolerance = 5 # Percent. Default 0.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This dead simple tool only works with Apple's `xccov` generated code coverage re
`-i` | Invert filter. Applied to -rg and to targets/paths filter lists in config. If no filters supplied prevents reporting allowing nothing.
`-m` | Include masked files coverage in total metrics. If true warnings would be produced only for unfiltered targets/paths, but total coverage would be reported for all the files as listed in original xccov json.
`-loc` | Count covered LOCs diff instead of percent coverage.
`-z` | Don't error on 0% coverage, produce warning only.
`-cfg` | Path to config. Parameters passed with the flags have precedence and overrides the values stored in config. Config passed with this flag overrides default config at `.xcccr.toml`. If there aren't any config default values are used.


Expand Down
4 changes: 2 additions & 2 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- This release only tested manually. Help wanted to cover with tests.
- Some minor bugs are expected.
- No breaking changes. New `ZeroWarnOnly` parameter added to config. Please check examples.
- This release still only tested manually. Help wanted to cover with tests.
8 changes: 8 additions & 0 deletions configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func prepareRunConditions() (rnCnd *RunConditions, err error) {
false,
"Count covered LOCs diff instead of percent coverage.",
)
zeroWarn := flag.Bool(
"z",
false,
"Don't error on 0%% coverage, produce warning only.",
)
cfgPth := flag.String(
"cfg",
"",
Expand Down Expand Up @@ -103,6 +108,9 @@ func prepareRunConditions() (rnCnd *RunConditions, err error) {
if *meterLOC {
cfg.MeterLOC = true
}
if *zeroWarn {
cfg.ZeroWarnOnly = true
}
cfg.ProjectPath = *projRoot
if cfg.FilterPattern != "" {
re, e := regexp.Compile(cfg.FilterPattern)
Expand Down
23 changes: 19 additions & 4 deletions reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,26 @@ func produceVerdict(cfg *Config, tu *DiffUnit, last, current *XCCoverageReport)
lstCovMsg = "last coverage is unavailable"
}
covMsg = fmt.Sprintf("%s: %s, %s.", covMsg, curCovMsg, lstCovMsg)
if lastPct > currentPct+cfg.Tolerance || currentPct == 0 {
fmt.Printf("::error::%s\n", covMsg)
os.Exit(1)
if lastPct > currentPct+cfg.Tolerance {
emmitError(covMsg)
}
fmt.Println(covMsg)
currentPctZero := currentPct == 0
if currentPctZero && cfg.ZeroWarnOnly == false {
emmitError(covMsg)
}
if currentPctZero {
covMsg = fmt.Sprintf("::warning::%s", covMsg)
}
exitMessage(covMsg)
}

func emmitError(message string) {
fmt.Printf("::error::%s\n", message)
os.Exit(1)
}

func exitMessage(message string) {
fmt.Println(message)
os.Exit(0)
}

Expand Down
1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Config struct {
FilterPattern string
InvertFilter bool
IncludeMasked bool
ZeroWarnOnly bool
MeterLOC bool
Tolerance int
}
Expand Down

0 comments on commit a565274

Please sign in to comment.