Skip to content
Merged
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
20 changes: 12 additions & 8 deletions book/super-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ func run(opts opts) wasm.Promise {
var r io.Reader
switch typ := opts.Input.Type(); typ {
case js.TypeString:
r = strings.NewReader(opts.Input.String())
if s := opts.Input.String(); strings.TrimSpace(s) != "" {
r = strings.NewReader(s)
}
case js.TypeObject:
if !opts.Input.InstanceOf(js.Global().Get("ReadableStream")) {
return nil, errInvalidInput
Expand All @@ -63,13 +65,15 @@ func run(opts opts) wasm.Promise {
return "", errInvalidInput
}
zctx := super.NewContext()
zr, err := anyio.NewReaderWithOpts(zctx, r, anyio.ReaderOpts{
Format: opts.InputFormat,
})
if err != nil {
return "", err
var readers []sio.Reader
if r != nil {
rc, err := anyio.NewReaderWithOpts(zctx, r, anyio.ReaderOpts{Format: opts.InputFormat})
if err != nil {
return "", err
}
defer rc.Close()
readers = []sio.Reader{rc}
}
defer zr.Close()
var buf bytes.Buffer
zwc, err := anyio.NewWriter(sio.NopCloser(&buf), anyio.WriterOpts{Format: opts.OutputFormat})
if err != nil {
Expand All @@ -78,7 +82,7 @@ func run(opts opts) wasm.Promise {
defer zwc.Close()
local := storage.NewLocalEngine()
comp := compiler.NewCompiler(local)
query, err := runtime.CompileQuery(context.Background(), zctx, comp, flowgraph, []sio.Reader{zr})
query, err := runtime.CompileQuery(context.Background(), zctx, comp, flowgraph, readers)
if err != nil {
return "", err
}
Expand Down
4 changes: 3 additions & 1 deletion mdtest/mdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
// contains an SPQ test. The content of the block must comprise three sections,
// each preceeded by one or more "#"-prefixed lines. The first section contains
// an SPQ program, the second contains input provided to the program when the
// test runs, and the third contains the program's expected output.
// test runs, and the third contains the program's expected output. If the
// second section contains only whitespace, no input is provided when the test
// runs.
//
// SPQ tests are run via the super command. The command's exit status must
// indicate success (i.e., be zero) unless the mdtest-spq block's info string
Expand Down
7 changes: 5 additions & 2 deletions mdtest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ func (t *Test) Run() error {
}
var c *exec.Cmd
if t.SPQ != "" {
c = exec.Command("super", "-s", "-c", t.SPQ, "-")
c.Stdin = strings.NewReader(t.Input)
c = exec.Command("super", "-s", "-c", t.SPQ)
if s := t.Input; strings.TrimSpace(s) != "" {
c.Args = append(c.Args, "-")
c.Stdin = strings.NewReader(s)
}
} else {
c = exec.Command("bash", "-e", "-o", "pipefail")
c.Dir = t.Dir
Expand Down