Skip to content

Commit fda8b24

Browse files
authored
Merge pull request #24 from gilmoreorless/issue-22-index-out-of-range
Fix index out of range error in check command
2 parents 51db6c1 + c4b4c7f commit fda8b24

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

cmd/check_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,42 @@ func TestZeroMissing(t *testing.T) {
7575
}
7676
}
7777

78+
// Regression test for https://github.com/iangrunert/git-ratchet/issues/22
79+
func TestAddRemove(t *testing.T) {
80+
if testing.Verbose() {
81+
log.SetLogThreshold(log.LevelInfo)
82+
log.SetStdoutThreshold(log.LevelInfo)
83+
}
84+
85+
createEmptyGitRepo(t)
86+
87+
runCheck(t, true, "measure-A,5")
88+
89+
t.Logf("Running check command with added measure w: %t z: %t i: %s", false, false, "measure-A,5\nmeasure-B,4")
90+
91+
errCode := Check("", 0, false, true, "csv", false, strings.NewReader("measure-A,5\nmeasure-B,4"))
92+
93+
if errCode != 0 {
94+
t.Fatalf("Check command failed unexpectedly!")
95+
}
96+
97+
t.Logf("Running check command with added and removed measures w: %t z: %t i: %s", false, false, "measure-B,4\nmeasure-C,3")
98+
99+
errCode = Check("", 0, false, true, "csv", false, strings.NewReader("measure-B,4\nmeasure-C,3"))
100+
101+
if errCode != 50 {
102+
t.Fatalf("Check command passed unexpectedly!")
103+
}
104+
105+
t.Logf("Running check command with added and removed measures w: %t z: %t i: %s", false, true, "measure-B,4\nmeasure-C,3")
106+
107+
errCode = Check("", 0, false, true, "csv", true, strings.NewReader("measure-B,4\nmeasure-C,3"))
108+
109+
if errCode != 0 {
110+
t.Fatalf("Check command failed unexpectedly!")
111+
}
112+
}
113+
78114
func TestCheckPrefix(t *testing.T) {
79115
if testing.Verbose() {
80116
log.SetLogThreshold(log.LevelInfo)

store/reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func CompareMeasures(prefix string, hash string, storedm []Measure, computedm []
247247
}
248248

249249
for j < len(computedm) {
250-
computed := computedm[i]
250+
computed := computedm[j]
251251
log.WARN.Printf("New measure found: %s", computed.Name)
252252
j++
253253
}

0 commit comments

Comments
 (0)