shelly/lib_test.go

52 lines
743 B
Go
Raw Normal View History

2021-10-24 21:31:09 +00:00
package shelly
import (
"log"
"os"
"os/exec"
"testing"
)
func TestLines(t *testing.T) {
2021-11-03 00:38:03 +00:00
//lines, err := Lines("; \";\" ;;")
2021-10-24 21:31:09 +00:00
//Lines("a\nb\\\\nc")
2021-11-03 00:38:03 +00:00
lines, err := Lines(`
2021-11-03 00:47:36 +00:00
"A STR"
2021-11-03 00:38:03 +00:00
`)
//lines, err := Lines(`
//go build -o main.exe -ldflags="a=1 b=2" ./main.go
2021-10-24 21:31:09 +00:00
//"A STR" 1 2 "a b" 1.23 \n &
//"STR \\ with escape \n chars \t" 1 234 true
//ls -larth
//pwd
//whoami
//date`)
if err != nil {
t.Fatal(err)
}
for _, l := range lines {
log.Printf("%#v", l)
}
}
func TestExec(t *testing.T) {
2021-10-25 21:44:30 +00:00
_, err := Exec(`
2021-10-25 00:42:20 +00:00
ls -larth &
pwd &
whoami &
2021-10-24 21:31:09 +00:00
date`, &Opts{
2021-10-25 00:42:20 +00:00
Await: false,
2021-10-24 21:31:09 +00:00
SetupProc: func(cmd *exec.Cmd) {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
},
})
if err != nil {
t.Fatal(err)
}
2021-10-25 00:42:20 +00:00
log.Printf("DONE")
2021-10-24 21:31:09 +00:00
}