From 9e6ee47bc97ec78807d1f7ea7d8e0c9ff6ed31fe Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sat, 22 Sep 2018 13:34:03 +0200 Subject: tests: detect and report chmod failures earlier Instead of reporting the consequence: matrix_test.go:906: modeHave 0664 != modeWant 0777 Report it if chmod itself fails, and also report the old file mode: matrix_test.go:901: chmod 000 -> 777 failed: bad file descriptor --- tests/matrix/matrix_test.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/matrix/matrix_test.go b/tests/matrix/matrix_test.go index 4938ba9..6ec41bd 100644 --- a/tests/matrix/matrix_test.go +++ b/tests/matrix/matrix_test.go @@ -896,11 +896,19 @@ func TestChmod(t *testing.T) { file.Close() modes := []os.FileMode{0777, 0707, 0606, 0666, 0444, 0000, 0111, 0123, 0321} for _, modeWant := range modes { - os.Chmod(path, modeWant) fi, err := os.Stat(path) if err != nil { t.Fatal(err) } + err = syscall.Chmod(path, uint32(modeWant)) + if err != nil { + t.Errorf("chmod %03o -> %03o failed: %v", fi.Mode(), modeWant, err) + continue + } + fi, err = os.Stat(path) + if err != nil { + t.Fatal(err) + } modeHave := fi.Mode() if modeHave != modeWant { t.Errorf("modeHave %#o != modeWant %#o", modeHave, modeWant) -- cgit v1.2.3