| 140 | } |
| 141 | |
| 142 | func TestParse_ParseError(t *testing.T) { |
| 143 | t.Parallel() |
| 144 | |
| 145 | t.Run("unterminated-string-no-results", func(t *testing.T) { |
| 146 | t.Parallel() |
| 147 | cmds, err := shellparse.Parse(`echo "unterminated`) |
| 148 | require.Error(t, err) |
| 149 | require.Nil(t, cmds) |
| 150 | }) |
| 151 | |
| 152 | t.Run("semicolon-prefix-yields-partial-results-plus-error", func(t *testing.T) { |
| 153 | t.Parallel() |
| 154 | // Some malformed inputs (e.g. trailing unterminated tokens after |
| 155 | // valid semicolon-separated commands) yield partial results |
| 156 | // alongside a non-nil error. Pin both sides of the contract so |
| 157 | // future mvdan.cc/sh upgrades that change partial-parse behavior |
| 158 | // fail this test loudly. |
| 159 | cmds, err := shellparse.Parse(`ls; cat; echo "unterminated`) |
| 160 | require.Error(t, err) |
| 161 | require.Equal(t, [][]string{{"ls"}, {"cat"}}, cmds) |
| 162 | }) |
| 163 | } |