Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions engine/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3703,16 +3703,18 @@ func TestOpen(t *testing.T) {
defer func() {
assert.NoError(t, os.Remove(n))
}()
assert.NoError(t, os.WriteFile(n, []byte("longer existing payload"), 0o644))

v := NewVariable()
var s *Stream

ok, err := Open(&vm, NewAtom(n), atomWrite, v, List(&compound{
functor: atomAlias,
args: []Term{atomOutput},
}), func(env *Env) *Promise {
ref, ok := env.lookup(v)
assert.True(t, ok)
s, ok := ref.(*Stream)
s, ok = ref.(*Stream)
assert.True(t, ok)

l, ok := vm.streams.lookup(atomOutput)
Expand All @@ -3722,20 +3724,15 @@ func TestOpen(t *testing.T) {
_, err := fmt.Fprintf(s.sink, "test\n")
assert.NoError(t, err)

f, err := os.Open(n)
assert.NoError(t, err)
defer func() {
assert.NoError(t, f.Close())
}()

b, err := io.ReadAll(f)
assert.NoError(t, err)
assert.Equal(t, "test\n", string(b))

return Bool(true)
}, nil).Force(context.Background())
assert.NoError(t, err)
assert.True(t, ok)
assert.NoError(t, s.Close())

b, err := os.ReadFile(n)
assert.NoError(t, err)
assert.Equal(t, "test\n", string(b))
})

t.Run("read_write", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions engine/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@ const (
// ioModeRead means you can read from the stream.
ioModeRead = ioMode(os.O_RDONLY)
// ioModeWrite means you can write to the stream.
ioModeWrite = ioMode(os.O_CREATE | os.O_WRONLY)
ioModeWrite = ioMode(os.O_CREATE | os.O_WRONLY | os.O_TRUNC)
// ioModeAppend means you can append to the stream.
ioModeAppend = ioMode(os.O_APPEND) | ioModeWrite
ioModeAppend = ioMode(os.O_APPEND | os.O_CREATE | os.O_WRONLY)
// ioModeReadWrite means you can both read from and write to an existing stream.
ioModeReadWrite = ioMode(os.O_RDWR)
)
Expand Down
Loading