diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-01-15 20:48:22 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-01-15 20:48:22 +0100 |
commit | a260b87d9da17f605666630f18c1ed909c2b8bae (patch) | |
tree | 03fb7aaf4b31ace780c4b040537e65c695b63457 /src | |
parent | 3d6d5cc3a417c04d9772596ea83f8e6b41321781 (diff) | |
download | vim-git-a260b87d9da17f605666630f18c1ed909c2b8bae.tar.gz |
patch 7.4.1096v7.4.1096
Problem: Need several lines to verify a command produces an error.
Solution: Add assert_fails(). (suggested by Nikolay Pavlov)
Make the quickfix alloc test actually work.
Diffstat (limited to 'src')
-rw-r--r-- | src/alloc.h | 1 | ||||
-rw-r--r-- | src/eval.c | 50 | ||||
-rw-r--r-- | src/misc2.c | 10 | ||||
-rw-r--r-- | src/testdir/test_quickfix.vim | 30 | ||||
-rw-r--r-- | src/version.c | 2 |
5 files changed, 65 insertions, 28 deletions
diff --git a/src/alloc.h b/src/alloc.h index c237ef348..7a992c689 100644 --- a/src/alloc.h +++ b/src/alloc.h @@ -17,4 +17,5 @@ typedef enum { aid_qf_namebuf, aid_qf_errmsg, aid_qf_pattern, + aid_last, } alloc_id_T; diff --git a/src/eval.c b/src/eval.c index 5eddf2368..ac1058cf0 100644 --- a/src/eval.c +++ b/src/eval.c @@ -476,6 +476,7 @@ static void f_arglistid __ARGS((typval_T *argvars, typval_T *rettv)); static void f_argv __ARGS((typval_T *argvars, typval_T *rettv)); static void f_assert_equal __ARGS((typval_T *argvars, typval_T *rettv)); static void f_assert_exception __ARGS((typval_T *argvars, typval_T *rettv)); +static void f_assert_fails __ARGS((typval_T *argvars, typval_T *rettv)); static void f_assert_false __ARGS((typval_T *argvars, typval_T *rettv)); static void f_assert_true __ARGS((typval_T *argvars, typval_T *rettv)); #ifdef FEAT_FLOAT @@ -8090,6 +8091,7 @@ static struct fst #endif {"assert_equal", 2, 3, f_assert_equal}, {"assert_exception", 1, 2, f_assert_exception}, + {"assert_fails", 1, 2, f_assert_fails}, {"assert_false", 1, 2, f_assert_false}, {"assert_true", 1, 2, f_assert_true}, #ifdef FEAT_FLOAT @@ -9009,8 +9011,11 @@ f_alloc_fail(argvars, rettv) else { alloc_fail_id = argvars[0].vval.v_number; + if (alloc_fail_id >= aid_last) + EMSG(_(e_invarg)); alloc_fail_countdown = argvars[1].vval.v_number; alloc_fail_repeat = argvars[2].vval.v_number; + did_outofmem_msg = FALSE; } } @@ -9301,6 +9306,51 @@ f_assert_exception(argvars, rettv) } /* + * "assert_fails(cmd [, error])" function + */ + static void +f_assert_fails(argvars, rettv) + typval_T *argvars; + typval_T *rettv UNUSED; +{ + char_u *cmd = get_tv_string_chk(&argvars[0]); + garray_T ga; + + called_emsg = FALSE; + suppress_errthrow = TRUE; + emsg_silent = TRUE; + do_cmdline_cmd(cmd); + if (!called_emsg) + { + prepare_assert_error(&ga); + ga_concat(&ga, (char_u *)"command did not fail: "); + ga_concat(&ga, cmd); + assert_error(&ga); + ga_clear(&ga); + } + else if (argvars[1].v_type != VAR_UNKNOWN) + { + char_u buf[NUMBUFLEN]; + char *error = (char *)get_tv_string_buf_chk(&argvars[1], buf); + + if (strstr((char *)vimvars[VV_ERRMSG].vv_str, error) == NULL) + { + prepare_assert_error(&ga); + fill_assert_error(&ga, &argvars[2], NULL, &argvars[1], + &vimvars[VV_ERRMSG].vv_tv); + assert_error(&ga); + ga_clear(&ga); + } + } + + called_emsg = FALSE; + suppress_errthrow = FALSE; + emsg_silent = FALSE; + emsg_on_display = FALSE; + set_vim_var_string(VV_ERRMSG, NULL, 0); +} + +/* * Common for assert_true() and assert_false(). */ static void diff --git a/src/misc2.c b/src/misc2.c index 854021255..0ee57fc4a 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -798,13 +798,17 @@ vim_mem_profile_dump() #endif /* MEM_PROFILE */ #ifdef FEAT_EVAL +static int alloc_does_fail __ARGS((long_u size)); + static int -alloc_does_fail() +alloc_does_fail(size) + long_u size; { if (alloc_fail_countdown == 0) { if (--alloc_fail_repeat <= 0) alloc_fail_id = 0; + do_outofmem_msg(size); return TRUE; } --alloc_fail_countdown; @@ -844,7 +848,7 @@ alloc_id(size, id) alloc_id_T id UNUSED; { #ifdef FEAT_EVAL - if (alloc_fail_id == id && alloc_does_fail()) + if (alloc_fail_id == id && alloc_does_fail((long_u)size)) return NULL; #endif return (lalloc((long_u)size, TRUE)); @@ -1008,7 +1012,7 @@ lalloc_id(size, message, id) alloc_id_T id UNUSED; { #ifdef FEAT_EVAL - if (alloc_fail_id == id && alloc_does_fail()) + if (alloc_fail_id == id && alloc_does_fail(size)) return NULL; #endif return (lalloc((long_u)size, message)); diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim index b9f3f7bbb..b2fc9683a 100644 --- a/src/testdir/test_quickfix.vim +++ b/src/testdir/test_quickfix.vim @@ -279,39 +279,19 @@ endfunction function Test_nomem() call alloc_fail(GetAllocId('qf_dirname_start'), 0, 0) - try - vimgrep vim runtest.vim - catch - call assert_true(v:exception =~ 'E342') - endtry + call assert_fails('vimgrep vim runtest.vim', 'E342:') call alloc_fail(GetAllocId('qf_dirname_now'), 0, 0) - try - vimgrep vim runtest.vim - catch - call assert_true(v:exception =~ 'E342') - endtry + call assert_fails('vimgrep vim runtest.vim', 'E342:') call alloc_fail(GetAllocId('qf_namebuf'), 0, 0) - try - cfile runtest.vim - catch - call assert_true(v:exception =~ 'E342') - endtry + call assert_fails('cfile runtest.vim', 'E342:') call alloc_fail(GetAllocId('qf_errmsg'), 0, 0) - try - cfile runtest.vim - catch - call assert_true(v:exception =~ 'E342') - endtry + call assert_fails('cfile runtest.vim', 'E342:') call alloc_fail(GetAllocId('qf_pattern'), 0, 0) - try - cfile runtest.vim - catch - call assert_true(v:exception =~ 'E342') - endtry + call assert_fails('cfile runtest.vim', 'E342:') endfunc diff --git a/src/version.c b/src/version.c index 2c92c175f..b84211680 100644 --- a/src/version.c +++ b/src/version.c @@ -742,6 +742,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1096, +/**/ 1095, /**/ 1094, |