Skip to content

Commit

Permalink
Clarify why we normalize terminal line endings to '\n'.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchell-as committed Oct 11, 2023
1 parent baad479 commit 60fd041
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/testhelpers/e2e/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,11 @@ func (s *Session) SpawnCmdWithOpts(exe string, optSetters ...SpawnOptSetter) *Sp
termtest.OptRows(30), // Needs to be able to accommodate most JSON output
)

// Multi-line expectation strings (e.g. TestBranch_List), as well as macOS and Linux, use '\n' to
// represent newlines. However, Windows uses '\r\n' to represent newlines. Normalize all line
// endings to be just '\n' or else the expectation will fail on Windows.
// TTYs output newlines in two steps: '\r' (CR) to move the caret to the beginning of the line,
// and '\n' (LF) to move the caret one line down. Terminal emulators do the same thing, so the
// raw terminal output will contain "\r\n". Since our multi-line expectation messages often use
// '\n', normalize line endings to that for convenience, regardless of platform ('\n' for Linux
// and macOS, "\r\n" for Windows).
spawnOpts.TermtestOpts = append(spawnOpts.TermtestOpts,
termtest.OptNormalizedLineEnds(true),
)
Expand Down

0 comments on commit 60fd041

Please sign in to comment.