TestWarningOnce tests that WarningOnce only shows each unique message once
(t *testing.T)
| 303 | |
| 304 | // TestWarningOnce tests that WarningOnce only shows each unique message once |
| 305 | func TestWarningOnce(t *testing.T) { |
| 306 | assert := asrt.New(t) |
| 307 | |
| 308 | // Capture output to test warning messages (warnings go to UserErr) |
| 309 | restoreOutput := util.CaptureUserErr() |
| 310 | |
| 311 | // Test that same message is only shown once |
| 312 | util.WarningOnce("test warning message") |
| 313 | util.WarningOnce("test warning message") |
| 314 | util.WarningOnce("test warning message") |
| 315 | |
| 316 | // Test that different messages are both shown |
| 317 | util.WarningOnce("different warning message") |
| 318 | |
| 319 | out := restoreOutput() |
| 320 | |
| 321 | // Should contain each unique message only once |
| 322 | assert.Equal(1, strings.Count(out, "test warning message")) |
| 323 | assert.Equal(1, strings.Count(out, "different warning message")) |
| 324 | |
| 325 | // Test with format arguments |
| 326 | restoreOutput = util.CaptureUserErr() |
| 327 | |
| 328 | util.WarningOnce("warning with %s", "arg1") |
| 329 | util.WarningOnce("warning with %s", "arg1") |
| 330 | util.WarningOnce("warning with %s", "arg2") |
| 331 | |
| 332 | out = restoreOutput() |
| 333 | |
| 334 | // Should show each formatted message once |
| 335 | assert.Equal(1, strings.Count(out, "warning with arg1")) |
| 336 | assert.Equal(1, strings.Count(out, "warning with arg2")) |
| 337 | } |
| 338 | |
| 339 | // TestSubtractSlices does simple test of SubtractSlices |
| 340 | func TestSubtractSlices(t *testing.T) { |
nothing calls this directly
no test coverage detected