A virtual jailed shell environment for Go apps backed by an io/fs#FS.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

test(printf): cover %b, %c, format reuse, width/precision, --

Documents the bash-influenced -v VAR flag as a kefka
extension (GNU printf has no -v) and adds the previously
missing tests for:

- %b escape interpretation (\\n, \\c, \\t, \\\\, \\0nnn)
- format reuse with arg list longer than the format
- width/precision (%5.3s, %-10d, %05d)
- -- separator before a literal -v format

Refs: docs/posix2018/CONFORMANCE.md
Assisted-by: Claude Opus 4.7 via Claude Code
Signed-off-by: Xe Iaso <me@xeiaso.net>

Xe Iaso 7103f35d 1052b986

+51
+6
command/internal/printf/printf.go
··· 44 44 return interp.ExitStatus(2) 45 45 } 46 46 47 + // -v VAR is a kefka extension influenced by the bash builtin: it stores 48 + // the formatted output in VAR instead of writing to stdout. GNU coreutils 49 + // printf does not support -v, but kefka's shell integration depends on 50 + // it, so it is preserved here. Passing "--" before the format disables 51 + // option parsing, matching POSIX usage so a literal "-v" can still be 52 + // printed via `printf -- '%s' '-v'`. 47 53 var targetVar string 48 54 hasTargetVar := false 49 55 argIdx := 0
+45
command/internal/printf/printf_test.go
··· 242 242 wantStdout: "hi", 243 243 }, 244 244 { 245 + name: "%b interprets backslash newline", 246 + args: []string{"%b", "\\n"}, 247 + wantStdout: "\n", 248 + }, 249 + { 250 + name: "%b terminates at \\c", 251 + args: []string{"%b", "a\\cb"}, 252 + wantStdout: "a", 253 + }, 254 + { 255 + name: "%b interprets backslash tab", 256 + args: []string{"%b", "a\\tb"}, 257 + wantStdout: "a\tb", 258 + }, 259 + { 260 + name: "%b interprets double backslash", 261 + args: []string{"%b", "a\\\\b"}, 262 + wantStdout: "a\\b", 263 + }, 264 + { 265 + name: "%b interprets octal escape", 266 + args: []string{"%b", "\\0101"}, 267 + wantStdout: "A", 268 + }, 269 + { 270 + name: "format reuse %d %d with extra args", 271 + args: []string{"%d %d\\n", "1", "2", "3", "4"}, 272 + wantStdout: "1 2\n3 4\n", 273 + }, 274 + { 275 + name: "width and precision combined %5.3s", 276 + args: []string{"%5.3s", "hello"}, 277 + wantStdout: " hel", 278 + }, 279 + { 280 + name: "left-justified width %-10d", 281 + args: []string{"|%-10d|", "42"}, 282 + wantStdout: "|42 |", 283 + }, 284 + { 285 + name: "literal -v after -- separator", 286 + args: []string{"--", "%s", "-v"}, 287 + wantStdout: "-v", 288 + }, 289 + { 245 290 name: "hex input parsed", 246 291 args: []string{"%d", "0x1f"}, 247 292 wantStdout: "31",