tinygo/testdata/filesystem.go
Ayke van Laethem 0ffe5ac2fa main: clean up tests
- Explicitly list all test cases. This makes it possible to store
    tests in testdata/ that aren't tested on all platforms.
  - Clean up filesystem and env test, by running them in a subtest and
    deduplicating some code and removing the additionalArgs parameter.
2021-04-09 18:33:48 +02:00

38 строки
571 Б
Go

package main
import (
"io/ioutil"
"os"
)
func main() {
_, err := os.Open("non-exist")
if !os.IsNotExist(err) {
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 := ioutil.ReadAll(f)
if err != nil {
panic(err)
}
print(string(data))
}