Skip to content

Commit 8ed1356

Browse files
committed
Enhance CommandMultipleCompletionsTestCase to include assertion for no completions yet
1 parent e71fd7c commit 8ed1356

File tree

6 files changed

+62
-16
lines changed

6 files changed

+62
-16
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ jobs:
1717
- name: Unshallow
1818
run: git fetch --prune --unshallow
1919
- name: Set up Go
20-
uses: actions/setup-go@v1
20+
uses: actions/setup-go@v6
2121
with:
2222
go-version: 1.22.x
2323
- name: Run GoReleaser
2424
uses: goreleaser/goreleaser-action@v6
2525
with:
26-
version: '~> v2'
26+
version: "~> v2"
2727
args: release -f main.goreleaser.yml --clean
2828
env:
2929
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- name: Checkout
1010
uses: actions/checkout@v2
1111
- name: Set up Go
12-
uses: actions/setup-go@v5
12+
uses: actions/setup-go@v6
1313
with:
1414
go-version: 1.24.x
1515
- name: setup-env
@@ -28,7 +28,7 @@ jobs:
2828
uses: actions/checkout@v2
2929

3030
- name: Set up Go
31-
uses: actions/setup-go@v1
31+
uses: actions/setup-go@v6
3232
with:
3333
go-version: 1.24.x
3434

@@ -113,7 +113,7 @@ jobs:
113113
uses: actions/checkout@v2
114114

115115
- name: Set up Go
116-
uses: actions/setup-go@v1
116+
uses: actions/setup-go@v6
117117
with:
118118
go-version: 1.24.x
119119

@@ -124,4 +124,4 @@ jobs:
124124
uname -a
125125
compgen -ac | sort | grep '^ex'
126126
127-
- run: TEST_TARGET=test_bash RUNS=25 make test_flakiness
127+
- run: TEST_TARGET=test_bash RUNS=25 make test_flakiness
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package assertions
2+
3+
import (
4+
"github.com/codecrafters-io/shell-tester/internal/screen_state"
5+
"github.com/codecrafters-io/shell-tester/internal/utils"
6+
)
7+
8+
// EmptyLineAssertion asserts that a single line of output is empty
9+
type EmptyLineAssertion struct {
10+
// StayOnSameLine is a flag to indicate that the shell cursor
11+
// should stay on the same line after the assertion is run
12+
// Most probably because the next assertion will run on the same line
13+
StayOnSameLine bool
14+
}
15+
16+
func (a EmptyLineAssertion) Inspect() string {
17+
return "EmptyLineAssertion"
18+
}
19+
20+
func (a EmptyLineAssertion) Run(screenState screen_state.ScreenState, startRowIndex int) (processedRowCount int, err *AssertionError) {
21+
processedRowCount = 1
22+
if a.StayOnSameLine {
23+
processedRowCount = 0
24+
}
25+
26+
row := screenState.GetRow(startRowIndex)
27+
28+
if row.IsEmpty() {
29+
return processedRowCount, nil
30+
}
31+
32+
// Build error message
33+
detailedErrorMessage := utils.BuildColoredErrorMessage("(empty line)", row.String(), "")
34+
message := "Line is not empty.\n" + detailedErrorMessage
35+
36+
return 0, &AssertionError{
37+
ErrorRowIndex: startRowIndex,
38+
Message: message,
39+
}
40+
}

internal/stage7.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ func testType2(stageHarness *test_case_harness.TestCaseHarness) error {
6868
var expectedPath = ""
6969
if executable == "my_exe" {
7070
expectedPath = filepath.Join(executableDir, myExeCommandName)
71+
}
7172

72-
// Alpine Busybox has a bug where it doesn't check permissions
73-
if isTestingTesterUsingBusyboxOnAlpine(stageHarness) {
74-
expectedPath = nonExePath
75-
}
73+
// Alpine Busybox has a bug where it doesn't check permissions
74+
if isTestingTesterUsingBusyboxAshOnAlpine(stageHarness) {
75+
expectedPath = nonExePath
7676
}
7777

7878
if err := testCase.RunForExecutable(asserter, shell, logger, expectedPath); err != nil {

internal/test_cases/command_multiple_completions_test_case.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,24 @@ func (t CommandMultipleCompletionsTestCase) Run(asserter *logged_shell_asserter.
8080
}
8181

8282
if t.CheckForBell {
83+
// Assert no completions yet when the bell is received
84+
asserter.AddAssertion(assertions.EmptyLineAssertion{
85+
StayOnSameLine: true,
86+
})
87+
8388
bellChannel := shell.VTBellChannel()
8489
asserter.AddAssertion(assertions.BellAssertion{
8590
BellChannel: bellChannel,
8691
})
92+
8793
// Run the assertion, before sending the enter key
8894
if err := asserter.AssertWithoutPrompt(); err != nil {
8995
return err
9096
}
91-
9297
logger.Successf("✓ Received bell")
93-
// Pop the bell assertion after running
98+
99+
// Pop the bell assertion and empty line assertion after running
100+
asserter.PopAssertion()
94101
asserter.PopAssertion()
95102
}
96103

internal/utils_sys.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ import (
88
)
99

1010
const ASH_PATH = "internal/test_helpers/ash/your_shell.sh"
11-
const DASH_PATH = "internal/test_helpers/dash/your_shell.sh"
1211

13-
func isTestingTesterUsingBusyboxOnAlpine(stageHarness *test_case_harness.TestCaseHarness) bool {
12+
func isTestingTesterUsingBusyboxAshOnAlpine(stageHarness *test_case_harness.TestCaseHarness) bool {
1413
path := stageHarness.Executable.Path
15-
isTestingTesterUsingBusybox := strings.HasSuffix(path, ASH_PATH) || strings.HasSuffix(path, DASH_PATH)
14+
isTestingTesterUsingBusyboxAsh := strings.HasSuffix(path, ASH_PATH)
1615

1716
_, err := os.Stat("/etc/alpine-release")
1817
isOnAlpine := err == nil
1918

20-
return isTestingTesterUsingBusybox && isOnAlpine
19+
return isTestingTesterUsingBusyboxAsh && isOnAlpine
2120
}

0 commit comments

Comments
 (0)