Mercurial > vim
comparison src/testing.c @ 22165:c512e6f57ff2 v8.2.1632
patch 8.2.1632: not checking the context of test_fails()
Commit: https://github.com/vim/vim/commit/44d6652d561d628d12e3ff7f6636ea7d1f805ced
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Sep 6 22:26:57 2020 +0200
patch 8.2.1632: not checking the context of test_fails()
Problem: Not checking the context of test_fails().
Solution: Add the line number and context arguments. Give error if
assert_fails() argument types are wrong.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 06 Sep 2020 22:30:03 +0200 |
parents | b6d36f0b4f03 |
children | a607f02fd17a |
comparison
equal
deleted
inserted
replaced
22164:7b7500b8b68e | 22165:c512e6f57ff2 |
---|---|
548 { | 548 { |
549 char_u *cmd = tv_get_string_chk(&argvars[0]); | 549 char_u *cmd = tv_get_string_chk(&argvars[0]); |
550 garray_T ga; | 550 garray_T ga; |
551 int save_trylevel = trylevel; | 551 int save_trylevel = trylevel; |
552 int called_emsg_before = called_emsg; | 552 int called_emsg_before = called_emsg; |
553 int wrong_arg = FALSE; | 553 char *wrong_arg_msg = NULL; |
554 | 554 |
555 // trylevel must be zero for a ":throw" command to be considered failed | 555 // trylevel must be zero for a ":throw" command to be considered failed |
556 trylevel = 0; | 556 trylevel = 0; |
557 suppress_errthrow = TRUE; | 557 suppress_errthrow = TRUE; |
558 emsg_silent = TRUE; | 558 emsg_silent = TRUE; |
588 list_T *list = argvars[1].vval.v_list; | 588 list_T *list = argvars[1].vval.v_list; |
589 typval_T *tv; | 589 typval_T *tv; |
590 | 590 |
591 if (list == NULL || list->lv_len < 1 || list->lv_len > 2) | 591 if (list == NULL || list->lv_len < 1 || list->lv_len > 2) |
592 { | 592 { |
593 wrong_arg = TRUE; | 593 wrong_arg_msg = e_assert_fails_second_arg; |
594 goto theend; | 594 goto theend; |
595 } | 595 } |
596 CHECK_LIST_MATERIALIZE(list); | 596 CHECK_LIST_MATERIALIZE(list); |
597 tv = &list->lv_first->li_tv; | 597 tv = &list->lv_first->li_tv; |
598 expected = tv_get_string_buf_chk(tv, buf); | 598 expected = tv_get_string_buf_chk(tv, buf); |
609 error_found = TRUE; | 609 error_found = TRUE; |
610 } | 610 } |
611 } | 611 } |
612 else | 612 else |
613 { | 613 { |
614 wrong_arg = TRUE; | 614 wrong_arg_msg = e_assert_fails_second_arg; |
615 goto theend; | 615 goto theend; |
616 } | 616 } |
617 | 617 |
618 if (!error_found && argvars[2].v_type != VAR_UNKNOWN | 618 if (!error_found && argvars[2].v_type != VAR_UNKNOWN |
619 && argvars[3].v_type == VAR_NUMBER) | 619 && argvars[3].v_type != VAR_UNKNOWN) |
620 { | 620 { |
621 if (argvars[3].vval.v_number >= 0 | 621 if (argvars[3].v_type != VAR_NUMBER) |
622 && argvars[3].vval.v_number != emsg_assert_fails_lnum) | 622 { |
623 wrong_arg_msg = e_assert_fails_fourth_argument; | |
624 goto theend; | |
625 } | |
626 else if (argvars[3].vval.v_number >= 0 | |
627 && argvars[3].vval.v_number != emsg_assert_fails_lnum) | |
623 { | 628 { |
624 error_found = TRUE; | 629 error_found = TRUE; |
625 error_found_index = 3; | 630 error_found_index = 3; |
626 } | 631 } |
627 if (!error_found && argvars[4].v_type == VAR_STRING | 632 if (!error_found && argvars[4].v_type != VAR_UNKNOWN) |
628 && argvars[4].vval.v_string != NULL | 633 { |
634 if (argvars[4].v_type != VAR_STRING) | |
635 { | |
636 wrong_arg_msg = e_assert_fails_fifth_argument; | |
637 goto theend; | |
638 } | |
639 else if (argvars[4].vval.v_string != NULL | |
629 && !pattern_match(argvars[4].vval.v_string, | 640 && !pattern_match(argvars[4].vval.v_string, |
630 emsg_assert_fails_context, FALSE)) | 641 emsg_assert_fails_context, FALSE)) |
631 { | 642 { |
632 error_found = TRUE; | 643 error_found = TRUE; |
633 error_found_index = 4; | 644 error_found_index = 4; |
645 } | |
634 } | 646 } |
635 } | 647 } |
636 | 648 |
637 if (error_found) | 649 if (error_found) |
638 { | 650 { |
670 emsg_silent = FALSE; | 682 emsg_silent = FALSE; |
671 emsg_on_display = FALSE; | 683 emsg_on_display = FALSE; |
672 emsg_assert_fails_used = FALSE; | 684 emsg_assert_fails_used = FALSE; |
673 VIM_CLEAR(emsg_assert_fails_msg); | 685 VIM_CLEAR(emsg_assert_fails_msg); |
674 set_vim_var_string(VV_ERRMSG, NULL, 0); | 686 set_vim_var_string(VV_ERRMSG, NULL, 0); |
675 if (wrong_arg) | 687 if (wrong_arg_msg != NULL) |
676 emsg(_("E856: assert_fails() second argument must be a string or a list with one or two strings")); | 688 emsg(_(wrong_arg_msg)); |
677 } | 689 } |
678 | 690 |
679 /* | 691 /* |
680 * "assert_false(actual[, msg])" function | 692 * "assert_false(actual[, msg])" function |
681 */ | 693 */ |