Skip to content

Commit 781628a

Browse files
Update the baseline for measures when an excuse is given.
1 parent 8843dad commit 781628a

File tree

2 files changed

+52
-45
lines changed

2 files changed

+52
-45
lines changed

cmd/check_test.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ var checkStyleFileErr error
1717
func TestMain(m *testing.M) {
1818
checkStyleFile, checkStyleFileErr = os.Open("./testdata/output.xml")
1919

20-
os.Exit(m.Run())
20+
os.Exit(m.Run())
2121
}
2222

2323
func TestCheck(t *testing.T) {
2424
if testing.Verbose() {
2525
log.SetLogThreshold(log.LevelInfo)
2626
log.SetStdoutThreshold(log.LevelInfo)
2727
}
28-
28+
2929
createEmptyGitRepo(t)
3030

3131
runCheck(t, false, "")
@@ -53,7 +53,7 @@ func TestZeroMissing(t *testing.T) {
5353
log.SetLogThreshold(log.LevelInfo)
5454
log.SetStdoutThreshold(log.LevelInfo)
5555
}
56-
56+
5757
createEmptyGitRepo(t)
5858

5959
runCheck(t, true, "foo,5")
@@ -124,7 +124,7 @@ func TestCheckExcuse(t *testing.T) {
124124
log.SetStdoutThreshold(log.LevelInfo)
125125
}
126126

127-
createEmptyGitRepo(t)
127+
repo := createEmptyGitRepo(t)
128128

129129
runCheckP(t, "foobar", true, "foo,5")
130130
// Increase on "barfoo" prefix is okay
@@ -149,22 +149,32 @@ func TestCheckExcuse(t *testing.T) {
149149
if errCode != 50 {
150150
t.Fatalf("Check command passed unexpectedly!")
151151
}
152+
153+
runCommand(t, repo, exec.Command("git", "add", createFile(t, repo, "test2.txt").Name()))
154+
runCommand(t, repo, exec.Command("git", "commit", "-m", "Third Commit"))
155+
156+
runCheckP(t, "foobar", true, "foo,6")
157+
158+
runCommand(t, repo, exec.Command("git", "add", createFile(t, repo, "test3.txt").Name()))
159+
runCommand(t, repo, exec.Command("git", "commit", "-m", "Fourth Commit"))
160+
161+
runCheckP(t, "foobar", true, "foo,6")
152162
}
153163

154164
func TestCheckWithCheckstyleInput(t *testing.T) {
155165
if testing.Verbose() {
156166
log.SetLogThreshold(log.LevelInfo)
157167
log.SetStdoutThreshold(log.LevelInfo)
158168
}
159-
169+
160170
if checkStyleFileErr != nil {
161171
t.Fatalf("Failure opening test data", checkStyleFileErr)
162172
}
163173

164174
createEmptyGitRepo(t)
165175

166176
t.Logf("Running check command p: %s w: %t i: %s", "jshint", true, checkStyleFile)
167-
177+
168178
errCode := Check("jshint", 0, true, "checkstyle", false, checkStyleFile)
169179

170180
if errCode != 0 {

store/reader.go

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,22 @@ func CompareMeasures(prefix string, hash string, storedm []Measure, computedm []
160160
return computedm, errors.New("No stored measures to compare against.")
161161
}
162162

163-
failing := make([]string, 0)
163+
excuses, err := GetExclusions(prefix, hash)
164+
165+
if err != nil {
166+
return computedm, err
167+
}
168+
169+
log.INFO.Printf("Total excuses %s", excuses)
170+
171+
failing := make([]*Measure, 0)
164172
zeroMes := make([]Measure, 0)
165173

166174
i := 0
167175
j := 0
168176

177+
exc := 0
178+
169179
for i < len(storedm) && j < len(computedm) {
170180
stored := storedm[i]
171181
computed := computedm[j]
@@ -176,7 +186,7 @@ func CompareMeasures(prefix string, hash string, storedm []Measure, computedm []
176186
if zeroOnMissing {
177187
zeroMes = append(zeroMes, Measure{Name: stored.Name, Value: 0, Baseline: 0})
178188
} else {
179-
failing = append(failing, stored.Name)
189+
failing = append(failing, &stored)
180190
}
181191
i++
182192
} else if computed.Name < stored.Name {
@@ -191,7 +201,28 @@ func CompareMeasures(prefix string, hash string, storedm []Measure, computedm []
191201
// Compare the value
192202
if computed.Value > (stored.Baseline + slack) {
193203
log.ERROR.Printf("Measure rising: %s, delta %d", computed.Name, (computed.Value - stored.Baseline))
194-
failing = append(failing, computed.Name)
204+
205+
if exc < len(excuses) {
206+
ex := excuses[exc]
207+
208+
log.INFO.Printf("Checking excuses: %s %s", ex, computed)
209+
if ex < computed.Name {
210+
log.WARN.Printf("Exclusion found for not failing measure: %s", ex)
211+
exc++
212+
failing = append(failing, &computed)
213+
} else if computed.Name < ex {
214+
log.ERROR.Printf("No exclusion for failing measure: %s", computed.Name)
215+
failing = append(failing, &computed)
216+
} else {
217+
log.WARN.Printf("Exclusion found for failing measure: %s", computed.Name)
218+
computed.Baseline = computed.Value
219+
computedm[j].Baseline = computed.Value
220+
exc++
221+
}
222+
} else {
223+
failing = append(failing, &computed)
224+
}
225+
195226
}
196227
i++
197228
j++
@@ -204,7 +235,7 @@ func CompareMeasures(prefix string, hash string, storedm []Measure, computedm []
204235
if zeroOnMissing {
205236
zeroMes = append(zeroMes, Measure{Name: stored.Name, Value: 0, Baseline: 0})
206237
} else {
207-
failing = append(failing, stored.Name)
238+
failing = append(failing, &stored)
208239
}
209240
i++
210241
}
@@ -216,41 +247,7 @@ func CompareMeasures(prefix string, hash string, storedm []Measure, computedm []
216247
}
217248

218249
if len(failing) > 0 {
219-
log.INFO.Printf("Checking for excuses")
220-
221-
exclusions, err := GetExclusions(prefix, hash)
222-
223-
if err != nil {
224-
return computedm, err
225-
}
226-
227-
log.INFO.Printf("Total excuses %s", exclusions)
228-
229-
i = 0
230-
j = 0
231-
232-
missingexclusion := false
233-
234-
for i < len(exclusions) && j < len(failing) {
235-
ex := exclusions[i]
236-
fail := failing[j]
237-
log.INFO.Printf("Checking excuses: %s %s", ex, fail)
238-
if ex < fail {
239-
log.WARN.Printf("Exclusion found for not failing measure: %s", ex)
240-
i++
241-
} else if fail < ex {
242-
log.ERROR.Printf("No exclusion for failing measure: %s", fail)
243-
missingexclusion = true
244-
j++
245-
} else {
246-
i++
247-
j++
248-
}
249-
}
250-
251-
if missingexclusion || j < len(failing) {
252-
return computedm, errors.New("One or more metrics currently failing.")
253-
}
250+
return computedm, errors.New("One or more metrics currently failing.")
254251
}
255252

256253
computedm = append(computedm, zeroMes...)

0 commit comments

Comments
 (0)