Open bitfield opened 1 year ago
I should also mention that https://pkg.go.dev/golang.org/x/exp/cmd/txtar exists now, alongside https://pkg.go.dev/golang.org/x/tools/txtar. It already supports comments via stdout when extracting, and stdin when archiving. It doesn't appear to do any form of sanity checking on the input, so I guess we could do the same.
I agree with Roger though - this tool should not be aware of testscript at all.
TL;DR have
txtar-c
include an optional test script in the archive it creates.Use case
Suppose we want to use the marvellous
testscript
runner to run a given script against a set of files. For example, we might want to test a directory containing Go files using some scripttest.txtar
:Of course, we can't run this script as it stands, because it doesn't contain the Go files. So, how to add them?
We could create a
txtar
archive of the directory usingtxtar-c
, concatenate the result with our original script, and run the result of that withtestscript
. This is straightforward:Unfortunately, if
DIR
has files containingtxtar
file marker lines, this produces the wrong result.txtar-c -quote
prepends the necessaryunquote
lines to its archive:Simple-mindedly prepending our
test.txtar
script to this would produce:That's no good, because presumably we need the files to be unquoted before running
go test
. So the script needs to go after anyunquote
lines, but before the file data. This is not straightforward, and this shell script is unsatisfactory for any number of reasons (bonus points if you spot all twelve):How much nicer it would be if we could simply ask
txtar-c
to include our script file in the appropriate place!This makes it very easy and pleasant to use
testscript
to run scripts against some existing set of files, for example in a CI pipeline. A decent value-add for eight extra lines of code, I think.