Skip to content

Commit

Permalink
examples: only require unix for file and dir examples
Browse files Browse the repository at this point in the history
  • Loading branch information
brandondyck committed Sep 9, 2024
1 parent 78901ef commit 9f8e98c
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 72 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 0 additions & 36 deletions examples_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// Copyright (c) The Test Authors
// SPDX-License-Identifier: MPL-2.0

//go:build unix

package test

import (
"errors"
"fmt"
"io/fs"
"math"
"os"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -226,11 +223,6 @@ func ExampleDescendingLess() {
// Output:
}

func ExampleDirExists() {
DirExists(t, "/tmp")
// Output:
}

func ExampleDirExistsFS() {
fsys := fstest.MapFS{
"foo": &fstest.MapFile{Mode: fs.ModeDir},
Expand All @@ -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")
Expand Down Expand Up @@ -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{
Expand All @@ -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{},
Expand All @@ -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},
Expand All @@ -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")
Expand Down
44 changes: 44 additions & 0 deletions examples_unix_test.go
Original file line number Diff line number Diff line change
@@ -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:
}
36 changes: 0 additions & 36 deletions must/examples_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions must/examples_unix_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down

0 comments on commit 9f8e98c

Please sign in to comment.