Add optional variables and fix stdout/stderr ordering#8
Open
andreasjansson wants to merge 2 commits intomainfrom
Open
Add optional variables and fix stdout/stderr ordering#8andreasjansson wants to merge 2 commits intomainfrom
andreasjansson wants to merge 2 commits intomainfrom
Conversation
Add support for optional variables that mark output lines which may or
may not appear. Syntax: {{ var: optional type }} or {{ var: optional }}
for duck-typed.
An optional variable must occupy an entire line by itself. When the
actual output doesn't contain that line, the test still passes and the
variable is not captured. When present, the variable captures normally
and can be used in constraints.
This is useful for commands that conditionally print progress or
diagnostic lines depending on execution time.
Examples:
{{ progress: optional string }}
{{ n: optional number }}
{{ data: optional json object }}
{{ x: optional }}
Implementation:
- Parser: extract 'optional' prefix in parse_placeholder
- Matcher: build_regex wraps optional-only lines in (?:...)? groups
with correct newline handling for start/middle/end positions
- 10 matcher unit tests, 5 parser unit tests, 18 corpus tests
Previously run_command read all of stdout then all of stderr, causing stderr to always appear after stdout regardless of when it was actually written. Now uses channel-based interleaving (same approach as run_command_streaming) to preserve temporal ordering of output lines from both streams. Adds 6 corpus tests verifying ordering with stderr-first, stdout-first, interleaved, and timed delay scenarios.
11b39b4 to
0ec74d1
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two changes:
1. Optional variable modifier for test patterns
Add support for optional variables that mark output lines which may or may not appear.
Syntax
An optional variable must occupy an entire line by itself in the expected output pattern. When the actual output doesn't contain that line, the test still passes and the variable is not captured. When present, the variable captures normally and can be used in constraints.
Example
This matches both
result: 42(no progress line) andProcessing...\nresult: 42(with progress line). Multiple consecutive optional lines are also supported.Implementation
cctr-corpus): Extractoptionalprefix inparse_placeholder, addedoptional: boolfield toVariableDeclbuild_regexwraps optional-only lines in(?:...)?groups with correct newline handling for start/middle/end positions2. Fix stdout/stderr stream ordering
Previously
run_commandread all of stdout then appended all of stderr:This caused stderr to always appear after stdout regardless of when it was actually written. Now uses the same channel-based interleaving approach as
run_command_streamingto preserve temporal ordering of output lines from both streams.6 corpus tests verify ordering with stderr-first, stdout-first, interleaved, and timed delay scenarios.