commit 82f49c6a373f981a778f4d939ca2d47c031e0659 (HEAD, refs/remotes/origin/master) Author: Paul Eggert Date: Wed Jun 8 10:33:34 2016 -0700 Replace IF_LINT by NONVOLATILE and UNINIT Inspired by a suggestion from RMS in: http://bugs.gnu.org/23640#58 * .dir-locals.el (c-mode): Adjust to macro changes. * src/conf_post.h (NONVOLATILE, UNINIT): New macros (Bug#23640). (IF_LINT): Remove. All uses replaced by the new macros. diff --git a/.dir-locals.el b/.dir-locals.el index 7c14802..97e5180 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -2,7 +2,7 @@ (sentence-end-double-space . t) (fill-column . 70))) (c-mode . ((c-file-style . "GNU") - (c-noise-macro-with-parens-names . ("IF_LINT")))) + (c-noise-macro-names . ("NONVOLATILE" "UNINIT")))) (objc-mode . ((c-file-style . "GNU"))) (log-edit-mode . ((log-edit-font-lock-gnu-style . t) (log-edit-setup-add-author . t))) diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c index 32e3817..f463f13 100644 --- a/lib-src/make-docfile.c +++ b/lib-src/make-docfile.c @@ -491,7 +491,7 @@ write_c_args (char *func, char *buf, int minargs, int maxargs) { char *p; bool in_ident = false; - char *ident_start IF_LINT (= NULL); + char *ident_start UNINIT; ptrdiff_t ident_length = 0; fputs ("(fn", stdout); diff --git a/src/buffer.c b/src/buffer.c index 534b9e4..af8c732 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -3907,7 +3907,8 @@ buffer. */) struct buffer *b, *ob = 0; Lisp_Object obuffer; ptrdiff_t count = SPECPDL_INDEX (); - ptrdiff_t n_beg, n_end, o_beg IF_LINT (= 0), o_end IF_LINT (= 0); + ptrdiff_t n_beg, n_end; + ptrdiff_t o_beg UNINIT, o_end UNINIT; CHECK_OVERLAY (overlay); if (NILP (buffer)) diff --git a/src/charset.c b/src/charset.c index 1a13584..6882052 100644 --- a/src/charset.c +++ b/src/charset.c @@ -240,7 +240,8 @@ struct charset_map_entries static void load_charset_map (struct charset *charset, struct charset_map_entries *entries, int n_entries, int control_flag) { - Lisp_Object vec, table IF_LINT (= Qnil); + Lisp_Object vec; + Lisp_Object table UNINIT; unsigned max_code = CHARSET_MAX_CODE (charset); bool ascii_compatible_p = charset->ascii_compatible_p; int min_char, max_char, nonascii_min_char; diff --git a/src/cm.c b/src/cm.c index 4f94c07..e135889 100644 --- a/src/cm.c +++ b/src/cm.c @@ -321,7 +321,7 @@ cmgoto (struct tty_display_info *tty, int row, int col) llcost, relcost, directcost; - int use IF_LINT (= 0); + int use UNINIT; char *p; const char *dcm; diff --git a/src/coding.c b/src/coding.c index a28fec1..3f7d111 100644 --- a/src/coding.c +++ b/src/coding.c @@ -2365,7 +2365,8 @@ decode_coding_emacs_mule (struct coding_system *coding) while (1) { - int c, id IF_LINT (= 0); + int c; + int id UNINIT; src_base = src; consumed_chars_base = consumed_chars; @@ -2410,7 +2411,7 @@ decode_coding_emacs_mule (struct coding_system *coding) } else { - int nchars IF_LINT (= 0), nbytes IF_LINT (= 0); + int nchars UNINIT, nbytes UNINIT; /* emacs_mule_char can load a charset map from a file, which allocates a large structure and might cause buffer text to be relocated as result. Thus, we need to remember the @@ -8565,8 +8566,8 @@ detect_coding_system (const unsigned char *src, base_category = XINT (CODING_ATTR_CATEGORY (attrs)); if (base_category == coding_category_undecided) { - enum coding_category category IF_LINT (= 0); - struct coding_system *this IF_LINT (= NULL); + enum coding_category category UNINIT; + struct coding_system *this UNINIT; int c, i; bool inhibit_nbd = inhibit_flag (coding.spec.undecided.inhibit_nbd, inhibit_null_byte_detection); diff --git a/src/composite.c b/src/composite.c index 49b0003..bef1c5f 100644 --- a/src/composite.c +++ b/src/composite.c @@ -1308,7 +1308,8 @@ composition_reseat_it (struct composition_it *cmp_it, ptrdiff_t charpos, int composition_update_it (struct composition_it *cmp_it, ptrdiff_t charpos, ptrdiff_t bytepos, Lisp_Object string) { - int i, c IF_LINT (= 0); + int i; + int c UNINIT; if (cmp_it->ch < 0) { diff --git a/src/conf_post.h b/src/conf_post.h index 762aa77..1dd915b 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -357,11 +357,21 @@ extern int emacs_setenv_TZ (char const *); # define FLEXIBLE_ARRAY_MEMBER #endif -/* Use CODE only if lint checking is in effect. */ +/* When used in place of 'volatile', 'NONVOLATILE' is equivalent to nothing, + except it cajoles GCC into not warning incorrectly that a variable needs to + be volatile. This works around GCC bug 54561. */ #if defined GCC_LINT || defined lint -# define IF_LINT(Code) Code +# define NONVOLATILE volatile #else -# define IF_LINT(Code) /* empty */ +# define NONVOLATILE /* empty */ +#endif + +/* 'int x UNINIT;' is equivalent to 'int x;', except it cajoles GCC + into not warning incorrectly about use of an uninitialized variable. */ +#if defined GCC_LINT || defined lint +# define UNINIT = {0,} +#else +# define UNINIT /* empty */ #endif /* conf_post.h ends here */ diff --git a/src/editfns.c b/src/editfns.c index 81c30d3..f29fc51 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -3362,7 +3362,7 @@ It returns the number of characters changed. */) ptrdiff_t size; /* Size of translate table. */ ptrdiff_t pos, pos_byte, end_pos; bool multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); - bool string_multibyte IF_LINT (= 0); + bool string_multibyte UNINIT; validate_region (&start, &end); if (CHAR_TABLE_P (table)) @@ -3917,7 +3917,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message) ptrdiff_t bufsize = sizeof initial_buffer; ptrdiff_t max_bufsize = STRING_BYTES_BOUND + 1; char *p; - ptrdiff_t buf_save_value_index IF_LINT (= 0); + ptrdiff_t buf_save_value_index UNINIT; char *format, *end; ptrdiff_t nchars; /* When we make a multibyte string, we must pay attention to the diff --git a/src/fileio.c b/src/fileio.c index 9e3e54d..9984045 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -4687,7 +4687,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, { int open_flags; int mode; - off_t offset IF_LINT (= 0); + off_t offset UNINIT; bool open_and_close_file = desc < 0; bool ok; int save_errno = 0; @@ -4695,7 +4695,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, struct stat st; struct timespec modtime; ptrdiff_t count = SPECPDL_INDEX (); - ptrdiff_t count1 IF_LINT (= 0); + ptrdiff_t count1 UNINIT; Lisp_Object handler; Lisp_Object visit_file; Lisp_Object annotations; diff --git a/src/font.c b/src/font.c index 6dbda40..f289891 100644 --- a/src/font.c +++ b/src/font.c @@ -2234,7 +2234,8 @@ font_sort_entities (Lisp_Object list, Lisp_Object prefer, struct font_sort_data *data; unsigned best_score; Lisp_Object best_entity; - Lisp_Object tail, vec IF_LINT (= Qnil); + Lisp_Object tail; + Lisp_Object vec UNINIT; USE_SAFE_ALLOCA; for (i = FONT_WEIGHT_INDEX; i <= FONT_AVGWIDTH_INDEX; i++) diff --git a/src/fontset.c b/src/fontset.c index d87901d..81528de 100644 --- a/src/fontset.c +++ b/src/fontset.c @@ -750,7 +750,8 @@ fontset_find_font (Lisp_Object fontset, int c, struct face *face, static Lisp_Object fontset_font (Lisp_Object fontset, int c, struct face *face, int id) { - Lisp_Object rfont_def, default_rfont_def IF_LINT (= Qnil); + Lisp_Object rfont_def; + Lisp_Object default_rfont_def UNINIT; Lisp_Object base_fontset; /* Try a font-group of FONTSET. */ diff --git a/src/fringe.c b/src/fringe.c index 55f37b8..87ec9d1 100644 --- a/src/fringe.c +++ b/src/fringe.c @@ -956,7 +956,7 @@ update_window_fringes (struct window *w, bool keep_current_p) row->indicate_bob_p is set, so it's OK that top_row_ends_at_zv_p is not initialized here. Similarly for bot_ind_rn, row->indicate_eob_p and bot_row_ends_at_zv_p. */ - int top_row_ends_at_zv_p IF_LINT (= 0), bot_row_ends_at_zv_p IF_LINT (= 0); + int top_row_ends_at_zv_p UNINIT, bot_row_ends_at_zv_p UNINIT; if (w->pseudo_window_p) return 0; diff --git a/src/gtkutil.c b/src/gtkutil.c index e791e6a..88e6d30 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -1829,7 +1829,8 @@ xg_get_file_with_chooser (struct frame *f, { char msgbuf[1024]; - GtkWidget *filewin, *wtoggle, *wbox, *wmessage IF_LINT (= NULL); + GtkWidget *filewin, *wtoggle, *wbox; + GtkWidget *wmessage UNINIT; GtkWindow *gwin = GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)); GtkFileChooserAction action = (mustmatch_p ? GTK_FILE_CHOOSER_ACTION_OPEN : diff --git a/src/image.c b/src/image.c index 0991f57..38866e0 100644 --- a/src/image.c +++ b/src/image.c @@ -1142,7 +1142,8 @@ static RGB_PIXEL_COLOR four_corners_best (XImagePtr_or_DC ximg, int *corners, unsigned long width, unsigned long height) { - RGB_PIXEL_COLOR corner_pixels[4], best IF_LINT (= 0); + RGB_PIXEL_COLOR corner_pixels[4]; + RGB_PIXEL_COLOR best UNINIT; int i, best_count; if (corners && corners[BOT_CORNER] >= 0) @@ -5895,9 +5896,8 @@ static bool png_load_body (struct frame *f, struct image *img, struct png_load_context *c) { Lisp_Object specified_file; - /* IF_LINT (volatile) works around GCC bug 54561. */ - Lisp_Object IF_LINT (volatile) specified_data; - FILE * IF_LINT (volatile) fp = NULL; + Lisp_Object NONVOLATILE specified_data; + FILE *NONVOLATILE fp = NULL; int x, y; ptrdiff_t i; png_struct *png_ptr; @@ -6668,8 +6668,7 @@ jpeg_load_body (struct frame *f, struct image *img, struct my_jpeg_error_mgr *mgr) { Lisp_Object specified_file; - /* IF_LINT (volatile) works around GCC bug 54561. */ - Lisp_Object IF_LINT (volatile) specified_data; + Lisp_Object NONVOLATILE specified_data; FILE *volatile fp = NULL; JSAMPARRAY buffer; int row_stride, x, y; diff --git a/src/indent.c b/src/indent.c index 0ef8903..5d7c6ae 100644 --- a/src/indent.c +++ b/src/indent.c @@ -1995,7 +1995,7 @@ whether or not it is currently displayed in some window. */) struct text_pos pt; struct window *w; Lisp_Object old_buffer; - EMACS_INT old_charpos IF_LINT (= 0), old_bytepos IF_LINT (= 0); + EMACS_INT old_charpos UNINIT, old_bytepos UNINIT; Lisp_Object lcols; void *itdata = NULL; @@ -2036,8 +2036,8 @@ whether or not it is currently displayed in some window. */) bool disp_string_at_start_p = 0; ptrdiff_t nlines = XINT (lines); int vpos_init = 0; - double start_col IF_LINT (= 0); - int start_x IF_LINT (= 0); + double start_col UNINIT; + int start_x UNINIT; int to_x = -1; bool start_x_given = !NILP (cur_col); diff --git a/src/keyboard.c b/src/keyboard.c index d2976cb..717c071 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -2312,9 +2312,7 @@ read_char (int commandflag, Lisp_Object map, Lisp_Object prev_event, bool *used_mouse_menu, struct timespec *end_time) { - /* IF_LINT (volatile) works around GCC bug 54561. */ - Lisp_Object IF_LINT (volatile) c; - + Lisp_Object NONVOLATILE c; ptrdiff_t jmpcount; sys_jmp_buf local_getcjmp; sys_jmp_buf save_jump; @@ -8843,7 +8841,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, /* The length of the echo buffer when we started reading, and the length of this_command_keys when we started reading. */ - ptrdiff_t echo_start IF_LINT (= 0); + ptrdiff_t echo_start UNINIT; ptrdiff_t keys_start; Lisp_Object current_binding = Qnil; @@ -8891,7 +8889,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, While we're reading, we keep the event here. */ Lisp_Object delayed_switch_frame; - Lisp_Object original_uppercase IF_LINT (= Qnil); + Lisp_Object original_uppercase UNINIT; int original_uppercase_position = -1; /* Gets around Microsoft compiler limitations. */ @@ -9001,7 +8999,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, while those allow us to restart the entire key sequence, echo_local_start and keys_local_start allow us to throw away just one key. */ - ptrdiff_t echo_local_start IF_LINT (= 0); + ptrdiff_t echo_local_start UNINIT; int keys_local_start; Lisp_Object new_binding; diff --git a/src/lread.c b/src/lread.c index 98a4d69..b08ce17 100644 --- a/src/lread.c +++ b/src/lread.c @@ -1040,7 +1040,7 @@ Return t if the file exists and loads successfully. */) { FILE *stream; int fd; - int fd_index; + int fd_index UNINIT; ptrdiff_t count = SPECPDL_INDEX (); Lisp_Object found, efound, hist_file_name; /* True means we printed the ".el is newer" message. */ @@ -1156,12 +1156,7 @@ Return t if the file exists and loads successfully. */) #endif } - if (fd < 0) - { - /* Pacify older GCC with --enable-gcc-warnings. */ - IF_LINT (fd_index = 0); - } - else + if (0 <= fd) { fd_index = SPECPDL_INDEX (); record_unwind_protect_int (close_file_unwind, fd); diff --git a/src/minibuf.c b/src/minibuf.c index 7583161..7bad6f0 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -194,7 +194,7 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, int c; unsigned char hide_char = 0; struct emacs_tty etty; - bool etty_valid IF_LINT (= false); + bool etty_valid UNINIT; /* Check, whether we need to suppress echoing. */ if (CHARACTERP (Vread_hide_char)) diff --git a/src/print.c b/src/print.c index 83edbb6..5531210 100644 --- a/src/print.c +++ b/src/print.c @@ -203,7 +203,7 @@ print_unwind (Lisp_Object saved_text) static void printchar_to_stream (unsigned int ch, FILE *stream) { - Lisp_Object dv IF_LINT (= Qnil); + Lisp_Object dv UNINIT; ptrdiff_t i = 0, n = 1; Lisp_Object coding_system = Vlocale_coding_system; bool encode_p = false; diff --git a/src/regex.c b/src/regex.c index fc2a46f..f92bcb7 100644 --- a/src/regex.c +++ b/src/regex.c @@ -5444,7 +5444,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1, /* Start of actual range_table, or end of bitmap if there is no range table. */ - re_char *range_table IF_LINT (= NULL); + re_char *range_table UNINIT; /* Nonzero if there is a range table. */ int range_table_exists; diff --git a/src/syntax.c b/src/syntax.c index 78c7de9..1c1a2f8 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -1633,7 +1633,7 @@ skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim, int c; char fastmap[0400]; /* Store the ranges of non-ASCII characters. */ - int *char_ranges IF_LINT (= NULL); + int *char_ranges UNINIT; int n_char_ranges = 0; bool negate = 0; ptrdiff_t i, i_byte; diff --git a/src/term.c b/src/term.c index df583cb..7e63a0c 100644 --- a/src/term.c +++ b/src/term.c @@ -548,8 +548,8 @@ encode_terminal_code (struct glyph *src, int src_len, { if (src->type == COMPOSITE_GLYPH) { - struct composition *cmp IF_LINT (= NULL); - Lisp_Object gstring IF_LINT (= Qnil); + struct composition *cmp UNINIT; + Lisp_Object gstring UNINIT; int i; nbytes = buf - encode_terminal_src; @@ -614,7 +614,7 @@ encode_terminal_code (struct glyph *src, int src_len, else if (! CHAR_GLYPH_PADDING_P (*src)) { GLYPH g; - int c IF_LINT (= 0); + int c UNINIT; Lisp_Object string; string = Qnil; @@ -3099,7 +3099,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx, struct tty_menu_state *state; int statecount, x, y, i; bool leave, onepane; - int result IF_LINT (= 0); + int result UNINIT; int title_faces[4]; /* Face to display the menu title. */ int faces[4], buffers_num_deleted = 0; struct frame *sf = SELECTED_FRAME (); diff --git a/src/window.c b/src/window.c index 99a0709..fe10241 100644 --- a/src/window.c +++ b/src/window.c @@ -2910,9 +2910,11 @@ window-start value is reasonable when this function is called. */) { struct window *w, *r, *s; struct frame *f; - Lisp_Object sibling, pwindow, swindow IF_LINT (= Qnil), delta; - ptrdiff_t startpos IF_LINT (= 0), startbyte IF_LINT (= 0); - int top IF_LINT (= 0), new_top; + Lisp_Object sibling, pwindow, delta; + Lisp_Object swindow UNINIT; + ptrdiff_t startpos UNINIT, startbyte UNINIT; + int top UNINIT; + int new_top; bool resize_failed = false; w = decode_valid_window (window); diff --git a/src/xdisp.c b/src/xdisp.c index d2f0d49..d589080 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -8558,7 +8558,8 @@ move_it_in_display_line_to (struct it *it, void *ppos_data = NULL; bool may_wrap = false; enum it_method prev_method = it->method; - ptrdiff_t closest_pos IF_LINT (= 0), prev_pos = IT_CHARPOS (*it); + ptrdiff_t closest_pos UNINIT; + ptrdiff_t prev_pos = IT_CHARPOS (*it); bool saw_smaller_pos = prev_pos < to_charpos; /* Don't produce glyphs in produce_glyphs. */ @@ -20416,16 +20417,16 @@ display_line (struct it *it) struct it wrap_it; void *wrap_data = NULL; bool may_wrap = false; - int wrap_x IF_LINT (= 0); + int wrap_x UNINIT; int wrap_row_used = -1; - int wrap_row_ascent IF_LINT (= 0), wrap_row_height IF_LINT (= 0); - int wrap_row_phys_ascent IF_LINT (= 0), wrap_row_phys_height IF_LINT (= 0); - int wrap_row_extra_line_spacing IF_LINT (= 0); - ptrdiff_t wrap_row_min_pos IF_LINT (= 0), wrap_row_min_bpos IF_LINT (= 0); - ptrdiff_t wrap_row_max_pos IF_LINT (= 0), wrap_row_max_bpos IF_LINT (= 0); + int wrap_row_ascent UNINIT, wrap_row_height UNINIT; + int wrap_row_phys_ascent UNINIT, wrap_row_phys_height UNINIT; + int wrap_row_extra_line_spacing UNINIT; + ptrdiff_t wrap_row_min_pos UNINIT, wrap_row_min_bpos UNINIT; + ptrdiff_t wrap_row_max_pos UNINIT, wrap_row_max_bpos UNINIT; int cvpos; ptrdiff_t min_pos = ZV + 1, max_pos = 0; - ptrdiff_t min_bpos IF_LINT (= 0), max_bpos IF_LINT (= 0); + ptrdiff_t min_bpos UNINIT, max_bpos UNINIT; bool pending_handle_line_prefix = false; /* We always start displaying at hpos zero even if hscrolled. */ @@ -25595,7 +25596,7 @@ draw_glyphs (struct window *w, int x, struct glyph_row *row, { struct glyph_string *h, *t; Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); - int mouse_beg_col IF_LINT (= 0), mouse_end_col IF_LINT (= 0); + int mouse_beg_col UNINIT, mouse_end_col UNINIT; bool check_mouse_face = false; int dummy_x = 0; @@ -29702,12 +29703,11 @@ note_mode_line_or_margin_highlight (Lisp_Object window, int x, int y, int dx, dy, width, height; ptrdiff_t charpos; Lisp_Object string, object = Qnil; - Lisp_Object pos IF_LINT (= Qnil), help; - + Lisp_Object pos UNINIT; Lisp_Object mouse_face; int original_x_pixel = x; struct glyph * glyph = NULL, * row_start_glyph = NULL; - struct glyph_row *row IF_LINT (= 0); + struct glyph_row *row UNINIT; if (area == ON_MODE_LINE || area == ON_HEADER_LINE) { @@ -29747,7 +29747,7 @@ note_mode_line_or_margin_highlight (Lisp_Object window, int x, int y, &object, &dx, &dy, &width, &height); } - help = Qnil; + Lisp_Object help = Qnil; #ifdef HAVE_WINDOW_SYSTEM if (IMAGEP (object)) @@ -30322,8 +30322,8 @@ note_mouse_highlight (struct frame *f, int x, int y) { /* The mouse-highlighting, if any, comes from an overlay or text property in the buffer. */ - Lisp_Object buffer IF_LINT (= Qnil); - Lisp_Object disp_string IF_LINT (= Qnil); + Lisp_Object buffer UNINIT; + Lisp_Object disp_string UNINIT; if (STRINGP (object)) { diff --git a/src/xfont.c b/src/xfont.c index 0ef64be..8fbe94c 100644 --- a/src/xfont.c +++ b/src/xfont.c @@ -635,7 +635,7 @@ xfont_list_family (struct frame *f) char **names; int num_fonts, i; Lisp_Object list; - char *last_family IF_LINT (= 0); + char *last_family UNINIT; int last_len; block_input (); commit 7715ee54b3588cfdef03b5d45aaf44b73b422ec6 Author: Michal Nazarewicz Date: Tue Jun 7 22:32:59 2016 +0200 Remove ‘ert-with-function-mocked’ macro in favour of ‘cl-letf’ macro * lisp/emacs-lisp/ert-x.el (ert-with-function-mocked): Remove macro in favour of ‘cl-letf’ macro which is more generic. All existing uses are migrated accordingly. The macro has not been included in an official release yet so it should be fine to delete it. diff --git a/etc/NEWS b/etc/NEWS index 7f91721..e2c99a1 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -411,9 +411,6 @@ by setting 'autoload-timestamps' to nil. FIXME As an experiment, nil is the current default. If no insurmountable problems before next release, it can stay that way. -** 'ert-with-function-mocked' of 'ert-x package allows mocking of functions -in unit tests. - --- ** 'gnutls-boot' now takes a parameter :complete-negotiation that says that negotiation should complete even on non-blocking sockets. diff --git a/lisp/emacs-lisp/ert-x.el b/lisp/emacs-lisp/ert-x.el index 67cb102..2a2418f 100644 --- a/lisp/emacs-lisp/ert-x.el +++ b/lisp/emacs-lisp/ert-x.el @@ -285,46 +285,6 @@ BUFFER defaults to current buffer. Does not modify BUFFER." (kill-buffer clone))))))) -(defmacro ert-with-function-mocked (name mock &rest body) - "Mocks function NAME with MOCK and run BODY. - -Once BODY finishes (be it normally by returning a value or -abnormally by throwing or signaling), the old definition of -function NAME is restored. - -BODY may further change the mock with `fset'. - -If MOCK is nil, the function NAME is mocked with a function -`ert-fail'ing when called. - -For example: - - ;; Regular use, function is mocked inside the BODY: - (should (eq 2 (+ 1 1))) - (ert-with-function-mocked ((+ (lambda (a b) (- a b)))) - (should (eq 0 (+ 1 1)))) - (should (eq 2 (+ 1 1))) - - ;; Macro correctly recovers from a throw or signal: - (should - (catch 'done - (ert-with-function-mocked ((+ (lambda (a b) (- a b)))) - (should (eq 0 (+ 1 1)))) - (throw 'done t))) - (should (eq 2 (+ 1 1))) -" - (declare (indent 2)) - (let ((old-var (make-symbol "old-var")) - (mock-var (make-symbol "mock-var"))) - `(let ((,old-var (symbol-function (quote ,name))) (,mock-var ,mock)) - (fset (quote ,name) - (or ,mock-var (lambda (&rest _) - (ert-fail (concat "`" ,(symbol-name name) - "' unexpectedly called."))))) - (unwind-protect - (progn ,@body) - (fset (quote ,name) ,old-var))))) - (provide 'ert-x) ;;; ert-x.el ends here diff --git a/test/lisp/calendar/icalendar-tests.el b/test/lisp/calendar/icalendar-tests.el index 20d8834..6db4222 100644 --- a/test/lisp/calendar/icalendar-tests.el +++ b/test/lisp/calendar/icalendar-tests.el @@ -32,7 +32,6 @@ ;;; Code: (require 'ert) -(require 'ert-x) (require 'icalendar) ;; ====================================================================== @@ -64,7 +63,7 @@ (hash (format "%d" (abs (sxhash entry-full)))) (contents "DTSTART:19640630T070100\nblahblah") (username (or user-login-name "UNKNOWN_USER"))) - (ert-with-function-mocked current-time (lambda () '(1 2 3)) + (cl-letf (((symbol-function 'current-time) (lambda () '(1 2 3)))) (should (= 77 icalendar--uid-count)) (should (string= (concat "xxx-123-77-" hash "-" username "-19640630") (icalendar--create-uid entry-full contents))) diff --git a/test/lisp/emacs-lisp/ert-x-tests.el b/test/lisp/emacs-lisp/ert-x-tests.el index a2665e7..ef8642a 100644 --- a/test/lisp/emacs-lisp/ert-x-tests.el +++ b/test/lisp/emacs-lisp/ert-x-tests.el @@ -275,49 +275,6 @@ desired effect." (should (equal (c x) (lisp x)))))) -(defun ert--dummy-id (a) - "Identity function. Used for tests only." - a) - -(ert-deftest ert-with-function-mocked () - (let ((mock-id (lambda (_) 21))) - (should (eq 42 (ert--dummy-id 42))) - - (ert-with-function-mocked ert--dummy-id nil - (fset 'ert--dummy-id mock-id) - (should (eq 21 (ert--dummy-id 42)))) - (should (eq 42 (ert--dummy-id 42))) - - (ert-with-function-mocked ert--dummy-id mock-id - (should (eq 21 (ert--dummy-id 42)))) - (should (eq 42 (ert--dummy-id 42))) - - (should - (catch 'exit - (ert-with-function-mocked ert--dummy-id mock-id - (should (eq 21 (ert--dummy-id 42)))) - (throw 'exit t))) - (should (eq 42 (ert--dummy-id 42))) - - (should - (string= "Foo" - (condition-case err - (progn - (ert-with-function-mocked ert--dummy-id mock-id - (should (eq 21 (ert--dummy-id 42)))) - (user-error "Foo")) - (user-error (cadr err))))) - (should (eq 42 (ert--dummy-id 42))) - - (should - (string= "`ert--dummy-id' unexpectedly called." - (condition-case err - (ert-with-function-mocked ert--dummy-id nil - (ert--dummy-id 42)) - (ert-test-failed (cadr err))))) - (should (eq 42 (ert--dummy-id 42))))) - - (provide 'ert-x-tests) ;;; ert-x-tests.el ends here diff --git a/test/lisp/gnus/message-tests.el b/test/lisp/gnus/message-tests.el index ae34f24..13c15e3 100644 --- a/test/lisp/gnus/message-tests.el +++ b/test/lisp/gnus/message-tests.el @@ -57,7 +57,7 @@ (ert-deftest message-strip-subject-trailing-was () - (ert-with-function-mocked message-talkative-question nil + (cl-letf (((symbol-function 'message-talkative-question) nil)) (with-temp-buffer (let ((no-was "Re: Foo ") (with-was "Re: Foo \t (was: Bar ) ") diff --git a/test/lisp/vc/vc-bzr-tests.el b/test/lisp/vc/vc-bzr-tests.el index 98d176c..f27e658 100644 --- a/test/lisp/vc/vc-bzr-tests.el +++ b/test/lisp/vc/vc-bzr-tests.el @@ -25,7 +25,6 @@ ;;; Code: (require 'ert) -(require 'ert-x) (require 'vc-bzr) (require 'vc-dir) @@ -102,7 +101,7 @@ (while (vc-dir-busy) (sit-for 0.1)) (vc-dir-mark-all-files t) - (ert-with-function-mocked y-or-n-p (lambda (_) t) + (cl-letf (((symbol-function 'y-or-n-p) (lambda (_) t))) (vc-next-action nil)) (should (get-buffer "*vc-log*"))) (delete-directory homedir t)))) commit 027e6fbfe472bad1fd0464e070bc782c7e3e776a Author: Glenn Morris Date: Wed Jun 8 12:47:08 2016 -0400 * test/lisp/emacs-lisp/package-tests.el (package-test-update-archives-async): Try re-enabling on hydra. diff --git a/test/lisp/emacs-lisp/package-tests.el b/test/lisp/emacs-lisp/package-tests.el index 0a446fd..3d2801e 100644 --- a/test/lisp/emacs-lisp/package-tests.el +++ b/test/lisp/emacs-lisp/package-tests.el @@ -370,8 +370,6 @@ Must called from within a `tar-mode' buffer." (ert-deftest package-test-update-archives-async () "Test updating package archives asynchronously." (skip-unless (executable-find "python2")) - ;; For some reason this test doesn't work reliably on hydra.nixos.org. - (skip-unless (not (getenv "NIX_STORE"))) (let* ((package-menu-async t) (default-directory package-test-data-dir) (process (start-process