Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/stage_h3.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ func testH3(stageHarness *test_case_harness.TestCaseHarness) error {
}

testCase1 := test_cases.HistoryTestCase{
PreviousCommands: previousCommands,
HistoryOffset: 0, // These are the first commands in history
LastNCommands: 2,
PreviousCommands: previousCommands,
SuccessMessage: "✓ Received expected response",
}
if err := testCase1.Run(asserter, shell, logger); err != nil {
Expand Down Expand Up @@ -79,8 +80,9 @@ func testH3(stageHarness *test_case_harness.TestCaseHarness) error {
}

testCase2 := test_cases.HistoryTestCase{
PreviousCommands: previousCommands,
HistoryOffset: 4, // 3 initial commands + 1 history command
LastNCommands: random.RandomInt(3, 5),
PreviousCommands: previousCommands,
SuccessMessage: "✓ Received expected response",
}
if err := testCase2.Run(asserter, shell, logger); err != nil {
Expand Down
20 changes: 14 additions & 6 deletions internal/test_cases/history_test_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ import (
// Verifies that the command is printed to the screen
// Verifies that the history output shows the command in the expected format
type HistoryTestCase struct {
// PreviousCommands is a list of previous commands expected to be in the history list
PreviousCommands []string
// HistoryOffset specifies the starting line number offset for the PreviousCommands
// This accounts for commands that were executed before the PreviousCommands in the same session
HistoryOffset int

// LastNCommands specifies how many of the most recent commands to check in history
// If not set, all commands will be checked
LastNCommands int

// PreviousCommands is a list of previous commands expected to be in the history list
PreviousCommands []string

// SuccessMessage is the message to log in case of success
SuccessMessage string
}
Expand All @@ -48,19 +52,23 @@ func (t HistoryTestCase) Run(asserter *logged_shell_asserter.LoggedShellAsserter

// Check only the specified number of most recent commands
for i, command := range t.PreviousCommands[startIdx:] {
expectedLineNumber := t.HistoryOffset + startIdx + i + 1
asserter.AddAssertion(assertions.SingleLineAssertion{
ExpectedOutput: fmt.Sprintf(" %d %s", startIdx+i+1, command),
ExpectedOutput: fmt.Sprintf(" %d %s", expectedLineNumber, command),
FallbackPatterns: []*regexp.Regexp{
regexp.MustCompile(fmt.Sprintf(`^\s*\d+\s+%s$`, regexp.QuoteMeta(command))),
regexp.MustCompile(fmt.Sprintf(`^\s*%d\s+%s$`, expectedLineNumber, regexp.QuoteMeta(command))),
regexp.MustCompile(fmt.Sprintf(`^\s*%d\s+%s$`, expectedLineNumber-1, regexp.QuoteMeta(command))), // 0-based for ash
},
})
}

// Add assertion for the history command itself
expectedHistoryLineNumber := t.HistoryOffset + len(t.PreviousCommands) + 1
asserter.AddAssertion(assertions.SingleLineAssertion{
ExpectedOutput: fmt.Sprintf(" %d %s", len(t.PreviousCommands)+1, historyCommand),
ExpectedOutput: fmt.Sprintf(" %d %s", expectedHistoryLineNumber, historyCommand),
FallbackPatterns: []*regexp.Regexp{
regexp.MustCompile(fmt.Sprintf(`^\s*\d+\s+%s$`, regexp.QuoteMeta(historyCommand))),
regexp.MustCompile(fmt.Sprintf(`^\s*%d\s+%s$`, expectedHistoryLineNumber, regexp.QuoteMeta(historyCommand))),
regexp.MustCompile(fmt.Sprintf(`^\s*%d\s+%s$`, expectedHistoryLineNumber-1, regexp.QuoteMeta(historyCommand))), // 0-based for ash
},
})

Expand Down
Loading