I/O

Read stdin

Given a file named “main.cloe” with:

(print (read) . end "")

And a file named “test.txt” with:

foo
bar
baz

When I run the following commands:

cloe main.cloe < test.txt

Then the stdout should contain exactly:

foo
bar
baz

Read a file

Given a file named “main.cloe” with:

(print (read . file "test.txt") . end "")

And a file named “test.txt” with:

foo
bar
baz

When I successfully run cloe main.cloe

Then the stdout should contain exactly:

foo
bar
baz

Given a file named “main.cloe” with:

(print "Hello!")

When I successfully run cloe main.cloe

Then the stdout should contain exactly “Hello!”.

Given a file named “main.cloe” with:

(print "Hello!" . end "!!")

When I successfully run cloe main.cloe

Then the stdout should contain exactly “Hello!!!”.

Given a file named “main.cloe” with:

(print "Hello," "world!")

When I successfully run cloe main.cloe

Then the stdout should contain exactly “Hello, world!”.

Given a file named “main.cloe” with:

(print 42)

When I successfully run cloe main.cloe

Then the stdout should contain exactly “42”.

Given a file named “main.cloe” with:

(print nil)

When I successfully run cloe main.cloe

Then the stdout should contain exactly “nil”.

Given a file named “main.cloe” with:

(print "string" 42 nil true)

When I successfully run cloe main.cloe

Then the stdout should contain exactly “string 42 nil true”.

Given a file named “main.cloe” with:

(print "This is stderr." . file 2)

When I successfully run cloe main.cloe

Then the stdout should contain exactly “”

And the stderr should contain exactly “This is stderr.”.

Given a file named “main.cloe” with:

(print "This is content." . file "output.txt")

When I successfully run cloe main.cloe

Then the stdout should contain exactly “”

And the file “output.txt” should contain exactly:

This is content.

Given a file named “main.cloe” with:

(print 42 . file nil)

When I run cloe main.cloe

Then the exit status should not be 0

And the stdout should contain exactly “”

And the stderr should contain “Error”.