Skip to content

Commit

Permalink
Merge pull request #86 from d5/ostestfix
Browse files Browse the repository at this point in the history
minor cleanups for 'os' module tests
  • Loading branch information
d5 authored Feb 7, 2019
2 parents e81380b + a9f9ba4 commit 9782d87
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions compiler/stdlib/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@ import (
"os"
"testing"

"github.com/d5/tengo/assert"
"github.com/d5/tengo/objects"
)

func TestReadFile(t *testing.T) {
content := []byte("the quick brown fox jumps over the lazy dog")
tf, err := ioutil.TempFile("", "test")
if err != nil {
t.Logf("could not open tempfile: %s", err)
if !assert.NoError(t, err) {
return
}
defer os.Remove(tf.Name())
defer func() { _ = os.Remove(tf.Name()) }()

_, err = tf.Write(content)
if err != nil {
t.Logf("could not write temp content: %s", err)
if !assert.NoError(t, err) {
return
}

tf.Close()
_ = tf.Close()

module(t, "os").call("read_file", tf.Name()).expect(&objects.Bytes{Value: content})
}
Expand All @@ -38,19 +36,16 @@ func TestFileStatArgs(t *testing.T) {
func TestFileStatFile(t *testing.T) {
content := []byte("the quick brown fox jumps over the lazy dog")
tf, err := ioutil.TempFile("", "test")
if err != nil {
t.Logf("could not open tempfile: %s", err)
if !assert.NoError(t, err) {
return
}
defer os.Remove(tf.Name())
defer func() { _ = os.Remove(tf.Name()) }()

_, err = tf.Write(content)
if err != nil {
t.Logf("could not write temp content: %s", err)
if !assert.NoError(t, err) {
return
}

tf.Close()
_ = tf.Close()

stat, err := os.Stat(tf.Name())
if err != nil {
Expand All @@ -71,15 +66,13 @@ func TestFileStatFile(t *testing.T) {

func TestFileStatDir(t *testing.T) {
td, err := ioutil.TempDir("", "test")
if err != nil {
t.Logf("could not open tempdir: %s", err)
if !assert.NoError(t, err) {
return
}
defer os.RemoveAll(td)
defer func() { _ = os.RemoveAll(td) }()

stat, err := os.Stat(td)
if err != nil {
t.Logf("could not get tmp dir stat: %s", err)
if !assert.NoError(t, err) {
return
}

Expand Down

0 comments on commit 9782d87

Please sign in to comment.