blob: de7fcbdf849778e865c9c68e10f38f03268f73b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package main
import (
"errors"
"io"
"io/fs"
"os"
)
func main() {
_, err := os.Open("non-exist")
if !errors.Is(err, fs.ErrNotExist) {
panic("should be non exist error")
}
f, err := os.Open("testdata/filesystem.txt")
if err != nil {
panic(err)
}
defer func() {
if err := f.Close(); err != nil {
panic(err)
}
// read after close: error should be returned
_, err := f.Read(make([]byte, 10))
if err == nil {
panic("error expected for reading after closing files")
}
}()
data, err := io.ReadAll(f)
if err != nil {
panic(err)
}
os.Stdout.Write(data)
path, err := os.Getwd()
if err != nil {
panic(err)
}
if path == "" {
panic("path is empty")
}
}
|