Skip to content

Commit 89b34a5

Browse files
committed
fix: improve clean handling
1 parent 30c4f71 commit 89b34a5

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

snaps/clean.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,20 @@ func Clean(m *testing.M, opts ...CleanOpts) (bool, error) {
135135
}
136136

137137
// getTestID will return the testID if the line is in the form of [Test... - number]
138-
func getTestID(b []byte) (string, bool) {
138+
func getTestID(b []byte) (string, string, bool) {
139139
if len(b) == 0 {
140-
return "", false
140+
return "", "", false
141141
}
142142

143143
// needs to start with [Test and end with ]
144144
if !bytes.HasPrefix(b, []byte("[Test")) || b[len(b)-1] != ']' {
145-
return "", false
145+
return "", "", false
146146
}
147147

148148
// needs to contain at least one ' - ' seperator
149149
firstSeparator := bytes.Index(b, []byte(" - "))
150150
if firstSeparator == -1 {
151-
return "", false
151+
return "", "", false
152152
}
153153

154154
// if there is a label, there will be a second seperator
@@ -160,10 +160,10 @@ func getTestID(b []byte) (string, bool) {
160160

161161
// needs to have a number after the first separator
162162
if !isNumber(b[firstSeparator+3 : secondSeparator]) {
163-
return "", false
163+
return "", "", false
164164
}
165165

166-
return string(b[1 : len(b)-1]), true
166+
return string(b[1 : len(b)-1]), string(b[1 : secondSeparator]), true
167167
}
168168

169169
func isNumber(b []byte) bool {
@@ -266,14 +266,14 @@ func examineSnaps(
266266
for s.Scan() {
267267
b := s.Bytes()
268268
// Check if line is a test id
269-
testID, match := getTestID(b)
269+
testIDWithLabel, testIDWithoutLabel, match := getTestID(b)
270270
if !match {
271271
continue
272272
}
273-
testIDs = append(testIDs, testID)
273+
testIDs = append(testIDs, testIDWithLabel)
274274

275-
if !registeredTests.Has(testID) && !testSkipped(testID, runOnly) {
276-
obsoleteTests = append(obsoleteTests, testID)
275+
if !registeredTests.Has(testIDWithoutLabel) && !testSkipped(testIDWithoutLabel, runOnly) {
276+
obsoleteTests = append(obsoleteTests, testIDWithoutLabel)
277277
needsUpdating = true
278278

279279
removeSnapshot(s)
@@ -284,7 +284,7 @@ func examineSnaps(
284284
line := s.Bytes()
285285

286286
if bytes.Equal(line, endSequenceByteSlice) {
287-
tests[testID] = data.String()
287+
tests[testIDWithLabel] = data.String()
288288

289289
data.Reset()
290290
break

snaps/clean_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ func TestGetTestID(t *testing.T) {
550550
// indexing beyond the capacity will cause test to panic
551551
b := make([]byte, 0, len(tc.input))
552552
b = append(b, []byte(tc.input)...)
553-
id, ok := getTestID(b)
553+
id, _, ok := getTestID(b)
554554

555555
test.Equal(t, tc.valid, ok)
556556
test.Equal(t, tc.expectedID, id)

0 commit comments

Comments
 (0)