From 74474324713025b86797fdb01844eaa9ccab5092 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sun, 11 Mar 2018 17:16:53 -0500 Subject: [PATCH] Fix tests for new `)` token error --- src/fish_tests.cpp | 14 ++++++++++++-- src/tokenizer.cpp | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 3ccd7ad25..71ee33a94 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -578,6 +578,15 @@ static void test_tokenizer() { do_test(token.error_offset == 3); } + { + tokenizer_t t(L"abc )defg(hij", 0); + do_test(t.next(&token)); + do_test(t.next(&token)); + do_test(token.type == TOK_ERROR); + do_test(token.error == TOK_CLOSING_UNOPENED_SUBSHELL); + do_test(token.error_offset == 4); + } + { tokenizer_t t(L"abc defg(hij (klm)", 0); do_test(t.next(&token)); @@ -4420,10 +4429,11 @@ static void test_illegal_command_exit_code() { const command_result_tuple_t tests[] = { {L"echo -n", STATUS_CMD_OK}, {L"pwd", STATUS_CMD_OK}, - {L")", STATUS_ILLEGAL_CMD}, {L") ", STATUS_ILLEGAL_CMD}, + // a `)` without a matching `(` is now a tokenizer error, and cannot be executed even as an illegal command + // {L")", STATUS_ILLEGAL_CMD}, {L") ", STATUS_ILLEGAL_CMD}, {L") ", STATUS_ILLEGAL_CMD} {L"*", STATUS_ILLEGAL_CMD}, {L"**", STATUS_ILLEGAL_CMD}, {L"?", STATUS_ILLEGAL_CMD}, {L"abc?def", STATUS_ILLEGAL_CMD}, - {L") ", STATUS_ILLEGAL_CMD}}; + }; int res = 0; const io_chain_t empty_ios; diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index c216e1972..f2ff61267 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -180,7 +180,7 @@ tok_t tokenizer_t::read_string() { else if (c == L')') { switch (paran_offsets.size()) { case 0: - return this->call_error(TOK_CLOSING_UNOPENED_SUBSHELL, buff_start, this->buff); + return this->call_error(TOK_CLOSING_UNOPENED_SUBSHELL, this->start, this->buff); case 1: mode &= ~(tok_mode::subshell); default: @@ -195,7 +195,7 @@ tok_t tokenizer_t::read_string() { //prints an error message with the caret pointing at token_start, //not err_loc, making the TOK_ILLEGAL_SLICE message misleading. // return call_error(TOK_ILLEGAL_SLICE, buff_start, this->buff); - return call_error(TOK_UNTERMINATED_SLICE, buff_start, this->buff); + return this->call_error(TOK_UNTERMINATED_SLICE, this->start, this->buff); } slice_offset = this->buff - this->start; mode |= tok_mode::array_brackets;