Skip to content

Commit d1210a5

Browse files
committed
cmd/cue: add false, echo, and cat testscript commands
These are used by `cue cmd` testscripts for various purposes, and they're not available on Windows nor Wine. They are simple enough to implement a basic version of, so do that. Updates #1821. Signed-off-by: Daniel Martí <[email protected]> Change-Id: Ib2fd9931503cf66c2c8fcc7fabcd014eceb47e9b Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1216402 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Roger Peppe <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent c0c6072 commit d1210a5

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

cmd/cue/cmd/script_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"bytes"
2020
"context"
2121
"encoding/json"
22+
"flag"
2223
"fmt"
2324
"io"
2425
"io/fs"
@@ -426,6 +427,38 @@ func TestMain(m *testing.M) {
426427
}
427428
},
428429
"testcmd": func() { check(testCmd()) },
430+
// These Unix-like commands are used by a few testscripts, especially when testing `cue cmd`.
431+
// They are not available on vanilla Windows, so add a simple version of them here.
432+
"false": func() {
433+
os.Exit(1)
434+
},
435+
"echo": func() {
436+
flag.Parse()
437+
args := flag.Args()
438+
for i, arg := range args {
439+
if i > 0 {
440+
fmt.Print(" ")
441+
}
442+
fmt.Print(arg)
443+
}
444+
fmt.Println()
445+
},
446+
"cat": func() {
447+
flag.Parse()
448+
args := flag.Args()
449+
if len(args) == 0 {
450+
_, err := io.Copy(os.Stdout, os.Stdin)
451+
check(err)
452+
return
453+
}
454+
for _, arg := range args {
455+
f, err := os.Open(arg)
456+
check(err)
457+
_, err = io.Copy(os.Stdout, f)
458+
f.Close()
459+
check(err)
460+
}
461+
},
429462
// Like `cue export`, but as a standalone Go program which doesn't
430463
// go through cmd/cue's setup of cuecontext and the evaluator.
431464
// Useful to check what the export behavior is for Go API users,

0 commit comments

Comments
 (0)