-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
preprocessor: ellipsis sanitiser should always add trailing dots
Some commands like 'go mod tidy' might not produce lots of output under certain conditions, e.g. when the modules they require are part of a cache. In that scenario, CI might well produce a different output because no cache is being used. The author however wants to use a cache to ensure that writing the guide does not take forever (the write-save-rerun cycle can get very expensive). In such a situation, an ellipsis sanitiser can be used to indicate this command _might_ produce lots of output, which disguises whether there was any output when it can vary based on cache state. This CL makes the change to an ellipsis sanitiser to always add a trailing '…'. Which now has the meaning "there might be lots of output" rather than "there is lots of output". This CL also adds quicktest as a dependency to help make our test code more succinct and readable. We also fix a bug in the transformation of script nodes, where a clear line was printed before a doc comment, ignoring whether that doc comment actually had any non-tag directive lines (because if a doc comment is only made up of tag directives, no comment will be printed and so the clear line is redundant). Preprocessor-No-Write-Cache: true Signed-off-by: Paul Jolly <[email protected]> Change-Id: I3097711c62d78b925efd4297b817a5bbef2e12b8 Dispatch-Trailer: {"type":"trybot","CL":1177002,"patchset":8,"ref":"refs/changes/02/1177002/8","targetBranch":"alpha"}
- Loading branch information
Showing
6 changed files
with
137 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2024 The CUE Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/go-quicktest/qt" | ||
) | ||
|
||
func TestEllipsisSanitiser(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
input string | ||
start int | ||
want string | ||
}{ | ||
{ | ||
name: "empty start at zero", | ||
input: "", | ||
start: 0, | ||
want: "...\n", | ||
}, | ||
{ | ||
name: "empty start at 1", | ||
input: "", | ||
start: 1, | ||
want: "...\n", | ||
}, | ||
{ | ||
name: "empty but non-zero start", | ||
input: "", | ||
start: 10, | ||
want: "...\n", | ||
}, | ||
{ | ||
name: "ensure no blank lines before ...", | ||
input: "test\n\nsomething", | ||
start: 2, | ||
want: "test\n...\n", | ||
}, | ||
{ | ||
name: "ellipsis at zero", | ||
input: "this\nis\na\ntest\n", | ||
start: 0, | ||
want: "...\n", | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
cmd := commandStmt{ | ||
Output: c.input, | ||
} | ||
san := ellipsisSanitiser{ | ||
Start: c.start, | ||
} | ||
err := san.sanitise(&cmd) | ||
qt.Assert(t, qt.IsNil(err)) | ||
qt.Assert(t, qt.Equals(cmd.Output, c.want)) | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters