Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testscript: relax constraints around actual source in cmp with update #107

Merged
merged 1 commit into from Jul 31, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion testscript/cmd.go
Expand Up @@ -131,7 +131,7 @@ func (ts *TestScript) doCmdCmp(args []string, env bool) {
if text1 == text2 {
return
}
if ts.params.UpdateScripts && !env && (args[0] == "stdout" || args[0] == "stderr") {
if ts.params.UpdateScripts && !env {
if scriptFile, ok := ts.scriptFiles[absName2]; ok {
ts.scriptUpdates[scriptFile] = text1
return
Expand Down
19 changes: 19 additions & 0 deletions testscript/testdata/testscript_update_script_actual_is_file.txt
@@ -0,0 +1,19 @@
unquote scripts/testscript.txt
unquote testscript-new.txt
testscript-update scripts
cmp scripts/testscript.txt testscript-new.txt

-- scripts/testscript.txt --
>cmp got want
>
>-- got --
>right
>-- want --
>wrong
-- testscript-new.txt --
>cmp got want
>
>-- got --
>right
>-- want --
>right
@@ -1,3 +1,5 @@
# Verify that comparing stdout against a file not in the archive does nothing

unquote scripts/testscript.txt
cp scripts/testscript.txt unchanged
! testscript-update scripts
Expand Down
8 changes: 4 additions & 4 deletions testscript/testscript.go
Expand Up @@ -143,10 +143,10 @@ type Params struct {
// error will be ignored.
IgnoreMissedCoverage bool

// UpdateScripts specifies that if a `cmp` command fails and
// its first argument is `stdout` or `stderr` and its second argument
// refers to a file inside the testscript file, the command will succeed
// and the testscript file will be updated to reflect the actual output.
// UpdateScripts specifies that if a `cmp` command fails and its second
// argument refers to a file inside the testscript file, the command will
// succeed and the testscript file will be updated to reflect the actual
// content (which could be stdout, stderr or a real file).
//
// The content will be quoted with txtar.Quote if needed;
// a manual change will be needed if it is not unquoted in the
Expand Down