Skip to content

Commit b61705d

Browse files
committed
Bundle the RSX test library
1 parent 752ce85 commit b61705d

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

tests/lib/test.risor renamed to lib/test.risor

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import color
22
import exec
33
import regexp
44
import os
5+
import uuid
56

67
__fatal := false
78
__raises := false
@@ -156,17 +157,19 @@ func stdout_equals(desc, cmd, expected) {
156157
func stdout_matches(desc, cmd, reg) {
157158
tokens := cmd.split(" ")
158159
bin := tokens[0]
159-
args := []
160+
args := [bin]
160161
if len(tokens) > 1 {
161162
args.extend(tokens[1:])
162163
}
163164

165+
cmd := exec.command(args)
164166
try(func() {
165-
out := exec(bin, args)
166-
if regexp.match(reg, out.stdout) {
167+
out := cmd.combined_output()
168+
out = string(out)
169+
if regexp.match(reg, out) {
167170
print_ok(desc)
168171
} else {
169-
errors.new(desc + '(output {out} does not match {reg})')
172+
error(desc + ' (output {out} does not match {reg})')
170173
}
171174
}, func(e) {
172175
print_fail(desc + ' (error: {e})')
@@ -191,7 +194,7 @@ func is_dir(desc, path) {
191194
// desc: the test description
192195
// path: the path to check
193196
func is_file(desc, path) {
194-
ok := try(func() { f := os.stat(path); !f.is_dir }, false)
197+
ok := try(func() { f := os.stat(path); f.mode.is_regular }, false)
195198
if ok {
196199
print_ok(desc)
197200
} else {

main.risor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ cli.app({
149149
aliases: ["n"],
150150
usage: "Create a new RSX project directory",
151151
action: func(ctx) {
152+
if len(ctx.args()) != 1 {
153+
os.write_file("/dev/stderr", "Missing directory argument.")
154+
return
155+
}
152156
name := ctx.args()[0]
153157
os.mkdir(name)
154158
os.write_file(filepath.join(name, "main.risor"), "import rsx\n"+`rsx.log("Hello, World!")`)

script/test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
go build
44

5-
risor --modules tests/lib tests/tests.risor
5+
./rsx eval tests/tests.risor

tests/tests.risor

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ test.with_temp_dir(func(tmp_dir) {
1717
test.is_dir('{dir} was created', dir)
1818
})
1919

20+
test.with_temp_dir(func(tmp_dir) {
21+
dir := filepath.join(tmp_dir, "rsx-new")
22+
test.stdout_matches(
23+
'rsx new without arguments fails',
24+
'{_rsxbin} new',
25+
'Missing directory argument.',
26+
)
27+
})
28+
2029
test.with_temp_dir(func(tmp_dir) {
2130
cd(tmp_dir)
2231
test.stdout_matches(

0 commit comments

Comments
 (0)