github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/testdata/filesystem.go (about)

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