diff --git a/README.md b/README.md index f581155..1afeba3 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ There are five key packages, :ballot_box_with_check: v1.11.0 adds an ErrorAs helper - FS examples are more reliable + - Examples run on non-Unix OS when possible :ballot_box_with_check: v1.10.0 adds a `util` package for helpers that return values diff --git a/examples_test.go b/examples_test.go index bf873e9..d6054ac 100644 --- a/examples_test.go +++ b/examples_test.go @@ -1,8 +1,6 @@ // Copyright (c) The Test Authors // SPDX-License-Identifier: MPL-2.0 -//go:build unix - package test import ( @@ -10,7 +8,6 @@ import ( "fmt" "io/fs" "math" - "os" "regexp" "strconv" "strings" @@ -226,11 +223,6 @@ func ExampleDescendingLess() { // Output: } -func ExampleDirExists() { - DirExists(t, "/tmp") - // Output: -} - func ExampleDirExistsFS() { fsys := fstest.MapFS{ "foo": &fstest.MapFile{Mode: fs.ModeDir}, @@ -239,11 +231,6 @@ func ExampleDirExistsFS() { // Output: } -func ExampleDirNotExists() { - DirNotExists(t, "/does/not/exist") - // Output: -} - func ExampleDirNotExistsFS() { fsys := fstest.MapFS{} DirNotExistsFS(t, fsys, "does/not/exist") @@ -339,12 +326,6 @@ func ExampleFalse() { // Output: } -func ExampleFileContains() { - _ = os.WriteFile("/tmp/example", []byte("foo bar baz"), fs.FileMode(0600)) - FileContains(t, "/tmp/example", "bar") - // Output: -} - func ExampleFileContainsFS() { fsys := fstest.MapFS{ "example": &fstest.MapFile{ @@ -355,12 +336,6 @@ func ExampleFileContainsFS() { // Output: } -func ExampleFileExists() { - _ = os.WriteFile("/tmp/example", []byte{}, fs.FileMode(0600)) - FileExists(t, "/tmp/example") - // Output: -} - func ExampleFileExistsFS() { fsys := fstest.MapFS{ "example": &fstest.MapFile{}, @@ -369,12 +344,6 @@ func ExampleFileExistsFS() { // Output: } -func ExampleFileMode() { - _ = os.WriteFile("/tmp/example_fm", []byte{}, fs.FileMode(0600)) - FileMode(t, "/tmp/example_fm", fs.FileMode(0600)) - // Output: -} - func ExampleFileModeFS() { fsys := fstest.MapFS{ "example": &fstest.MapFile{Mode: 0600}, @@ -383,11 +352,6 @@ func ExampleFileModeFS() { // Output: } -func ExampleFileNotExists() { - FileNotExists(t, "/tmp/not_existing_file") - // Output: -} - func ExampleFileNotExistsFS() { fsys := fstest.MapFS{} FileNotExistsFS(t, fsys, "not_existing_file") diff --git a/examples_unix_test.go b/examples_unix_test.go new file mode 100644 index 0000000..5addf47 --- /dev/null +++ b/examples_unix_test.go @@ -0,0 +1,44 @@ +// Copyright (c) The Test Authors +// SPDX-License-Identifier: MPL-2.0 + +//go:build unix + +package test + +import ( + "io/fs" + "os" +) + +func ExampleDirExists() { + DirExists(t, "/tmp") + // Output: +} + +func ExampleDirNotExists() { + DirNotExists(t, "/does/not/exist") + // Output: +} + +func ExampleFileContains() { + _ = os.WriteFile("/tmp/example", []byte("foo bar baz"), fs.FileMode(0600)) + FileContains(t, "/tmp/example", "bar") + // Output: +} + +func ExampleFileExists() { + _ = os.WriteFile("/tmp/example", []byte{}, fs.FileMode(0600)) + FileExists(t, "/tmp/example") + // Output: +} + +func ExampleFileMode() { + _ = os.WriteFile("/tmp/example_fm", []byte{}, fs.FileMode(0600)) + FileMode(t, "/tmp/example_fm", fs.FileMode(0600)) + // Output: +} + +func ExampleFileNotExists() { + FileNotExists(t, "/tmp/not_existing_file") + // Output: +} diff --git a/must/examples_test.go b/must/examples_test.go index ad7bc55..8719d3e 100644 --- a/must/examples_test.go +++ b/must/examples_test.go @@ -3,8 +3,6 @@ // Copyright (c) The Test Authors // SPDX-License-Identifier: MPL-2.0 -//go:build unix - package must import ( @@ -12,7 +10,6 @@ import ( "fmt" "io/fs" "math" - "os" "regexp" "strconv" "strings" @@ -228,11 +225,6 @@ func ExampleDescendingLess() { // Output: } -func ExampleDirExists() { - DirExists(t, "/tmp") - // Output: -} - func ExampleDirExistsFS() { fsys := fstest.MapFS{ "foo": &fstest.MapFile{Mode: fs.ModeDir}, @@ -241,11 +233,6 @@ func ExampleDirExistsFS() { // Output: } -func ExampleDirNotExists() { - DirNotExists(t, "/does/not/exist") - // Output: -} - func ExampleDirNotExistsFS() { fsys := fstest.MapFS{} DirNotExistsFS(t, fsys, "does/not/exist") @@ -341,12 +328,6 @@ func ExampleFalse() { // Output: } -func ExampleFileContains() { - _ = os.WriteFile("/tmp/example", []byte("foo bar baz"), fs.FileMode(0600)) - FileContains(t, "/tmp/example", "bar") - // Output: -} - func ExampleFileContainsFS() { fsys := fstest.MapFS{ "example": &fstest.MapFile{ @@ -357,12 +338,6 @@ func ExampleFileContainsFS() { // Output: } -func ExampleFileExists() { - _ = os.WriteFile("/tmp/example", []byte{}, fs.FileMode(0600)) - FileExists(t, "/tmp/example") - // Output: -} - func ExampleFileExistsFS() { fsys := fstest.MapFS{ "example": &fstest.MapFile{}, @@ -371,12 +346,6 @@ func ExampleFileExistsFS() { // Output: } -func ExampleFileMode() { - _ = os.WriteFile("/tmp/example_fm", []byte{}, fs.FileMode(0600)) - FileMode(t, "/tmp/example_fm", fs.FileMode(0600)) - // Output: -} - func ExampleFileModeFS() { fsys := fstest.MapFS{ "example": &fstest.MapFile{Mode: 0600}, @@ -385,11 +354,6 @@ func ExampleFileModeFS() { // Output: } -func ExampleFileNotExists() { - FileNotExists(t, "/tmp/not_existing_file") - // Output: -} - func ExampleFileNotExistsFS() { fsys := fstest.MapFS{} FileNotExistsFS(t, fsys, "not_existing_file") diff --git a/must/examples_unix_test.go b/must/examples_unix_test.go new file mode 100644 index 0000000..39c1ef4 --- /dev/null +++ b/must/examples_unix_test.go @@ -0,0 +1,46 @@ +// Code generated via scripts/generate.sh. DO NOT EDIT. + +// Copyright (c) The Test Authors +// SPDX-License-Identifier: MPL-2.0 + +//go:build unix + +package must + +import ( + "io/fs" + "os" +) + +func ExampleDirExists() { + DirExists(t, "/tmp") + // Output: +} + +func ExampleDirNotExists() { + DirNotExists(t, "/does/not/exist") + // Output: +} + +func ExampleFileContains() { + _ = os.WriteFile("/tmp/example", []byte("foo bar baz"), fs.FileMode(0600)) + FileContains(t, "/tmp/example", "bar") + // Output: +} + +func ExampleFileExists() { + _ = os.WriteFile("/tmp/example", []byte{}, fs.FileMode(0600)) + FileExists(t, "/tmp/example") + // Output: +} + +func ExampleFileMode() { + _ = os.WriteFile("/tmp/example_fm", []byte{}, fs.FileMode(0600)) + FileMode(t, "/tmp/example_fm", fs.FileMode(0600)) + // Output: +} + +func ExampleFileNotExists() { + FileNotExists(t, "/tmp/not_existing_file") + // Output: +} diff --git a/scripts/generate.sh b/scripts/generate.sh index 6a3c440..042c929 100755 --- a/scripts/generate.sh +++ b/scripts/generate.sh @@ -19,6 +19,7 @@ apply scripts_test.go apply test.go apply test_test.go apply examples_test.go +apply examples_unix_test.go cp -R testdata must/