diff --git a/cmd/txtar-c/savedir.go b/cmd/txtar-c/savedir.go index 07f0ab27..a0a3c046 100644 --- a/cmd/txtar-c/savedir.go +++ b/cmd/txtar-c/savedir.go @@ -10,7 +10,6 @@ // // See https://godoc.org/github.com/rogpeppe/go-internal/txtar for details of the format // and how to parse a txtar file. -// package main import ( @@ -35,8 +34,9 @@ func usage() { } var ( - quoteFlag = flag.Bool("quote", false, "quote files that contain txtar file markers instead of failing") - allFlag = flag.Bool("a", false, "include dot files too") + quoteFlag = flag.Bool("quote", false, "quote files that contain txtar file markers instead of failing") + scriptFlag = flag.String("script", "", "include testscript `FILE` (after any 'unquote' lines)") + allFlag = flag.Bool("a", false, "include dot files too") ) func main() { @@ -105,7 +105,13 @@ func main1() int { }) return nil }) - + if *scriptFlag != "" { + script, err := os.ReadFile(*scriptFlag) + if err != nil { + log.Fatal(err) + } + a.Comment = append(a.Comment, script...) + } data := txtar.Format(a) os.Stdout.Write(data) diff --git a/cmd/txtar-c/testdata/script.txtar b/cmd/txtar-c/testdata/script.txtar new file mode 100644 index 00000000..7db941ae --- /dev/null +++ b/cmd/txtar-c/testdata/script.txtar @@ -0,0 +1,35 @@ +unquote expect +# With the -script flag, it should include the contents of test.txtar as a comment +exec txtar-c -script test.txtar blah +cmp stdout expect + +-- test.txtar -- +exec echo hello + +-- blah/go.mod -- +module example.com/blah + +-- blah/main.go -- +package main + +import "fmt" + +func main() { + fmt.Println("Hello, world!") +} + +-- expect -- +>exec echo hello +> +>-- go.mod -- +>module example.com/blah +> +>-- main.go -- +>package main +> +>import "fmt" +> +>func main() { +> fmt.Println("Hello, world!") +>} +> \ No newline at end of file diff --git a/cmd/txtar-c/testdata/script_quote.txtar b/cmd/txtar-c/testdata/script_quote.txtar new file mode 100644 index 00000000..6f12e93c --- /dev/null +++ b/cmd/txtar-c/testdata/script_quote.txtar @@ -0,0 +1,43 @@ +unquote expect +unquote blah/needsquote.txtar +# With both -script and -quote, it should include test.txtar after any 'unquote's +exec txtar-c -quote -script test.txtar blah +cmp stdout expect + +-- test.txtar -- +exec echo hello + +-- blah/go.mod -- +module example.com/blah + +-- blah/main.go -- +package main + +import "fmt" + +func main() { + fmt.Println("Hello, world!") +} + +-- blah/needsquote.txtar -- +>-- file_entry.txt -- + +-- expect -- +>unquote needsquote.txtar +>exec echo hello +> +>-- go.mod -- +>module example.com/blah +> +>-- main.go -- +>package main +> +>import "fmt" +> +>func main() { +> fmt.Println("Hello, world!") +>} +> +>-- needsquote.txtar -- +>>-- file_entry.txt -- +>> \ No newline at end of file