diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-09-06 21:47:48 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-09-06 21:47:48 +0200 |
commit | 9bd5d879c2ecfbdbb168b090e12f4b89724a302e (patch) | |
tree | e9c9a342ba1d31c884d65edcbe864ba35518cf51 /src/testing.c | |
parent | c98cdb3bc970f04f93b4c394b4ec94c2eb5546c3 (diff) | |
download | vim-git-9bd5d879c2ecfbdbb168b090e12f4b89724a302e.tar.gz |
patch 8.2.1631: test_fails() does not check the context of the line numberv8.2.1631
Problem: test_fails() does not check the context of the line number.
Solution: Use another argument to specify the context of the line number.
Diffstat (limited to 'src/testing.c')
-rw-r--r-- | src/testing.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/testing.c b/src/testing.c index ed2d511f2..5f7858d89 100644 --- a/src/testing.c +++ b/src/testing.c @@ -573,7 +573,7 @@ f_assert_fails(typval_T *argvars, typval_T *rettv) char_u buf[NUMBUFLEN]; char_u *expected; int error_found = FALSE; - int lnum_error_found = FALSE; + int error_found_index = 1; char_u *actual = emsg_assert_fails_msg == NULL ? (char_u *)"[unknown]" : emsg_assert_fails_msg; @@ -616,12 +616,22 @@ f_assert_fails(typval_T *argvars, typval_T *rettv) } if (!error_found && argvars[2].v_type != VAR_UNKNOWN - && argvars[3].v_type == VAR_NUMBER - && argvars[3].vval.v_number >= 0 - && argvars[3].vval.v_number != emsg_assert_fails_lnum) + && argvars[3].v_type == VAR_NUMBER) { - error_found = TRUE; - lnum_error_found = TRUE; + if (argvars[3].vval.v_number >= 0 + && argvars[3].vval.v_number != emsg_assert_fails_lnum) + { + error_found = TRUE; + error_found_index = 3; + } + if (!error_found && argvars[4].v_type == VAR_STRING + && argvars[4].vval.v_string != NULL + && !pattern_match(argvars[4].vval.v_string, + emsg_assert_fails_context, FALSE)) + { + error_found = TRUE; + error_found_index = 4; + } } if (error_found) @@ -629,19 +639,23 @@ f_assert_fails(typval_T *argvars, typval_T *rettv) typval_T actual_tv; prepare_assert_error(&ga); - if (lnum_error_found) + if (error_found_index == 3) { actual_tv.v_type = VAR_NUMBER; actual_tv.vval.v_number = emsg_assert_fails_lnum; } + else if (error_found_index == 4) + { + actual_tv.v_type = VAR_STRING; + actual_tv.vval.v_string = emsg_assert_fails_context; + } else { actual_tv.v_type = VAR_STRING; actual_tv.vval.v_string = actual; } fill_assert_error(&ga, &argvars[2], NULL, - &argvars[lnum_error_found ? 3 : 1], - &actual_tv, ASSERT_OTHER); + &argvars[error_found_index], &actual_tv, ASSERT_OTHER); ga_concat(&ga, (char_u *)": "); assert_append_cmd_or_arg(&ga, argvars, cmd); assert_error(&ga); |