@@ -205,9 +205,8 @@ func TestSaveWritesOwnerOnlyPermissions(t *testing.T) {
205205 assert .Equal (t , os .FileMode (0o600 ), info .Mode ().Perm (), "saved test data must be owner read/write only" )
206206}
207207
208- // nonStoppingT is a testing.TestingT whose FailNow returns instead of calling runtime.Goexit. The interface
209- // documents Goexit semantics, but TestingT exists so other harnesses can be plugged in, and this pins that a
210- // harness which does not stop cannot make this package do damage after it has reported a failure.
208+ // nonStoppingT is a TestingT whose FailNow returns rather than calling runtime.Goexit, so these tests can assert
209+ // that the package stops doing work after it reports a failure.
211210type nonStoppingT struct {
212211 failed bool
213212 msgs []string
@@ -225,14 +224,13 @@ func (r *nonStoppingT) Fatalf(f string, a ...any) {
225224 r .FailNow ()
226225}
227226
228- // unmarshalable has a func field, which encoding/json always rejects, so Save fails at the marshal step .
227+ // unmarshalable fails json.Marshal: encoding/json always rejects a func field .
229228type unmarshalable struct {
230229 Fn func ()
231230}
232231
233- // TestSaveWritesNothingAfterAMarshalFailure is the regression test. Before the explicit return, save reported the
234- // marshal failure and then carried on to os.WriteFile with a nil byte slice, leaving a zero byte file that a later
235- // stage would try to load.
232+ // Before the fix, a marshal failure was reported and os.WriteFile still ran with a nil slice, leaving a zero byte
233+ // file for a later stage to load.
236234func TestSaveWritesNothingAfterAMarshalFailure (t * testing.T ) {
237235 t .Parallel ()
238236
@@ -246,12 +244,12 @@ func TestSaveWritesNothingAfterAMarshalFailure(t *testing.T) {
246244 assert .NoFileExists (t , path , "no file may be written after a marshal failure" )
247245}
248246
249- // TestIsPresentDoesNotMaskAnUnreadableFile pins that a read failure reports the failure rather than quietly
250- // answering "absent", which would invite a caller to overwrite state it could not read.
247+ // A read failure must be reported, not reported as "absent", which would invite a caller to overwrite state it
248+ // could not read.
251249func TestIsPresentDoesNotMaskAnUnreadableFile (t * testing.T ) {
252250 t .Parallel ()
253251
254- // A directory where a file is expected: FileExistsE succeeds, os.ReadFile then fails with EISDIR.
252+ // A directory where a file is expected: FileExistsE succeeds, os.ReadFile fails with EISDIR.
255253 folder := t .TempDir ()
256254 path := teststate .FormatPath (folder , "IsADirectory.json" )
257255 require .NoError (t , os .MkdirAll (path , 0o755 ))
@@ -265,7 +263,7 @@ func TestIsPresentDoesNotMaskAnUnreadableFile(t *testing.T) {
265263 assert .Contains (t , recorder .msgs [0 ], "unexpected error" )
266264}
267265
268- // TestIsEmptyJSONReportsAParseFailure pins that invalid JSON is reported rather than being called empty.
266+ // Invalid JSON must be reported, not called empty.
269267func TestIsEmptyJSONReportsAParseFailure (t * testing.T ) {
270268 t .Parallel ()
271269
0 commit comments