Commit 5d2da07
committed
internal/cuetxtar: Append \n to generated txtar file content
Txtar archives cannot model files that lack a trailing newline.
We have many tests that generate content and we then compare that
content to files within txtar archives. Often, the generated content
does not contain a trailing newline, which poses a problem when it must
be compared to content from a txtar archive.
We've typically worked around this by using `fmt.Fprintln` to write out
the generated content, which adds the trailing newline. But this is
fragile and you have to remember to use the println variant. In a couple
of places we've done more elaborate trimming of content.
Given this limitation of txtar archives, it is preferable to always
ensure the generated file content (assuming there is some) ends with a
newline, and to achieve this within the txtar test framework itself. As
implemented here, this does not require any changes to our existing
tests: the numerous sites where fmt.Fprintln is in use continue to work,
but they are no longer necessary - using the plain buf.Write works just
fine now.
This has been tested with CUE_UPDATE=1 too, to ensure that that doesn't
cause any churn.
Signed-off-by: Matthew Sackman <[email protected]>
Change-Id: I55a941c8b99198117af04e23f0c005df3dd09b4d
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1210652
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>1 parent 153fc8a commit 5d2da07
File tree
3 files changed
+20
-8
lines changed- encoding
- jsonschema
- openapi
- internal/cuetxtar
3 files changed
+20
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
128 | | - | |
| 127 | + | |
| 128 | + | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
135 | | - | |
136 | | - | |
| 134 | + | |
137 | 135 | | |
138 | 136 | | |
139 | 137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
151 | 165 | | |
152 | 166 | | |
153 | 167 | | |
| |||
505 | 519 | | |
506 | 520 | | |
507 | 521 | | |
508 | | - | |
| 522 | + | |
509 | 523 | | |
510 | 524 | | |
511 | 525 | | |
| |||
555 | 569 | | |
556 | 570 | | |
557 | 571 | | |
558 | | - | |
| 572 | + | |
559 | 573 | | |
560 | 574 | | |
561 | 575 | | |
| |||
0 commit comments