neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 7035125b2b26aa68fcfb7cda39377ac79926a0f9
parent 978962f9a00ce75216d2c36b79397ef3d2b54096
Author: dundargoc <gocdundar@gmail.com>
Date:   Mon,  8 Apr 2024 11:03:20 +0200

test: improve test conventions

Work on https://github.com/neovim/neovim/issues/27004.

Diffstat:
Mcmake/RunTests.cmake | 4++--
Mruntime/doc/dev_tools.txt | 2+-
Mscripts/legacy2luatest.pl | 6+++---
Mtest/README.md | 10+++++-----
Mtest/benchmark/autocmd_spec.lua | 6+++---
Mtest/benchmark/bench_regexp_spec.lua | 6+++---
Mtest/benchmark/preload.lua | 2+-
Mtest/benchmark/screenpos_spec.lua | 16++++++++--------
Mtest/benchmark/treesitter_spec.lua | 8++++----
Mtest/busted/outputHandlers/TAP.lua | 4++--
Mtest/busted/outputHandlers/nvim.lua | 4++--
Mtest/functional/api/autocmd_spec.lua | 22+++++++++++-----------
Mtest/functional/api/buffer_spec.lua | 32++++++++++++++++----------------
Mtest/functional/api/buffer_updates_spec.lua | 30+++++++++++++++---------------
Mtest/functional/api/command_spec.lua | 24++++++++++++------------
Mtest/functional/api/extmark_spec.lua | 26+++++++++++++-------------
Mtest/functional/api/highlight_spec.lua | 20++++++++++----------
Mtest/functional/api/keymap_spec.lua | 40++++++++++++++++++++--------------------
Mtest/functional/api/menu_spec.lua | 8++++----
Mtest/functional/api/proc_spec.lua | 18+++++++++---------
Mtest/functional/api/server_notifications_spec.lua | 17++++++++---------
Mtest/functional/api/server_requests_spec.lua | 28++++++++++++++--------------
Mtest/functional/api/tabpage_spec.lua | 18+++++++++---------
Mtest/functional/api/ui_spec.lua | 20++++++++++----------
Mtest/functional/api/version_spec.lua | 6+++---
Mtest/functional/api/vim_spec.lua | 121+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mtest/functional/api/window_spec.lua | 44++++++++++++++++++++++----------------------
Mtest/functional/autocmd/autocmd_oldtest_spec.lua | 20++++++++++----------
Mtest/functional/autocmd/autocmd_spec.lua | 38+++++++++++++++++++-------------------
Mtest/functional/autocmd/bufenter_spec.lua | 16++++++++--------
Mtest/functional/autocmd/bufmodifiedset_spec.lua | 12++++++------
Mtest/functional/autocmd/cmdline_spec.lua | 18+++++++++---------
Mtest/functional/autocmd/cursorhold_spec.lua | 14+++++++-------
Mtest/functional/autocmd/cursormoved_spec.lua | 14+++++++-------
Mtest/functional/autocmd/dirchanged_spec.lua | 18+++++++++---------
Mtest/functional/autocmd/filetype_spec.lua | 10+++++-----
Mtest/functional/autocmd/focus_spec.lua | 18+++++++++---------
Mtest/functional/autocmd/modechanged_spec.lua | 8++++----
Mtest/functional/autocmd/recording_spec.lua | 10+++++-----
Mtest/functional/autocmd/safestate_spec.lua | 12++++++------
Mtest/functional/autocmd/searchwrapped_spec.lua | 16++++++++--------
Mtest/functional/autocmd/show_spec.lua | 18+++++++++---------
Mtest/functional/autocmd/signal_spec.lua | 18+++++++++---------
Mtest/functional/autocmd/tabclose_spec.lua | 8++++----
Mtest/functional/autocmd/tabnew_spec.lua | 10+++++-----
Mtest/functional/autocmd/tabnewentered_spec.lua | 20++++++++++----------
Mtest/functional/autocmd/termxx_spec.lua | 32++++++++++++++++----------------
Mtest/functional/autocmd/textchanged_spec.lua | 20++++++++++----------
Mtest/functional/autocmd/textyankpost_spec.lua | 8++++----
Mtest/functional/autocmd/win_scrolled_resized_spec.lua | 18+++++++++---------
Mtest/functional/core/channels_spec.lua | 27+++++++++++++--------------
Mtest/functional/core/exit_spec.lua | 34+++++++++++++++++-----------------
Mtest/functional/core/fileio_spec.lua | 64++++++++++++++++++++++++++++++++--------------------------------
Mtest/functional/core/job_spec.lua | 80++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mtest/functional/core/log_spec.lua | 16++++++++--------
Mtest/functional/core/main_spec.lua | 22+++++++++++-----------
Mtest/functional/core/path_spec.lua | 24++++++++++++------------
Mtest/functional/core/remote_spec.lua | 34+++++++++++++++++-----------------
Mtest/functional/core/spellfile_spec.lua | 18+++++++++---------
Mtest/functional/core/startup_spec.lua | 64++++++++++++++++++++++++++++++++--------------------------------
Mtest/functional/editor/K_spec.lua | 15+++++++--------
Mtest/functional/editor/completion_spec.lua | 18+++++++++---------
Mtest/functional/editor/count_spec.lua | 12++++++------
Mtest/functional/editor/ctrl_c_spec.lua | 10+++++-----
Mtest/functional/editor/fold_spec.lua | 28++++++++++++++--------------
Mtest/functional/editor/jump_spec.lua | 20++++++++++----------
Mtest/functional/editor/lang_spec.lua | 10+++++-----
Mtest/functional/editor/langmap_spec.lua | 21+++++++++------------
Mtest/functional/editor/macro_spec.lua | 22+++++++++++-----------
Mtest/functional/editor/mark_spec.lua | 44++++++++++++++++++++++----------------------
Mtest/functional/editor/meta_key_spec.lua | 16++++++++--------
Mtest/functional/editor/mode_cmdline_spec.lua | 11+++++------
Mtest/functional/editor/mode_insert_spec.lua | 20++++++++++----------
Mtest/functional/editor/mode_normal_spec.lua | 12++++++------
Mtest/functional/editor/put_spec.lua | 26+++++++++++++-------------
Mtest/functional/editor/search_spec.lua | 10+++++-----
Mtest/functional/editor/tabpage_spec.lua | 24++++++++++++------------
Mtest/functional/editor/undo_spec.lua | 28++++++++++++++--------------
Mtest/functional/ex_cmds/append_spec.lua | 18+++++++++---------
Mtest/functional/ex_cmds/arg_spec.lua | 18+++++++++---------
Mtest/functional/ex_cmds/cd_spec.lua | 26+++++++++++++-------------
Mtest/functional/ex_cmds/cmd_map_spec.lua | 22+++++++++++-----------
Mtest/functional/ex_cmds/debug_spec.lua | 6+++---
Mtest/functional/ex_cmds/dict_notifications_spec.lua | 20++++++++++----------
Mtest/functional/ex_cmds/digraphs_spec.lua | 8++++----
Mtest/functional/ex_cmds/drop_spec.lua | 8++++----
Mtest/functional/ex_cmds/echo_spec.lua | 26+++++++++++++-------------
Mtest/functional/ex_cmds/edit_spec.lua | 12++++++------
Mtest/functional/ex_cmds/encoding_spec.lua | 6+++---
Mtest/functional/ex_cmds/excmd_spec.lua | 14+++++++-------
Mtest/functional/ex_cmds/file_spec.lua | 14+++++++-------
Mtest/functional/ex_cmds/grep_spec.lua | 5++---
Mtest/functional/ex_cmds/help_spec.lua | 20++++++++++----------
Mtest/functional/ex_cmds/highlight_spec.lua | 14+++++++-------
Mtest/functional/ex_cmds/ls_spec.lua | 18+++++++++---------
Mtest/functional/ex_cmds/make_spec.lua | 16++++++++--------
Mtest/functional/ex_cmds/map_spec.lua | 22+++++++++++-----------
Mtest/functional/ex_cmds/menu_spec.lua | 10+++++-----
Mtest/functional/ex_cmds/mksession_spec.lua | 26+++++++++++++-------------
Mtest/functional/ex_cmds/mkview_spec.lua | 16++++++++--------
Mtest/functional/ex_cmds/normal_spec.lua | 16++++++++--------
Mtest/functional/ex_cmds/oldfiles_spec.lua | 28++++++++++++++--------------
Mtest/functional/ex_cmds/print_commands_spec.lua | 4++--
Mtest/functional/ex_cmds/profile_spec.lua | 20++++++++++----------
Mtest/functional/ex_cmds/quickfix_commands_spec.lua | 20++++++++++----------
Mtest/functional/ex_cmds/quit_spec.lua | 4++--
Mtest/functional/ex_cmds/script_spec.lua | 22+++++++++++-----------
Mtest/functional/ex_cmds/sign_spec.lua | 8++++----
Mtest/functional/ex_cmds/source_spec.lua | 40++++++++++++++++++++--------------------
Mtest/functional/ex_cmds/swapfile_preserve_recover_spec.lua | 50+++++++++++++++++++++++++-------------------------
Mtest/functional/ex_cmds/syntax_spec.lua | 8++++----
Mtest/functional/ex_cmds/trust_spec.lua | 44++++++++++++++++++++++----------------------
Mtest/functional/ex_cmds/undojoin_spec.lua | 16++++++++--------
Mtest/functional/ex_cmds/verbose_spec.lua | 16++++++++--------
Mtest/functional/ex_cmds/wincmd_spec.lua | 10+++++-----
Mtest/functional/ex_cmds/write_spec.lua | 20++++++++++----------
Mtest/functional/ex_cmds/wundo_spec.lua | 9++-------
Mtest/functional/ex_cmds/wviminfo_spec.lua | 10+++++-----
Mtest/functional/example_spec.lua | 10+++++-----
Dtest/functional/helpers.lua | 1042-------------------------------------------------------------------------------
Mtest/functional/legacy/002_filename_recognition_spec.lua | 6+++---
Mtest/functional/legacy/004_bufenter_with_modelines_spec.lua | 6+++---
Mtest/functional/legacy/005_bufleave_delete_buffer_spec.lua | 8++++----
Mtest/functional/legacy/007_ball_buffer_list_spec.lua | 6+++---
Mtest/functional/legacy/008_autocommands_spec.lua | 13++++++-------
Mtest/functional/legacy/011_autocommands_spec.lua | 17+++++------------
Mtest/functional/legacy/012_directory_spec.lua | 28++++++++++++++--------------
Mtest/functional/legacy/015_alignment_spec.lua | 6+++---
Mtest/functional/legacy/018_unset_smart_indenting_spec.lua | 12++++++------
Mtest/functional/legacy/019_smarttab_expandtab_spec.lua | 6+++---
Mtest/functional/legacy/020_blockwise_visual_spec.lua | 6+++---
Mtest/functional/legacy/021_control_wi_spec.lua | 6+++---
Mtest/functional/legacy/023_edit_arguments_spec.lua | 8++++----
Mtest/functional/legacy/025_jump_tag_hidden_spec.lua | 12++++++------
Mtest/functional/legacy/026_execute_while_if_spec.lua | 10+++++-----
Mtest/functional/legacy/028_source_ctrl_v_spec.lua | 6+++---
Mtest/functional/legacy/029_join_spec.lua | 12++++++------
Mtest/functional/legacy/030_fileformats_spec.lua | 12++++++------
Mtest/functional/legacy/031_close_commands_spec.lua | 18+++++++++---------
Mtest/functional/legacy/033_lisp_indent_spec.lua | 8++++----
Mtest/functional/legacy/034_user_function_spec.lua | 6+++---
Mtest/functional/legacy/035_increment_and_decrement_spec.lua | 6+++---
Mtest/functional/legacy/036_regexp_character_classes_spec.lua | 14+++++++-------
Mtest/functional/legacy/038_virtual_replace_spec.lua | 6+++---
Mtest/functional/legacy/039_visual_block_mode_commands_spec.lua | 10+++++-----
Mtest/functional/legacy/043_magic_settings_spec.lua | 6+++---
Mtest/functional/legacy/044_099_regexp_multibyte_magic_spec.lua | 6+++---
Mtest/functional/legacy/046_multi_line_regexps_spec.lua | 6+++---
Mtest/functional/legacy/054_buffer_local_autocommands_spec.lua | 8++++----
Mtest/functional/legacy/055_list_and_dict_types_spec.lua | 6+++---
Mtest/functional/legacy/056_script_local_function_spec.lua | 6+++---
Mtest/functional/legacy/057_sort_spec.lua | 6+++---
Mtest/functional/legacy/060_exists_and_has_functions_spec.lua | 8++++----
Mtest/functional/legacy/061_undo_tree_spec.lua | 24++++++++++++------------
Mtest/functional/legacy/063_match_and_matchadd_spec.lua | 6+++---
Mtest/functional/legacy/065_float_and_logic_operators_spec.lua | 6+++---
Mtest/functional/legacy/066_visual_block_tab_spec.lua | 6+++---
Mtest/functional/legacy/067_augroup_exists_spec.lua | 6+++---
Mtest/functional/legacy/068_text_formatting_spec.lua | 12++++++------
Mtest/functional/legacy/069_multibyte_formatting_spec.lua | 10++--------
Mtest/functional/legacy/072_undo_file_spec.lua | 6+++---
Mtest/functional/legacy/074_global_var_in_viminfo_spec.lua | 4++--
Mtest/functional/legacy/078_swapfile_recover_spec.lua | 4++--
Mtest/functional/legacy/081_coptions_movement_spec.lua | 6+++---
Mtest/functional/legacy/082_string_comparison_spec.lua | 6+++---
Mtest/functional/legacy/083_tag_search_with_file_encoding_spec.lua | 8++++----
Mtest/functional/legacy/090_sha256_spec.lua | 6+++---
Mtest/functional/legacy/091_context_variables_spec.lua | 6+++---
Mtest/functional/legacy/092_mksession_cursor_cols_utf8_spec.lua | 6+++---
Mtest/functional/legacy/093_mksession_cursor_cols_latin1_spec.lua | 6+++---
Mtest/functional/legacy/094_visual_mode_operators_spec.lua | 6+++---
Mtest/functional/legacy/095_regexp_multibyte_spec.lua | 6+++---
Mtest/functional/legacy/096_location_list_spec.lua | 6+++---
Mtest/functional/legacy/097_glob_path_spec.lua | 12++++++------
Mtest/functional/legacy/101_hlsearch_spec.lua | 6+++---
Mtest/functional/legacy/102_fnameescape_spec.lua | 6+++---
Mtest/functional/legacy/103_visual_mode_reset_spec.lua | 6+++---
Mtest/functional/legacy/106_errorformat_spec.lua | 6+++---
Mtest/functional/legacy/107_adjust_window_and_contents_spec.lua | 10+++++-----
Mtest/functional/legacy/108_backtrace_debug_commands_spec.lua | 8++++----
Mtest/functional/legacy/arglist_spec.lua | 10+++++-----
Mtest/functional/legacy/assert_spec.lua | 12++++++------
Mtest/functional/legacy/autochdir_spec.lua | 12++++++------
Mtest/functional/legacy/autocmd_option_spec.lua | 16++++++++--------
Mtest/functional/legacy/autocmd_spec.lua | 14+++++++-------
Mtest/functional/legacy/autoformat_join_spec.lua | 8++++----
Mtest/functional/legacy/breakindent_spec.lua | 10+++++-----
Mtest/functional/legacy/changelist_spec.lua | 6+++---
Mtest/functional/legacy/charsearch_spec.lua | 6+++---
Mtest/functional/legacy/close_count_spec.lua | 14+++++++-------
Mtest/functional/legacy/cmdline_spec.lua | 14+++++++-------
Mtest/functional/legacy/command_count_spec.lua | 6+++---
Mtest/functional/legacy/comparators_spec.lua | 6+++---
Mtest/functional/legacy/conceal_spec.lua | 14+++++++-------
Mtest/functional/legacy/cpoptions_spec.lua | 8++++----
Mtest/functional/legacy/crash_spec.lua | 10+++++-----
Mtest/functional/legacy/debugger_spec.lua | 10+++++-----
Mtest/functional/legacy/delete_spec.lua | 10+++++-----
Mtest/functional/legacy/digraph_spec.lua | 6+++---
Mtest/functional/legacy/display_spec.lua | 10+++++-----
Mtest/functional/legacy/edit_spec.lua | 10+++++-----
Mtest/functional/legacy/erasebackword_spec.lua | 4++--
Mtest/functional/legacy/eval_spec.lua | 16++++++++--------
Mtest/functional/legacy/ex_mode_spec.lua | 16++++++++--------
Mtest/functional/legacy/excmd_spec.lua | 28++++++++++++++--------------
Mtest/functional/legacy/fixeol_spec.lua | 6+++---
Mtest/functional/legacy/fnamemodify_spec.lua | 6+++---
Mtest/functional/legacy/fold_spec.lua | 15+++++++--------
Mtest/functional/legacy/function_sort_spec.lua | 16++++++++--------
Mtest/functional/legacy/getcwd_spec.lua | 8++++----
Mtest/functional/legacy/gf_spec.lua | 10+++++-----
Mtest/functional/legacy/glob2regpat_spec.lua | 6+++---
Mtest/functional/legacy/global_spec.lua | 10+++++-----
Mtest/functional/legacy/highlight_spec.lua | 16++++++++--------
Mtest/functional/legacy/increment_spec.lua | 8++++----
Mtest/functional/legacy/insertcount_spec.lua | 6+++---
Mtest/functional/legacy/join_spec.lua | 6+++---
Mtest/functional/legacy/lispwords_spec.lua | 12++++++------
Mtest/functional/legacy/listchars_spec.lua | 6+++---
Mtest/functional/legacy/listlbr_spec.lua | 6+++---
Mtest/functional/legacy/listlbr_utf8_spec.lua | 10+++++-----
Mtest/functional/legacy/mapping_spec.lua | 8++++----
Mtest/functional/legacy/marks_spec.lua | 6+++---
Mtest/functional/legacy/match_spec.lua | 8++++----
Mtest/functional/legacy/matchparen_spec.lua | 8++++----
Mtest/functional/legacy/memory_usage_spec.lua | 28++++++++++++++--------------
Mtest/functional/legacy/messages_spec.lua | 16++++++++--------
Mtest/functional/legacy/mksession_spec.lua | 10+++++-----
Mtest/functional/legacy/move_spec.lua | 8++++----
Mtest/functional/legacy/nested_function_spec.lua | 6+++---
Mtest/functional/legacy/normal_spec.lua | 14+++++++-------
Mtest/functional/legacy/number_spec.lua | 10+++++-----
Mtest/functional/legacy/options_spec.lua | 10+++++-----
Mtest/functional/legacy/prompt_buffer_spec.lua | 20++++++++++----------
Mtest/functional/legacy/put_spec.lua | 12++++++------
Mtest/functional/legacy/qf_title_spec.lua | 6+++---
Mtest/functional/legacy/scroll_opt_spec.lua | 10+++++-----
Mtest/functional/legacy/search_mbyte_spec.lua | 12++++++------
Mtest/functional/legacy/search_spec.lua | 18+++++++++---------
Mtest/functional/legacy/search_stat_spec.lua | 4++--
Mtest/functional/legacy/signs_spec.lua | 4++--
Mtest/functional/legacy/source_spec.lua | 8++++----
Mtest/functional/legacy/statusline_spec.lua | 8++++----
Mtest/functional/legacy/substitute_spec.lua | 10+++++-----
Mtest/functional/legacy/syn_attr_spec.lua | 10+++++-----
Mtest/functional/legacy/tabline_spec.lua | 8++++----
Mtest/functional/legacy/tagcase_spec.lua | 18+++++++++---------
Mtest/functional/legacy/textobjects_spec.lua | 12++++++------
Mtest/functional/legacy/undolevels_spec.lua | 6+++---
Mtest/functional/legacy/utf8_spec.lua | 12++++++------
Mtest/functional/legacy/vimscript_spec.lua | 10+++++-----
Mtest/functional/legacy/visual_spec.lua | 8++++----
Mtest/functional/legacy/window_cmd_spec.lua | 12++++++------
Mtest/functional/legacy/wordcount_spec.lua | 10+++++-----
Mtest/functional/legacy/writefile_spec.lua | 4++--
Mtest/functional/lua/api_spec.lua | 18+++++++++---------
Mtest/functional/lua/base64_spec.lua | 12++++++------
Mtest/functional/lua/buffer_updates_spec.lua | 30+++++++++++++++---------------
Mtest/functional/lua/command_line_completion_spec.lua | 8++++----
Mtest/functional/lua/commands_spec.lua | 34+++++++++++++++++-----------------
Mtest/functional/lua/comment_spec.lua | 16++++++++--------
Mtest/functional/lua/diagnostic_spec.lua | 36++++++++++++++----------------------
Mtest/functional/lua/ffi_spec.lua | 8++++----
Mtest/functional/lua/filetype_spec.lua | 20++++++++++----------
Mtest/functional/lua/fs_spec.lua | 26+++++++++++++-------------
Mtest/functional/lua/glob_spec.lua | 10+++++-----
Mtest/functional/lua/highlight_spec.lua | 18+++++++++---------
Mtest/functional/lua/inspector_spec.lua | 10+++++-----
Mtest/functional/lua/iter_spec.lua | 182++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mtest/functional/lua/json_spec.lua | 10+++++-----
Mtest/functional/lua/loader_spec.lua | 28++++++++++++++--------------
Mtest/functional/lua/loop_spec.lua | 20++++++++++----------
Mtest/functional/lua/luaeval_spec.lua | 28++++++++++++++--------------
Mtest/functional/lua/mpack_spec.lua | 8++++----
Mtest/functional/lua/overrides_spec.lua | 24++++++++++++------------
Mtest/functional/lua/runtime_spec.lua | 20++++++++++----------
Mtest/functional/lua/secure_spec.lua | 40++++++++++++++++++++--------------------
Mtest/functional/lua/snippet_spec.lua | 26+++++++++++++-------------
Mtest/functional/lua/spell_spec.lua | 10+++++-----
Mtest/functional/lua/system_spec.lua | 8++++----
Mtest/functional/lua/text_spec.lua | 6+++---
Mtest/functional/lua/thread_spec.lua | 16++++++++--------
Mtest/functional/lua/ui_event_spec.lua | 20++++++++++----------
Mtest/functional/lua/ui_spec.lua | 20++++++++++----------
Mtest/functional/lua/uri_spec.lua | 16++++++++--------
Mtest/functional/lua/version_spec.lua | 16++++++++--------
Mtest/functional/lua/vim_spec.lua | 70+++++++++++++++++++++++++++++++++++-----------------------------------
Mtest/functional/lua/watch_spec.lua | 23++++++++++-------------
Mtest/functional/lua/xdiff_spec.lua | 10+++++-----
Mtest/functional/options/autochdir_spec.lua | 18+++++++++---------
Mtest/functional/options/chars_spec.lua | 16++++++++--------
Mtest/functional/options/cursorbind_spec.lua | 10+++++-----
Mtest/functional/options/defaults_spec.lua | 44++++++++++++++++++++++----------------------
Mtest/functional/options/keymap_spec.lua | 10+++++-----
Mtest/functional/options/modified_spec.lua | 8++++----
Mtest/functional/options/mousescroll_spec.lua | 20++++++++++----------
Mtest/functional/options/num_options_spec.lua | 5++---
Mtest/functional/options/shortmess_spec.lua | 12++++++------
Mtest/functional/options/tabstop_spec.lua | 8++++----
Mtest/functional/options/winfixbuf_spec.lua | 6+++---
Mtest/functional/plugin/ccomplete_spec.lua | 14+++++++-------
Mtest/functional/plugin/cfilter_spec.lua | 10+++++-----
Mtest/functional/plugin/editorconfig_spec.lua | 30+++++++++++++++---------------
Mtest/functional/plugin/health_spec.lua | 32++++++++++++++++----------------
Mtest/functional/plugin/lsp/codelens_spec.lua | 10+++++-----
Mtest/functional/plugin/lsp/completion_spec.lua | 8++++----
Mtest/functional/plugin/lsp/diagnostic_spec.lua | 14+++++++-------
Mtest/functional/plugin/lsp/handler_spec.lua | 10+++++-----
Dtest/functional/plugin/lsp/helpers.lua | 219-------------------------------------------------------------------------------
Mtest/functional/plugin/lsp/incremental_sync_spec.lua | 12++++++------
Mtest/functional/plugin/lsp/inlay_hint_spec.lua | 18+++++++++---------
Mtest/functional/plugin/lsp/semantic_tokens_spec.lua | 28++++++++++++++--------------
Mtest/functional/plugin/lsp/snippet_spec.lua | 10+++++-----
Atest/functional/plugin/lsp/testutil.lua | 219+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtest/functional/plugin/lsp/utils_spec.lua | 12++++++------
Mtest/functional/plugin/lsp_spec.lua | 72++++++++++++++++++++++++++++++++++++------------------------------------
Mtest/functional/plugin/man_spec.lua | 24++++++++++++------------
Mtest/functional/plugin/matchparen_spec.lua | 12++++++------
Mtest/functional/plugin/msgpack_spec.lua | 16++++++++--------
Mtest/functional/plugin/shada_spec.lua | 16++++++++--------
Mtest/functional/plugin/tohtml_spec.lua | 16++++++++--------
Mtest/functional/plugin/tutor_spec.lua | 10+++++-----
Mtest/functional/plugin/vim_syntax_spec.lua | 10+++++-----
Mtest/functional/preload.lua | 4++--
Mtest/functional/provider/clipboard_spec.lua | 11+++++------
Mtest/functional/provider/define_spec.lua | 14+++++++-------
Mtest/functional/provider/nodejs_spec.lua | 14+++++++-------
Mtest/functional/provider/perl_spec.lua | 22+++++++++++-----------
Mtest/functional/provider/provider_spec.lua | 10+++++-----
Mtest/functional/provider/python3_spec.lua | 26+++++++++++++-------------
Mtest/functional/provider/ruby_spec.lua | 36++++++++++++++++++------------------
Mtest/functional/script/luacats_grammar_spec.lua | 4++--
Mtest/functional/script/luacats_parser_spec.lua | 4++--
Mtest/functional/script/text_utils_spec.lua | 8++++----
Mtest/functional/shada/buffers_spec.lua | 10+++++-----
Mtest/functional/shada/compatibility_spec.lua | 15+++++++--------
Mtest/functional/shada/errors_spec.lua | 9++++-----
Dtest/functional/shada/helpers.lua | 87-------------------------------------------------------------------------------
Mtest/functional/shada/history_spec.lua | 15+++++++--------
Mtest/functional/shada/marks_spec.lua | 18+++++++++---------
Mtest/functional/shada/merging_spec.lua | 51+++++++++++++++++++++++++--------------------------
Mtest/functional/shada/registers_spec.lua | 10+++++-----
Mtest/functional/shada/shada_spec.lua | 19+++++++++----------
Atest/functional/shada/testutil.lua | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtest/functional/shada/variables_spec.lua | 11+++++------
Mtest/functional/terminal/altscreen_spec.lua | 18+++++++++---------
Mtest/functional/terminal/api_spec.lua | 22+++++++++++-----------
Mtest/functional/terminal/buffer_spec.lua | 48++++++++++++++++++++++++------------------------
Mtest/functional/terminal/channel_spec.lua | 26+++++++++++++-------------
Mtest/functional/terminal/cursor_spec.lua | 32++++++++++++++++----------------
Mtest/functional/terminal/edit_spec.lua | 16++++++++--------
Mtest/functional/terminal/ex_terminal_spec.lua | 28++++++++++++++--------------
Dtest/functional/terminal/helpers.lua | 191-------------------------------------------------------------------------------
Mtest/functional/terminal/highlight_spec.lua | 74+++++++++++++++++++++++++++++++++++++-------------------------------------
Mtest/functional/terminal/mouse_spec.lua | 24++++++++++++------------
Mtest/functional/terminal/scrollback_spec.lua | 42+++++++++++++++++++++---------------------
Atest/functional/terminal/testutil.lua | 191+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtest/functional/terminal/tui_spec.lua | 130++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mtest/functional/terminal/window_spec.lua | 26+++++++++++++-------------
Mtest/functional/terminal/window_split_tab_spec.lua | 26+++++++++++++-------------
Atest/functional/testutil.lua | 1042+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtest/functional/treesitter/fold_spec.lua | 16++++++++--------
Mtest/functional/treesitter/highlight_spec.lua | 20++++++++++----------
Mtest/functional/treesitter/inspect_tree_spec.lua | 16++++++++--------
Mtest/functional/treesitter/language_spec.lua | 18+++++++++---------
Mtest/functional/treesitter/node_spec.lua | 12++++++------
Mtest/functional/treesitter/parser_spec.lua | 26+++++++++++++-------------
Mtest/functional/treesitter/query_spec.lua | 22+++++++++++-----------
Mtest/functional/treesitter/utils_spec.lua | 10+++++-----
Mtest/functional/ui/bufhl_spec.lua | 12++++++------
Mtest/functional/ui/cmdline_highlight_spec.lua | 20++++++++++----------
Mtest/functional/ui/cmdline_spec.lua | 22+++++++++++-----------
Mtest/functional/ui/cursor_spec.lua | 18+++++++++---------
Mtest/functional/ui/decorations_spec.lua | 38+++++++++++++++++++-------------------
Mtest/functional/ui/diff_spec.lua | 20++++++++++----------
Mtest/functional/ui/embed_spec.lua | 60++++++++++++++++++++++++++++++------------------------------
Mtest/functional/ui/float_spec.lua | 44++++++++++++++++++++++----------------------
Mtest/functional/ui/fold_spec.lua | 18+++++++++---------
Mtest/functional/ui/highlight_spec.lua | 18+++++++++---------
Mtest/functional/ui/hlstate_spec.lua | 38+++++++++++++++++++-------------------
Mtest/functional/ui/inccommand_spec.lua | 40++++++++++++++++++++--------------------
Mtest/functional/ui/inccommand_user_spec.lua | 18+++++++++---------
Mtest/functional/ui/input_spec.lua | 22+++++++++++-----------
Mtest/functional/ui/linematch_spec.lua | 24++++++++++++------------
Mtest/functional/ui/messages_spec.lua | 48++++++++++++++++++++++++------------------------
Mtest/functional/ui/mode_spec.lua | 8++++----
Mtest/functional/ui/mouse_spec.lua | 20++++++++++----------
Mtest/functional/ui/multibyte_spec.lua | 18+++++++++---------
Mtest/functional/ui/multigrid_spec.lua | 16++++++++--------
Mtest/functional/ui/options_spec.lua | 12++++++------
Mtest/functional/ui/output_spec.lua | 43++++++++++++++++++++++---------------------
Mtest/functional/ui/popupmenu_spec.lua | 26+++++++++++++-------------
Mtest/functional/ui/quickfix_spec.lua | 6+++---
Mtest/functional/ui/screen.lua | 16++++++++--------
Mtest/functional/ui/screen_basic_spec.lua | 16++++++++--------
Mtest/functional/ui/searchhl_spec.lua | 16++++++++--------
Mtest/functional/ui/sign_spec.lua | 6+++---
Mtest/functional/ui/spell_spec.lua | 14+++++++-------
Mtest/functional/ui/statuscolumn_spec.lua | 22+++++++++++-----------
Mtest/functional/ui/statusline_spec.lua | 24++++++++++++------------
Mtest/functional/ui/syntax_conceal_spec.lua | 12++++++------
Mtest/functional/ui/tabline_spec.lua | 10+++++-----
Mtest/functional/ui/title_spec.lua | 20++++++++++----------
Mtest/functional/ui/wildmode_spec.lua | 18+++++++++---------
Mtest/functional/ui/winbar_spec.lua | 20++++++++++----------
Mtest/functional/vimscript/api_functions_spec.lua | 18+++++++++---------
Mtest/functional/vimscript/buf_functions_spec.lua | 22+++++++++++-----------
Mtest/functional/vimscript/changedtick_spec.lua | 22+++++++++++-----------
Mtest/functional/vimscript/container_functions_spec.lua | 10+++++-----
Mtest/functional/vimscript/ctx_functions_spec.lua | 28++++++++++++++--------------
Mtest/functional/vimscript/environ_spec.lua | 20++++++++++----------
Mtest/functional/vimscript/errorlist_spec.lua | 20++++++++++----------
Mtest/functional/vimscript/eval_spec.lua | 50+++++++++++++++++++++++++-------------------------
Mtest/functional/vimscript/executable_spec.lua | 11+++++------
Mtest/functional/vimscript/execute_spec.lua | 22+++++++++++-----------
Mtest/functional/vimscript/exepath_spec.lua | 16++++++++--------
Mtest/functional/vimscript/fnamemodify_spec.lua | 20++++++++++----------
Mtest/functional/vimscript/functions_spec.lua | 10+++++-----
Mtest/functional/vimscript/getline_spec.lua | 10+++++-----
Mtest/functional/vimscript/glob_spec.lua | 6+++---
Mtest/functional/vimscript/has_spec.lua | 14+++++++-------
Mtest/functional/vimscript/hostname_spec.lua | 12++++++------
Mtest/functional/vimscript/input_spec.lua | 18+++++++++---------
Mtest/functional/vimscript/json_functions_spec.lua | 20++++++++++----------
Mtest/functional/vimscript/lang_spec.lua | 6+++---
Mtest/functional/vimscript/let_spec.lua | 22+++++++++++-----------
Mtest/functional/vimscript/map_functions_spec.lua | 30+++++++++++++++---------------
Mtest/functional/vimscript/match_functions_spec.lua | 12++++++------
Mtest/functional/vimscript/minmax_functions_spec.lua | 14+++++++-------
Mtest/functional/vimscript/modeline_spec.lua | 8++++----
Mtest/functional/vimscript/msgpack_functions_spec.lua | 20++++++++++----------
Mtest/functional/vimscript/null_spec.lua | 14+++++++-------
Mtest/functional/vimscript/operators_spec.lua | 8++++----
Mtest/functional/vimscript/printf_spec.lua | 14+++++++-------
Mtest/functional/vimscript/reltime_spec.lua | 8++++----
Mtest/functional/vimscript/screenchar_spec.lua | 6+++---
Mtest/functional/vimscript/screenpos_spec.lua | 8++++----
Mtest/functional/vimscript/server_spec.lua | 26+++++++++++++-------------
Mtest/functional/vimscript/setpos_spec.lua | 18+++++++++---------
Mtest/functional/vimscript/sort_spec.lua | 18+++++++++---------
Mtest/functional/vimscript/special_vars_spec.lua | 16++++++++--------
Mtest/functional/vimscript/state_spec.lua | 16++++++++--------
Mtest/functional/vimscript/string_spec.lua | 22+++++++++++-----------
Mtest/functional/vimscript/system_spec.lua | 54++++++++++++++++++++++++------------------------------
Mtest/functional/vimscript/timer_spec.lua | 16++++++++--------
Mtest/functional/vimscript/uniq_spec.lua | 12++++++------
Mtest/functional/vimscript/vvar_event_spec.lua | 6+++---
Mtest/functional/vimscript/wait_spec.lua | 26+++++++++++++-------------
Mtest/functional/vimscript/writefile_spec.lua | 22+++++++++++-----------
Dtest/helpers.lua | 779-------------------------------------------------------------------------------
Mtest/old/testdir/load.vim | 2+-
Atest/testutil.lua | 779+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dtest/unit/api/helpers.lua | 177-------------------------------------------------------------------------------
Mtest/unit/api/private_helpers_spec.lua | 42+++++++++++++++++++++---------------------
Atest/unit/api/testutil.lua | 174+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtest/unit/buffer_spec.lua | 12++++++------
Mtest/unit/charset/vim_str2nr_spec.lua | 10+++++-----
Mtest/unit/eval/decode_spec.lua | 12++++++------
Mtest/unit/eval/encode_spec.lua | 22+++++++++++-----------
Dtest/unit/eval/helpers.lua | 606-------------------------------------------------------------------------------
Atest/unit/eval/testutil.lua | 606+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtest/unit/eval/tricks_spec.lua | 12++++++------
Mtest/unit/eval/tv_clear_spec.lua | 26+++++++++++++-------------
Mtest/unit/eval/typval_spec.lua | 78+++++++++++++++++++++++++++++++++++++++---------------------------------------
Mtest/unit/fileio_spec.lua | 16++++++++--------
Mtest/unit/garray_spec.lua | 20++++++++++----------
Dtest/unit/helpers.lua | 911-------------------------------------------------------------------------------
Mtest/unit/indent_spec.lua | 14+++++++-------
Mtest/unit/keycodes_spec.lua | 14+++++++-------
Mtest/unit/marktree_spec.lua | 20++++++++++----------
Mtest/unit/mbyte_spec.lua | 12++++++------
Mtest/unit/memory_spec.lua | 14+++++++-------
Mtest/unit/message_spec.lua | 26+++++++++++++-------------
Mtest/unit/msgpack_spec.lua | 12++++++------
Mtest/unit/multiqueue_spec.lua | 12++++++------
Mtest/unit/optionstr_spec.lua | 10+++++-----
Mtest/unit/os/env_spec.lua | 20++++++++++----------
Mtest/unit/os/fileio_spec.lua | 16++++++++--------
Mtest/unit/os/fs_spec.lua | 32++++++++++++++++----------------
Mtest/unit/os/shell_spec.lua | 12++++++------
Mtest/unit/os/users_spec.lua | 18+++++++++---------
Mtest/unit/path_spec.lua | 30+++++++++++++++---------------
Mtest/unit/preload.lua | 2+-
Mtest/unit/preprocess.lua | 6+++---
Mtest/unit/profile_spec.lua | 38+++++++++++++++++++-------------------
Mtest/unit/rbuffer_spec.lua | 16++++++++--------
Mtest/unit/search_spec.lua | 16++++++++--------
Mtest/unit/statusline_spec.lua | 20++++++++++----------
Mtest/unit/strings_spec.lua | 14+++++++-------
Mtest/unit/tempfile_spec.lua | 20++++++++++----------
Mtest/unit/testtest_spec.lua | 6+++---
Atest/unit/testutil.lua | 911+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtest/unit/undo_spec.lua | 22+++++++++++-----------
Mtest/unit/viml/expressions/lexer_spec.lua | 34+++++++++++++++++-----------------
Mtest/unit/viml/expressions/parser_spec.lua | 44++++++++++++++++++++++----------------------
Dtest/unit/viml/helpers.lua | 151------------------------------------------------------------------------------
Atest/unit/viml/testutil.lua | 151++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
497 files changed, 8283 insertions(+), 8342 deletions(-)

diff --git a/cmake/RunTests.cmake b/cmake/RunTests.cmake @@ -46,7 +46,7 @@ if(DEFINED ENV{TEST_FILTER_OUT} AND NOT "$ENV{TEST_FILTER_OUT}" STREQUAL "") list(APPEND BUSTED_ARGS --filter-out $ENV{TEST_FILTER_OUT}) endif() -# TMPDIR: for helpers.tmpname() and Nvim tempname(). +# TMPDIR: for testutil.tmpname() and Nvim tempname(). set(ENV{TMPDIR} "${BUILD_DIR}/Xtest_tmpdir") execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory $ENV{TMPDIR}) @@ -57,7 +57,7 @@ if(NOT DEFINED ENV{TEST_TIMEOUT} OR "$ENV{TEST_TIMEOUT}" STREQUAL "") set(ENV{TEST_TIMEOUT} 1200) endif() -set(ENV{SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_NAME}) # used by test/helpers.lua. +set(ENV{SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_NAME}) # used by test/testutil.lua. if(NOT WIN32) # Tests assume POSIX "sh" and may fail if SHELL=fish. #24941 #6172 diff --git a/runtime/doc/dev_tools.txt b/runtime/doc/dev_tools.txt @@ -88,7 +88,7 @@ Then, in another terminal: gdb build/bin/nvim target remote localhost:7777 < -- See also test/functional/helpers.lua https://github.com/neovim/neovim/blob/3098b18a2b63a841351f6d5e3697cb69db3035ef/test/functional/helpers.lua#L38-L44. +- See also test/functional/testutil.lua https://github.com/neovim/neovim/blob/3098b18a2b63a841351f6d5e3697cb69db3035ef/test/functional/testutil.lua#L38-L44. USING LLDB TO STEP THROUGH UNIT TESTS ~ diff --git a/scripts/legacy2luatest.pl b/scripts/legacy2luatest.pl @@ -282,9 +282,9 @@ open my $spec_file_handle, ">", $spec_file; print $spec_file_handle <<"EOS"; @{[join "\n", @{$description_lines}]} -local helpers = require('test.functional.helpers') -local feed, insert, source = helpers.feed, helpers.insert, helpers.source -local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local t = require('test.functional.testutil') +local feed, insert, source = t.feed, t.insert, t.source +local clear, execute, expect = t.clear, t.execute, t.expect describe('$test_name', function() before_each(clear) diff --git a/test/README.md b/test/README.md @@ -44,9 +44,9 @@ Layout parser: normally used to make macros not accessible via this mechanism accessible the other way. - `/test/*/preload.lua` : modules preloaded by busted `--helper` option -- `/test/**/helpers.lua` : common utility functions for test code +- `/test/**/testutil.lua` : common utility functions for test code - `/test/*/**/*_spec.lua` : actual tests. Files that do not end with - `_spec.lua` are libraries like `/test/**/helpers.lua`, except that they have + `_spec.lua` are libraries like `/test/**/testutil.lua`, except that they have some common topic. - `/test/old/testdir` : old tests (from Vim) @@ -119,7 +119,7 @@ Debugging tests If `$VALGRIND` is also set it will pass `--vgdb=yes` to valgrind instead of starting gdbserver directly. - See [test/functional/helpers.lua](https://github.com/neovim/neovim/blob/9cadbf1d36b63f53f0de48c8c5ff6c752ff05d70/test/functional/helpers.lua#L52-L69) for details. + See [test/functional/testutil.lua](https://github.com/neovim/neovim/blob/9cadbf1d36b63f53f0de48c8c5ff6c752ff05d70/test/functional/testutil.lua#L52-L69) for details. - Hanging tests can happen due to unexpected "press-enter" prompts. The default screen width is 50 columns. Commands that try to print lines longer @@ -218,7 +218,7 @@ Guidelines - Luajit needs to know about type and constant declarations used in function prototypes. The - [helpers.lua](https://github.com/neovim/neovim/blob/master/test/unit/helpers.lua) + [testutil.lua](https://github.com/neovim/neovim/blob/master/test/unit/testutil.lua) file automatically parses `types.h`, so types used in the tested functions could be moved to it to avoid having to rewrite the declarations in the test files. @@ -297,7 +297,7 @@ Number; !must be defined to function properly): - `VALGRIND` (F) (D): makes nvim instances to be run under `valgrind`. Log files are named `valgrind-%p.log` in this case. Note that non-empty valgrind log may fail tests. Valgrind arguments may be seen in - `/test/functional/helpers.lua`. May be used in conjunction with `GDB`. + `/test/functional/testutil.lua`. May be used in conjunction with `GDB`. - `VALGRIND_LOG` (F) (S): overrides valgrind log file name used for `VALGRIND`. diff --git a/test/benchmark/autocmd_spec.lua b/test/benchmark/autocmd_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local exec_lua = helpers.exec_lua +local clear = t.clear +local exec_lua = t.exec_lua local N = 7500 diff --git a/test/benchmark/bench_regexp_spec.lua b/test/benchmark/bench_regexp_spec.lua @@ -1,8 +1,8 @@ -- Test for benchmarking the RE engine. -local helpers = require('test.functional.helpers')(after_each) -local insert, source = helpers.insert, helpers.source -local clear, command = helpers.clear, helpers.command +local t = require('test.functional.testutil')(after_each) +local insert, source = t.insert, t.source +local clear, command = t.clear, t.command -- Temporary file for gathering benchmarking results for each regexp engine. local result_file = 'benchmark.out' diff --git a/test/benchmark/preload.lua b/test/benchmark/preload.lua @@ -1,4 +1,4 @@ -- Modules loaded here will not be cleared and reloaded by Busted. -- Busted started doing this to help provide more isolation. See issue #62 -- for more information about this. -local helpers = require('test.functional.helpers') +local t = require('test.functional.testutil') diff --git a/test/benchmark/screenpos_spec.lua b/test/benchmark/screenpos_spec.lua @@ -1,5 +1,5 @@ -local helpers = require('test.functional.helpers')(after_each) -local api = helpers.api +local t = require('test.functional.testutil')(after_each) +local api = t.api local Screen = require('test.functional.ui.screen') local function rand_utf8(count, seed) @@ -78,7 +78,7 @@ local N = 10000 local function benchmark(lines, expected_value) local lnum = #lines - local results = helpers.exec_lua( + local results = t.exec_lua( [==[ local N, lnum = ... @@ -99,7 +99,7 @@ local function benchmark(lines, expected_value) ) for _, value in ipairs(results[1]) do - helpers.eq(expected_value, value) + t.eq(expected_value, value) end local stats = results[2] table.sort(stats) @@ -119,7 +119,7 @@ end local function benchmarks(benchmark_results) describe('screenpos() perf', function() - before_each(helpers.clear) + before_each(t.clear) -- no breakindent for li, lines_type in ipairs(benchmark_lines) do @@ -134,7 +134,7 @@ local function benchmarks(benchmark_results) screen:attach() api.nvim_buf_set_lines(0, 0, 1, false, lines) -- for smaller screen expect (last line always different, first line same as others) - helpers.feed('G$') + t.feed('G$') screen:expect(result.screen) benchmark(lines, result.value) end) @@ -153,9 +153,9 @@ local function benchmarks(benchmark_results) local screen = Screen.new(width, height + 1) screen:attach() api.nvim_buf_set_lines(0, 0, 1, false, lines) - helpers.command('set breakindent') + t.command('set breakindent') -- for smaller screen expect (last line always different, first line same as others) - helpers.feed('G$') + t.feed('G$') screen:expect(result.screen) benchmark(lines, result.value) end) diff --git a/test/benchmark/treesitter_spec.lua b/test/benchmark/treesitter_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local exec_lua = helpers.exec_lua +local clear = t.clear +local exec_lua = t.exec_lua describe('treesitter perf', function() setup(function() @@ -9,7 +9,7 @@ describe('treesitter perf', function() end) it('can handle large folds', function() - helpers.command 'edit ./src/nvim/eval.c' + t.command 'edit ./src/nvim/eval.c' exec_lua [[ local parser = vim.treesitter.get_parser(0, "c", {}) vim.treesitter.highlighter.new(parser) diff --git a/test/busted/outputHandlers/TAP.lua b/test/busted/outputHandlers/TAP.lua @@ -1,13 +1,13 @@ -- Extends the upstream TAP handler, to display the log with suiteEnd. -local global_helpers = require('test.helpers') +local t_global = require('test.testutil') return function(options) local busted = require 'busted' local handler = require 'busted.outputHandlers.TAP'(options) local suiteEnd = function() - io.write(global_helpers.read_nvim_log(nil, true)) + io.write(t_global.read_nvim_log(nil, true)) return nil, true end busted.subscribe({ 'suite', 'end' }, suiteEnd) diff --git a/test/busted/outputHandlers/nvim.lua b/test/busted/outputHandlers/nvim.lua @@ -1,5 +1,5 @@ local pretty = require 'pl.pretty' -local global_helpers = require('test.helpers') +local t_global = require('test.testutil') local colors = setmetatable({}, { __index = function() @@ -236,7 +236,7 @@ return function(options) io.write(suiteEndString:format(testCount, tests, fileCount, files, elapsedTime_ms)) io.write(getSummaryString()) if failureCount > 0 or errorCount > 0 then - io.write(global_helpers.read_nvim_log(nil, true)) + io.write(t_global.read_nvim_log(nil, true)) end io.flush() diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local neq = helpers.neq -local exec_lua = helpers.exec_lua -local matches = helpers.matches -local api = helpers.api -local source = helpers.source -local pcall_err = helpers.pcall_err +local t = require('test.functional.testutil')(after_each) + +local clear = t.clear +local command = t.command +local eq = t.eq +local neq = t.neq +local exec_lua = t.exec_lua +local matches = t.matches +local api = t.api +local source = t.source +local pcall_err = t.pcall_err before_each(clear) diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua @@ -1,21 +1,21 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local eq = helpers.eq -local ok = helpers.ok -local describe_lua_and_rpc = helpers.describe_lua_and_rpc(describe) -local api = helpers.api -local fn = helpers.fn -local request = helpers.request -local exc_exec = helpers.exc_exec -local exec_lua = helpers.exec_lua -local feed_command = helpers.feed_command -local insert = helpers.insert +local clear = t.clear +local eq = t.eq +local ok = t.ok +local describe_lua_and_rpc = t.describe_lua_and_rpc(describe) +local api = t.api +local fn = t.fn +local request = t.request +local exc_exec = t.exc_exec +local exec_lua = t.exec_lua +local feed_command = t.feed_command +local insert = t.insert local NIL = vim.NIL -local command = helpers.command -local feed = helpers.feed -local pcall_err = helpers.pcall_err -local assert_alive = helpers.assert_alive +local command = t.command +local feed = t.feed +local pcall_err = t.pcall_err +local assert_alive = t.assert_alive describe('api/buf', function() before_each(clear) diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq, ok = helpers.eq, helpers.ok -local fn = helpers.fn -local api = helpers.api -local command, eval, next_msg = helpers.command, helpers.eval, helpers.next_msg -local nvim_prog = helpers.nvim_prog -local pcall_err = helpers.pcall_err +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eq, ok = t.eq, t.ok +local fn = t.fn +local api = t.api +local command, eval, next_msg = t.command, t.eval, t.next_msg +local nvim_prog = t.nvim_prog +local pcall_err = t.pcall_err local sleep = vim.uv.sleep -local write_file = helpers.write_file +local write_file = t.write_file local origlines = { 'original line 1', @@ -34,7 +34,7 @@ local function sendkeys(keys) end local function open(activate, lines) - local filename = helpers.tmpname() + local filename = t.tmpname() write_file(filename, table.concat(lines, '\n') .. '\n', true) command('edit ' .. filename) local b = api.nvim_get_current_buf() @@ -511,11 +511,11 @@ describe('API: buffer events:', function() -- create several new sessions, in addition to our main API local sessions = {} - local pipe = helpers.new_pipename() + local pipe = t.new_pipename() eval("serverstart('" .. pipe .. "')") - sessions[1] = helpers.connect(pipe) - sessions[2] = helpers.connect(pipe) - sessions[3] = helpers.connect(pipe) + sessions[1] = t.connect(pipe) + sessions[2] = t.connect(pipe) + sessions[3] = t.connect(pipe) local function request(sessionnr, method, ...) local status, rv = sessions[sessionnr]:request(method, ...) @@ -814,7 +814,7 @@ describe('API: buffer events:', function() clear() sleep(250) -- response - eq(true, helpers.request('nvim_buf_attach', 0, false, {})) + eq(true, t.request('nvim_buf_attach', 0, false, {})) -- notification eq({ [1] = 'notification', diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua @@ -1,17 +1,17 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local NIL = vim.NIL -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local api = helpers.api -local matches = helpers.matches -local source = helpers.source -local pcall_err = helpers.pcall_err -local exec_lua = helpers.exec_lua -local assert_alive = helpers.assert_alive -local feed = helpers.feed -local fn = helpers.fn +local clear = t.clear +local command = t.command +local eq = t.eq +local api = t.api +local matches = t.matches +local source = t.source +local pcall_err = t.pcall_err +local exec_lua = t.exec_lua +local assert_alive = t.assert_alive +local feed = t.feed +local fn = t.fn describe('nvim_get_commands', function() local cmd_dict = { diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua @@ -1,20 +1,20 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local request = helpers.request -local eq = helpers.eq -local ok = helpers.ok -local pcall_err = helpers.pcall_err -local insert = helpers.insert -local feed = helpers.feed -local clear = helpers.clear -local command = helpers.command -local exec = helpers.exec -local api = helpers.api -local assert_alive = helpers.assert_alive +local request = t.request +local eq = t.eq +local ok = t.ok +local pcall_err = t.pcall_err +local insert = t.insert +local feed = t.feed +local clear = t.clear +local command = t.command +local exec = t.exec +local api = t.api +local assert_alive = t.assert_alive local function expect(contents) - return eq(contents, helpers.curbuf_contents()) + return eq(contents, t.curbuf_contents()) end local function set_extmark(ns_id, id, line, col, opts) diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear +local t = require('test.functional.testutil')(after_each) +local clear = t.clear local Screen = require('test.functional.ui.screen') -local eq, eval = helpers.eq, helpers.eval -local command = helpers.command -local exec_capture = helpers.exec_capture -local api = helpers.api -local fn = helpers.fn -local pcall_err = helpers.pcall_err -local ok = helpers.ok -local assert_alive = helpers.assert_alive +local eq, eval = t.eq, t.eval +local command = t.command +local exec_capture = t.exec_capture +local api = t.api +local fn = t.fn +local pcall_err = t.pcall_err +local ok = t.ok +local assert_alive = t.assert_alive describe('API: highlight', function() clear() diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua @@ -1,17 +1,17 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local command = helpers.command -local eq, neq = helpers.eq, helpers.neq -local exec_lua = helpers.exec_lua -local exec = helpers.exec -local feed = helpers.feed -local fn = helpers.fn -local api = helpers.api -local source = helpers.source -local pcall_err = helpers.pcall_err - -local shallowcopy = helpers.shallowcopy +local t = require('test.functional.testutil')(after_each) + +local clear = t.clear +local command = t.command +local eq, neq = t.eq, t.neq +local exec_lua = t.exec_lua +local exec = t.exec +local feed = t.feed +local fn = t.fn +local api = t.api +local source = t.source +local pcall_err = t.pcall_err + +local shallowcopy = t.shallowcopy local sleep = vim.uv.sleep local sid_api_client = -9 @@ -1114,7 +1114,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() feed('asdf\n') eq(1, exec_lua [[return GlobalCount]]) - eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) + eq('\nNo mapping found', t.exec_capture('nmap asdf')) end) it('no double-free when unmapping simplifiable lua mappings', function() @@ -1138,13 +1138,13 @@ describe('nvim_set_keymap, nvim_del_keymap', function() feed('<C-I>\n') eq(1, exec_lua [[return GlobalCount]]) - eq('\nNo mapping found', helpers.exec_capture('nmap <C-I>')) + eq('\nNo mapping found', t.exec_capture('nmap <C-I>')) end) it('can set descriptions on mappings', function() api.nvim_set_keymap('n', 'lhs', 'rhs', { desc = 'map description' }) eq(generate_mapargs('n', 'lhs', 'rhs', { desc = 'map description' }), get_mapargs('n', 'lhs')) - eq('\nn lhs rhs\n map description', helpers.exec_capture('nmap lhs')) + eq('\nn lhs rhs\n map description', t.exec_capture('nmap lhs')) end) it('can define !-mode abbreviations with lua callbacks', function() @@ -1290,7 +1290,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() it('does not crash when setting mapping in a non-existing buffer #13541', function() pcall_err(api.nvim_buf_set_keymap, 100, '', 'lsh', 'irhs<Esc>', {}) - helpers.assert_alive() + t.assert_alive() end) it('can make lua mappings', function() @@ -1372,7 +1372,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() feed('asdf\n') eq(1, exec_lua [[return GlobalCount]]) - eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) + eq('\nNo mapping found', t.exec_capture('nmap asdf')) end) it('no double-free when unmapping simplifiable lua mappings', function() @@ -1396,6 +1396,6 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() feed('<C-I>\n') eq(1, exec_lua [[return GlobalCount]]) - eq('\nNo mapping found', helpers.exec_capture('nmap <C-I>')) + eq('\nNo mapping found', t.exec_capture('nmap <C-I>')) end) end) diff --git a/test/functional/api/menu_spec.lua b/test/functional/api/menu_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local feed = helpers.feed +local clear = t.clear +local command = t.command +local feed = t.feed describe('update_menu notification', function() local screen diff --git a/test/functional/api/proc_spec.lua b/test/functional/api/proc_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local fn = helpers.fn -local neq = helpers.neq -local nvim_argv = helpers.nvim_argv -local request = helpers.request -local retry = helpers.retry +local clear = t.clear +local eq = t.eq +local fn = t.fn +local neq = t.neq +local nvim_argv = t.nvim_argv +local request = t.request +local retry = t.retry local NIL = vim.NIL -local is_os = helpers.is_os +local is_os = t.is_os describe('API', function() before_each(clear) diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua @@ -1,12 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local assert_log = helpers.assert_log -local eq, clear, eval, command, next_msg = - helpers.eq, helpers.clear, helpers.eval, helpers.command, helpers.next_msg -local api = helpers.api -local exec_lua = helpers.exec_lua -local retry = helpers.retry -local assert_alive = helpers.assert_alive -local check_close = helpers.check_close +local t = require('test.functional.testutil')(after_each) +local assert_log = t.assert_log +local eq, clear, eval, command, next_msg = t.eq, t.clear, t.eval, t.command, t.next_msg +local api = t.api +local exec_lua = t.exec_lua +local retry = t.retry +local assert_alive = t.assert_alive +local check_close = t.check_close local testlog = 'Xtest-server-notify-log' diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua @@ -1,17 +1,17 @@ -- Test server -> client RPC scenarios. Note: unlike `rpcnotify`, to evaluate -- `rpcrequest` calls we need the client event loop to be running. -local helpers = require('test.functional.helpers')(after_each) - -local clear, eval = helpers.clear, helpers.eval -local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop -local nvim_prog, command, fn = helpers.nvim_prog, helpers.command, helpers.fn -local source, next_msg = helpers.source, helpers.next_msg -local ok = helpers.ok -local api = helpers.api -local spawn, merge_args = helpers.spawn, helpers.merge_args -local set_session = helpers.set_session -local pcall_err = helpers.pcall_err -local assert_alive = helpers.assert_alive +local t = require('test.functional.testutil')(after_each) + +local clear, eval = t.clear, t.eval +local eq, neq, run, stop = t.eq, t.neq, t.run, t.stop +local nvim_prog, command, fn = t.nvim_prog, t.command, t.fn +local source, next_msg = t.source, t.next_msg +local ok = t.ok +local api = t.api +local spawn, merge_args = t.spawn, t.merge_args +local set_session = t.set_session +local pcall_err = t.pcall_err +local assert_alive = t.assert_alive describe('server -> client', function() local cid @@ -259,7 +259,7 @@ describe('server -> client', function() pcall(fn.jobstop, jobid) end) - if helpers.skip(helpers.is_os('win')) then + if t.skip(t.is_os('win')) then return end @@ -280,7 +280,7 @@ describe('server -> client', function() end) describe('connecting to another (peer) nvim', function() - local nvim_argv = merge_args(helpers.nvim_argv, { '--headless' }) + local nvim_argv = merge_args(t.nvim_argv, { '--headless' }) local function connect_test(server, mode, address) local serverpid = fn.getpid() local client = spawn(nvim_argv, false, nil, true) diff --git a/test/functional/api/tabpage_spec.lua b/test/functional/api/tabpage_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, eq, ok = helpers.clear, helpers.eq, helpers.ok -local exec = helpers.exec -local feed = helpers.feed -local api = helpers.api -local fn = helpers.fn -local request = helpers.request +local t = require('test.functional.testutil')(after_each) +local clear, eq, ok = t.clear, t.eq, t.ok +local exec = t.exec +local feed = t.feed +local api = t.api +local fn = t.fn +local request = t.request local NIL = vim.NIL -local pcall_err = helpers.pcall_err -local command = helpers.command +local pcall_err = t.pcall_err +local command = t.command describe('api/tabpage', function() before_each(clear) diff --git a/test/functional/api/ui_spec.lua b/test/functional/api/ui_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval -local exec = helpers.exec -local feed = helpers.feed -local api = helpers.api -local request = helpers.request -local pcall_err = helpers.pcall_err +local clear = t.clear +local command = t.command +local eq = t.eq +local eval = t.eval +local exec = t.exec +local feed = t.feed +local api = t.api +local request = t.request +local pcall_err = t.pcall_err describe('nvim_ui_attach()', function() before_each(function() diff --git a/test/functional/api/version_spec.lua b/test/functional/api/version_spec.lua @@ -1,6 +1,6 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, fn, eq = helpers.clear, helpers.fn, helpers.eq -local api = helpers.api +local t = require('test.functional.testutil')(after_each) +local clear, fn, eq = t.clear, t.fn, t.eq +local api = t.api local function read_mpack_file(fname) local fd = io.open(fname, 'rb') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua @@ -1,42 +1,42 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') local uv = vim.uv local fmt = string.format -local dedent = helpers.dedent -local assert_alive = helpers.assert_alive +local dedent = t.dedent +local assert_alive = t.assert_alive local NIL = vim.NIL -local clear, eq, neq = helpers.clear, helpers.eq, helpers.neq -local command = helpers.command -local command_output = helpers.api.nvim_command_output -local exec = helpers.exec -local exec_capture = helpers.exec_capture -local eval = helpers.eval -local expect = helpers.expect -local fn = helpers.fn -local api = helpers.api -local matches = helpers.matches +local clear, eq, neq = t.clear, t.eq, t.neq +local command = t.command +local command_output = t.api.nvim_command_output +local exec = t.exec +local exec_capture = t.exec_capture +local eval = t.eval +local expect = t.expect +local fn = t.fn +local api = t.api +local matches = t.matches local pesc = vim.pesc -local mkdir_p = helpers.mkdir_p -local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed -local async_meths = helpers.async_meths -local is_os = helpers.is_os -local parse_context = helpers.parse_context -local request = helpers.request -local rmdir = helpers.rmdir -local source = helpers.source -local next_msg = helpers.next_msg -local tmpname = helpers.tmpname -local write_file = helpers.write_file -local exec_lua = helpers.exec_lua -local exc_exec = helpers.exc_exec -local insert = helpers.insert -local skip = helpers.skip - -local pcall_err = helpers.pcall_err +local mkdir_p = t.mkdir_p +local ok, nvim_async, feed = t.ok, t.nvim_async, t.feed +local async_meths = t.async_meths +local is_os = t.is_os +local parse_context = t.parse_context +local request = t.request +local rmdir = t.rmdir +local source = t.source +local next_msg = t.next_msg +local tmpname = t.tmpname +local write_file = t.write_file +local exec_lua = t.exec_lua +local exc_exec = t.exc_exec +local insert = t.insert +local skip = t.skip + +local pcall_err = t.pcall_err local format_string = require('test.format_string').format_string -local intchar2lua = helpers.intchar2lua -local mergedicts_copy = helpers.mergedicts_copy +local intchar2lua = t.intchar2lua +local mergedicts_copy = t.mergedicts_copy local endswith = vim.endswith describe('API', function() @@ -702,12 +702,12 @@ describe('API', function() end) after_each(function() - helpers.rmdir('Xtestdir') + t.rmdir('Xtestdir') end) it('works', function() api.nvim_set_current_dir('Xtestdir') - eq(start_dir .. helpers.get_pathsep() .. 'Xtestdir', fn.getcwd()) + eq(start_dir .. t.get_pathsep() .. 'Xtestdir', fn.getcwd()) end) it('sets previous directory', function() @@ -1467,7 +1467,7 @@ describe('API', function() eq(NIL, api.nvim_get_var('Unknown_script_func')) -- Check if autoload works properly - local pathsep = helpers.get_pathsep() + local pathsep = t.get_pathsep() local xconfig = 'Xhome' .. pathsep .. 'Xconfig' local xdata = 'Xhome' .. pathsep .. 'Xdata' local autoload_folder = table.concat({ xconfig, 'nvim', 'autoload' }, pathsep) @@ -1951,7 +1951,7 @@ describe('API', function() describe('RPC (K_EVENT)', function() it('does not complete ("interrupt") normal-mode operator-pending #6166', function() - helpers.insert([[ + t.insert([[ FIRST LINE SECOND LINE]]) api.nvim_input('gg') @@ -1988,7 +1988,7 @@ describe('API', function() it('does not complete ("interrupt") normal-mode map-pending #6166', function() command("nnoremap dd :let g:foo='it worked...'<CR>") - helpers.insert([[ + t.insert([[ FIRST LINE SECOND LINE]]) api.nvim_input('gg') @@ -2000,13 +2000,13 @@ describe('API', function() expect([[ FIRST LINE SECOND LINE]]) - eq('it worked...', helpers.eval('g:foo')) + eq('it worked...', t.eval('g:foo')) end) it('does not complete ("interrupt") insert-mode map-pending #6166', function() command('inoremap xx foo') command('set timeoutlen=9999') - helpers.insert([[ + t.insert([[ FIRST LINE SECOND LINE]]) api.nvim_input('ix') @@ -2153,35 +2153,32 @@ describe('API', function() describe('nvim_replace_termcodes', function() it('escapes K_SPECIAL as K_SPECIAL KS_SPECIAL KE_FILLER', function() - eq('\128\254X', helpers.api.nvim_replace_termcodes('\128', true, true, true)) + eq('\128\254X', t.api.nvim_replace_termcodes('\128', true, true, true)) end) it('leaves non-K_SPECIAL string unchanged', function() - eq('abc', helpers.api.nvim_replace_termcodes('abc', true, true, true)) + eq('abc', t.api.nvim_replace_termcodes('abc', true, true, true)) end) it('converts <expressions>', function() - eq('\\', helpers.api.nvim_replace_termcodes('<Leader>', true, true, true)) + eq('\\', t.api.nvim_replace_termcodes('<Leader>', true, true, true)) end) it('converts <LeftMouse> to K_SPECIAL KS_EXTRA KE_LEFTMOUSE', function() -- K_SPECIAL KS_EXTRA KE_LEFTMOUSE -- 0x80 0xfd 0x2c -- 128 253 44 - eq('\128\253\44', helpers.api.nvim_replace_termcodes('<LeftMouse>', true, true, true)) + eq('\128\253\44', t.api.nvim_replace_termcodes('<LeftMouse>', true, true, true)) end) it('converts keycodes', function() - eq( - '\nx\27x\rx<x', - helpers.api.nvim_replace_termcodes('<NL>x<Esc>x<CR>x<lt>x', true, true, true) - ) + eq('\nx\27x\rx<x', t.api.nvim_replace_termcodes('<NL>x<Esc>x<CR>x<lt>x', true, true, true)) end) it('does not convert keycodes if special=false', function() eq( '<NL>x<Esc>x<CR>x<lt>x', - helpers.api.nvim_replace_termcodes('<NL>x<Esc>x<CR>x<lt>x', true, true, false) + t.api.nvim_replace_termcodes('<NL>x<Esc>x<CR>x<lt>x', true, true, false) ) end) @@ -2210,18 +2207,18 @@ describe('API', function() api.nvim_feedkeys(':let x1="…"\n', '', true) -- Both nvim_replace_termcodes and nvim_feedkeys escape \x80 - local inp = helpers.api.nvim_replace_termcodes(':let x2="…"<CR>', true, true, true) + local inp = t.api.nvim_replace_termcodes(':let x2="…"<CR>', true, true, true) api.nvim_feedkeys(inp, '', true) -- escape_ks=true -- nvim_feedkeys with K_SPECIAL escaping disabled - inp = helpers.api.nvim_replace_termcodes(':let x3="…"<CR>', true, true, true) + inp = t.api.nvim_replace_termcodes(':let x3="…"<CR>', true, true, true) api.nvim_feedkeys(inp, '', false) -- escape_ks=false - helpers.stop() + t.stop() end -- spin the loop a bit - helpers.run(nil, nil, on_setup) + t.run(nil, nil, on_setup) eq('…', api.nvim_get_var('x1')) -- Because of the double escaping this is neq @@ -2364,7 +2361,7 @@ describe('API', function() {0:~ }|*6 {1:very fail} | ]]) - helpers.poke_eventloop() + t.poke_eventloop() -- shows up to &cmdheight lines async_meths.nvim_err_write('more fail\ntoo fail\n') @@ -2676,7 +2673,7 @@ describe('API', function() describe('nvim_list_runtime_paths', function() setup(function() - local pathsep = helpers.get_pathsep() + local pathsep = t.get_pathsep() mkdir_p('Xtest' .. pathsep .. 'a') mkdir_p('Xtest' .. pathsep .. 'b') end) @@ -3183,7 +3180,7 @@ describe('API', function() end) describe('nvim_get_runtime_file', function() - local p = helpers.alter_slashes + local p = t.alter_slashes it('can find files', function() eq({}, api.nvim_get_runtime_file('bork.borkbork', false)) eq({}, api.nvim_get_runtime_file('bork.borkbork', true)) @@ -3410,13 +3407,13 @@ describe('API', function() {desc="(global option, fallback requested) points to global", linenr=9, sid=1, args={'completeopt', {}}}, } - for _, t in pairs(tests) do - it(t.desc, function() + for _, test in pairs(tests) do + it(test.desc, function() -- Switch to the target buffer/window so that curbuf/curwin are used. api.nvim_set_current_win(wins[2]) - local info = api.nvim_get_option_info2(unpack(t.args)) - eq(t.linenr, info.last_set_linenr) - eq(t.sid, info.last_set_sid) + local info = api.nvim_get_option_info2(unpack(test.args)) + eq(test.linenr, info.last_set_linenr) + eq(test.sid, info.last_set_sid) end) end @@ -3537,9 +3534,9 @@ describe('API', function() false, { width = 79, height = 31, row = 1, col = 1, relative = 'editor' } ) - local t = api.nvim_open_term(b, {}) + local term = api.nvim_open_term(b, {}) - api.nvim_chan_send(t, io.open('test/functional/fixtures/smile2.cat', 'r'):read('*a')) + api.nvim_chan_send(term, io.open('test/functional/fixtures/smile2.cat', 'r'):read('*a')) screen:expect { grid = [[ ^ | diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua @@ -1,27 +1,27 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') local clear, curbuf, curbuf_contents, curwin, eq, neq, matches, ok, feed, insert, eval = - helpers.clear, - helpers.api.nvim_get_current_buf, - helpers.curbuf_contents, - helpers.api.nvim_get_current_win, - helpers.eq, - helpers.neq, - helpers.matches, - helpers.ok, - helpers.feed, - helpers.insert, - helpers.eval -local poke_eventloop = helpers.poke_eventloop -local exec = helpers.exec -local exec_lua = helpers.exec_lua -local fn = helpers.fn -local request = helpers.request + t.clear, + t.api.nvim_get_current_buf, + t.curbuf_contents, + t.api.nvim_get_current_win, + t.eq, + t.neq, + t.matches, + t.ok, + t.feed, + t.insert, + t.eval +local poke_eventloop = t.poke_eventloop +local exec = t.exec +local exec_lua = t.exec_lua +local fn = t.fn +local request = t.request local NIL = vim.NIL -local api = helpers.api -local command = helpers.command -local pcall_err = helpers.pcall_err -local assert_alive = helpers.assert_alive +local api = t.api +local command = t.command +local pcall_err = t.pcall_err +local assert_alive = t.assert_alive describe('API/win', function() before_each(clear) @@ -1297,7 +1297,7 @@ describe('API/win', function() local tab1 = api.nvim_get_current_tabpage() local tab1_win = api.nvim_get_current_win() - helpers.command('tabnew') + t.command('tabnew') local tab2 = api.nvim_get_current_tabpage() local tab2_win = api.nvim_get_current_win() diff --git a/test/functional/autocmd/autocmd_oldtest_spec.lua b/test/functional/autocmd/autocmd_oldtest_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local eq = helpers.eq -local api = helpers.api -local fn = helpers.fn -local exec = helpers.exec -local feed = helpers.feed -local assert_log = helpers.assert_log -local check_close = helpers.check_close -local is_os = helpers.is_os +local clear = t.clear +local eq = t.eq +local api = t.api +local fn = t.fn +local exec = t.exec +local feed = t.feed +local assert_log = t.assert_log +local check_close = t.check_close +local is_os = t.is_os local testlog = 'Xtest_autocmd_oldtest_log' diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua @@ -1,24 +1,24 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local assert_visible = helpers.assert_visible -local assert_alive = helpers.assert_alive -local dedent = helpers.dedent -local eq = helpers.eq -local neq = helpers.neq -local eval = helpers.eval -local feed = helpers.feed -local clear = helpers.clear -local matches = helpers.matches -local api = helpers.api -local pcall_err = helpers.pcall_err -local fn = helpers.fn -local expect = helpers.expect -local command = helpers.command -local exc_exec = helpers.exc_exec -local exec_lua = helpers.exec_lua -local retry = helpers.retry -local source = helpers.source +local assert_visible = t.assert_visible +local assert_alive = t.assert_alive +local dedent = t.dedent +local eq = t.eq +local neq = t.neq +local eval = t.eval +local feed = t.feed +local clear = t.clear +local matches = t.matches +local api = t.api +local pcall_err = t.pcall_err +local fn = t.fn +local expect = t.expect +local command = t.command +local exc_exec = t.exc_exec +local exec_lua = t.exec_lua +local retry = t.retry +local source = t.source describe('autocmd', function() before_each(clear) diff --git a/test/functional/autocmd/bufenter_spec.lua b/test/functional/autocmd/bufenter_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval -local request = helpers.request -local source = helpers.source +local clear = t.clear +local command = t.command +local eq = t.eq +local eval = t.eval +local request = t.request +local source = t.source describe('autocmd BufEnter', function() before_each(clear) @@ -33,7 +33,7 @@ describe('autocmd BufEnter', function() end) it('triggered by ":split normal|:help|:bw"', function() - helpers.add_builddir_to_rtp() + t.add_builddir_to_rtp() command('split normal') command('wincmd j') command('help') diff --git a/test/functional/autocmd/bufmodifiedset_spec.lua b/test/functional/autocmd/bufmodifiedset_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local eval = helpers.eval -local source = helpers.source -local request = helpers.request +local clear = t.clear +local eq = t.eq +local eval = t.eval +local source = t.source +local request = t.request describe('BufModified', function() before_each(clear) diff --git a/test/functional/autocmd/cmdline_spec.lua b/test/functional/autocmd/cmdline_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local expect = helpers.expect -local eval = helpers.eval -local next_msg = helpers.next_msg -local feed = helpers.feed -local api = helpers.api +local clear = t.clear +local command = t.command +local eq = t.eq +local expect = t.expect +local eval = t.eval +local next_msg = t.next_msg +local feed = t.feed +local api = t.api describe('cmdline autocommands', function() local channel diff --git a/test/functional/autocmd/cursorhold_spec.lua b/test/functional/autocmd/cursorhold_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local feed = helpers.feed -local retry = helpers.retry -local exec = helpers.source +local clear = t.clear +local eq = t.eq +local feed = t.feed +local retry = t.retry +local exec = t.source local sleep = vim.uv.sleep -local api = helpers.api +local api = t.api before_each(clear) diff --git a/test/functional/autocmd/cursormoved_spec.lua b/test/functional/autocmd/cursormoved_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local eval = helpers.eval -local api = helpers.api -local source = helpers.source -local command = helpers.command +local clear = t.clear +local eq = t.eq +local eval = t.eval +local api = t.api +local source = t.source +local command = t.command describe('CursorMoved', function() before_each(clear) diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval -local request = helpers.request -local is_os = helpers.is_os +local clear = t.clear +local command = t.command +local eq = t.eq +local eval = t.eval +local request = t.request +local is_os = t.is_os describe('autocmd DirChanged and DirChangedPre', function() local curdir = vim.uv.cwd():gsub('\\', '/') @@ -22,12 +22,12 @@ describe('autocmd DirChanged and DirChangedPre', function() setup(function() for _, dir in pairs(dirs) do - helpers.mkdir(dir) + t.mkdir(dir) end end) teardown(function() for _, dir in pairs(dirs) do - helpers.rmdir(dir) + t.rmdir(dir) end end) diff --git a/test/functional/autocmd/filetype_spec.lua b/test/functional/autocmd/filetype_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eval = helpers.eval -local clear = helpers.clear -local command = helpers.command +local eval = t.eval +local clear = t.clear +local command = t.command describe('autocmd FileType', function() before_each(clear) it('is triggered by :help only once', function() - helpers.add_builddir_to_rtp() + t.add_builddir_to_rtp() command('let g:foo = 0') command('autocmd FileType help let g:foo = g:foo + 1') command('help help') diff --git a/test/functional/autocmd/focus_spec.lua b/test/functional/autocmd/focus_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) -local thelpers = require('test.functional.terminal.helpers') -local clear = helpers.clear -local feed_command = helpers.feed_command -local feed_data = thelpers.feed_data +local t = require('test.functional.testutil')(after_each) +local tt = require('test.functional.terminal.testutil') +local clear = t.clear +local feed_command = t.feed_command +local feed_data = tt.feed_data -if helpers.skip(helpers.is_os('win')) then +if t.skip(t.is_os('win')) then return end @@ -14,7 +14,7 @@ describe('autoread TUI FocusGained/FocusLost', function() before_each(function() clear() - screen = thelpers.setup_child_nvim({ + screen = tt.setup_child_nvim({ '-u', 'NONE', '-i', @@ -39,7 +39,7 @@ describe('autoread TUI FocusGained/FocusLost', function() line 4 ]] - helpers.write_file(path, '') + t.write_file(path, '') local atime = os.time() - 10 vim.uv.fs_utime(path, atime, atime) @@ -75,7 +75,7 @@ describe('autoread TUI FocusGained/FocusLost', function() unchanged = true, } - helpers.write_file(path, expected_addition) + t.write_file(path, expected_addition) feed_data('\027[I') diff --git a/test/functional/autocmd/modechanged_spec.lua b/test/functional/autocmd/modechanged_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq -local feed, command = helpers.feed, helpers.command -local exec_lua = helpers.exec_lua +local t = require('test.functional.testutil')(after_each) +local clear, eval, eq = t.clear, t.eval, t.eq +local feed, command = t.feed, t.command +local exec_lua = t.exec_lua describe('ModeChanged', function() before_each(function() diff --git a/test/functional/autocmd/recording_spec.lua b/test/functional/autocmd/recording_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local eval = helpers.eval -local source_vim = helpers.source +local clear = t.clear +local eq = t.eq +local eval = t.eval +local source_vim = t.source describe('RecordingEnter', function() before_each(clear) diff --git a/test/functional/autocmd/safestate_spec.lua b/test/functional/autocmd/safestate_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local exec = helpers.exec -local feed = helpers.feed -local api = helpers.api +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eq = t.eq +local exec = t.exec +local feed = t.feed +local api = t.api before_each(clear) diff --git a/test/functional/autocmd/searchwrapped_spec.lua b/test/functional/autocmd/searchwrapped_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local command = helpers.command -local api = helpers.api -local eq = helpers.eq -local eval = helpers.eval -local feed = helpers.feed +local t = require('test.functional.testutil')(after_each) + +local clear = t.clear +local command = t.command +local api = t.api +local eq = t.eq +local eval = t.eval +local feed = t.feed describe('autocmd SearchWrapped', function() before_each(function() diff --git a/test/functional/autocmd/show_spec.lua b/test/functional/autocmd/show_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local dedent = helpers.dedent -local eq = helpers.eq -local fn = helpers.fn -local eval = helpers.eval -local exec = helpers.exec -local feed = helpers.feed +local clear = t.clear +local command = t.command +local dedent = t.dedent +local eq = t.eq +local fn = t.fn +local eval = t.eval +local exec = t.exec +local feed = t.feed describe(':autocmd', function() before_each(function() diff --git a/test/functional/autocmd/signal_spec.lua b/test/functional/autocmd/signal_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local fn = helpers.fn -local next_msg = helpers.next_msg -local is_os = helpers.is_os -local skip = helpers.skip +local t = require('test.functional.testutil')(after_each) + +local clear = t.clear +local command = t.command +local eq = t.eq +local fn = t.fn +local next_msg = t.next_msg +local is_os = t.is_os +local skip = t.skip if skip(is_os('win'), 'Only applies to POSIX systems') then return diff --git a/test/functional/autocmd/tabclose_spec.lua b/test/functional/autocmd/tabclose_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, eq = helpers.clear, helpers.eq -local api = helpers.api -local command = helpers.command +local t = require('test.functional.testutil')(after_each) +local clear, eq = t.clear, t.eq +local api = t.api +local command = t.command describe('TabClosed', function() before_each(clear) diff --git a/test/functional/autocmd/tabnew_spec.lua b/test/functional/autocmd/tabnew_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval +local clear = t.clear +local command = t.command +local eq = t.eq +local eval = t.eval describe('autocmd TabNew', function() before_each(clear) diff --git a/test/functional/autocmd/tabnewentered_spec.lua b/test/functional/autocmd/tabnewentered_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local command = helpers.command -local dedent = helpers.dedent -local eval = helpers.eval -local eq = helpers.eq -local feed = helpers.feed -local api = helpers.api -local exec_capture = helpers.exec_capture +local t = require('test.functional.testutil')(after_each) + +local clear = t.clear +local command = t.command +local dedent = t.dedent +local eval = t.eval +local eq = t.eq +local feed = t.feed +local api = t.api +local exec_capture = t.exec_capture describe('TabNewEntered', function() describe('au TabNewEntered', function() diff --git a/test/functional/autocmd/termxx_spec.lua b/test/functional/autocmd/termxx_spec.lua @@ -1,17 +1,17 @@ local uv = vim.uv -local helpers = require('test.functional.helpers')(after_each) -local thelpers = require('test.functional.terminal.helpers') - -local clear, command, testprg = helpers.clear, helpers.command, helpers.testprg -local eval, eq, neq, retry = helpers.eval, helpers.eq, helpers.neq, helpers.retry -local matches = helpers.matches -local ok = helpers.ok -local feed = helpers.feed -local api = helpers.api -local pcall_err = helpers.pcall_err -local assert_alive = helpers.assert_alive -local skip = helpers.skip -local is_os = helpers.is_os +local t = require('test.functional.testutil')(after_each) +local tt = require('test.functional.terminal.testutil') + +local clear, command, testprg = t.clear, t.command, t.testprg +local eval, eq, neq, retry = t.eval, t.eq, t.neq, t.retry +local matches = t.matches +local ok = t.ok +local feed = t.feed +local api = t.api +local pcall_err = t.pcall_err +local assert_alive = t.assert_alive +local skip = t.skip +local is_os = t.is_os describe('autocmd TermClose', function() before_each(function() @@ -198,11 +198,11 @@ end) describe('autocmd TextChangedT', function() clear() - local screen = thelpers.screen_setup() + local screen = tt.screen_setup() it('works', function() command('autocmd TextChangedT * ++once let g:called = 1') - thelpers.feed_data('a') + tt.feed_data('a') retry(nil, nil, function() eq(1, api.nvim_get_var('called')) end) @@ -210,7 +210,7 @@ describe('autocmd TextChangedT', function() it('cannot delete terminal buffer', function() command([[autocmd TextChangedT * call nvim_input('<CR>') | bwipe!]]) - thelpers.feed_data('a') + tt.feed_data('a') screen:expect({ any = 'E937: ' }) matches( '^E937: Attempt to delete a buffer that is in use: term://', diff --git a/test/functional/autocmd/textchanged_spec.lua b/test/functional/autocmd/textchanged_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local exec = helpers.exec -local command = helpers.command -local feed = helpers.feed -local eq = helpers.eq -local neq = helpers.neq -local eval = helpers.eval -local poke_eventloop = helpers.poke_eventloop -local write_file = helpers.write_file +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local exec = t.exec +local command = t.command +local feed = t.feed +local eq = t.eq +local neq = t.neq +local eval = t.eval +local poke_eventloop = t.poke_eventloop +local write_file = t.write_file -- oldtest: Test_ChangedP() it('TextChangedI and TextChangedP autocommands', function() diff --git a/test/functional/autocmd/textyankpost_spec.lua b/test/functional/autocmd/textyankpost_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq -local feed, command, expect = helpers.feed, helpers.command, helpers.expect -local api, fn, neq = helpers.api, helpers.fn, helpers.neq +local t = require('test.functional.testutil')(after_each) +local clear, eval, eq = t.clear, t.eval, t.eq +local feed, command, expect = t.feed, t.command, t.expect +local api, fn, neq = t.api, t.fn, t.neq describe('TextYankPost', function() before_each(function() diff --git a/test/functional/autocmd/win_scrolled_resized_spec.lua b/test/functional/autocmd/win_scrolled_resized_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local eq = helpers.eq -local eval = helpers.eval -local exec = helpers.exec -local command = helpers.command -local feed = helpers.feed -local api = helpers.api -local assert_alive = helpers.assert_alive +local clear = t.clear +local eq = t.eq +local eval = t.eval +local exec = t.exec +local command = t.command +local feed = t.feed +local api = t.api +local assert_alive = t.assert_alive before_each(clear) diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua @@ -1,18 +1,17 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, eq, eval, next_msg, ok, source = - helpers.clear, helpers.eq, helpers.eval, helpers.next_msg, helpers.ok, helpers.source -local command, fn, api = helpers.command, helpers.fn, helpers.api -local matches = helpers.matches +local t = require('test.functional.testutil')(after_each) +local clear, eq, eval, next_msg, ok, source = t.clear, t.eq, t.eval, t.next_msg, t.ok, t.source +local command, fn, api = t.command, t.fn, t.api +local matches = t.matches local sleep = vim.uv.sleep -local spawn, nvim_argv = helpers.spawn, helpers.nvim_argv -local get_session, set_session = helpers.get_session, helpers.set_session -local nvim_prog = helpers.nvim_prog -local is_os = helpers.is_os -local retry = helpers.retry -local expect_twostreams = helpers.expect_twostreams -local assert_alive = helpers.assert_alive -local pcall_err = helpers.pcall_err -local skip = helpers.skip +local spawn, nvim_argv = t.spawn, t.nvim_argv +local get_session, set_session = t.get_session, t.set_session +local nvim_prog = t.nvim_prog +local is_os = t.is_os +local retry = t.retry +local expect_twostreams = t.expect_twostreams +local assert_alive = t.assert_alive +local pcall_err = t.pcall_err +local skip = t.skip describe('channels', function() local init = [[ diff --git a/test/functional/core/exit_spec.lua b/test/functional/core/exit_spec.lua @@ -1,24 +1,24 @@ -local helpers = require('test.functional.helpers')(after_each) - -local assert_alive = helpers.assert_alive -local command = helpers.command -local feed_command = helpers.feed_command -local feed = helpers.feed -local eval = helpers.eval -local eq = helpers.eq -local run = helpers.run -local fn = helpers.fn -local nvim_prog = helpers.nvim_prog -local pcall_err = helpers.pcall_err -local exec_capture = helpers.exec_capture -local poke_eventloop = helpers.poke_eventloop +local t = require('test.functional.testutil')(after_each) + +local assert_alive = t.assert_alive +local command = t.command +local feed_command = t.feed_command +local feed = t.feed +local eval = t.eval +local eq = t.eq +local run = t.run +local fn = t.fn +local nvim_prog = t.nvim_prog +local pcall_err = t.pcall_err +local exec_capture = t.exec_capture +local poke_eventloop = t.poke_eventloop describe('v:exiting', function() local cid before_each(function() - helpers.clear() - cid = helpers.api.nvim_get_chan_info(0).id + t.clear() + cid = t.api.nvim_get_chan_info(0).id end) it('defaults to v:null', function() @@ -74,7 +74,7 @@ describe(':cquit', function() end before_each(function() - helpers.clear() + t.clear() end) it('exits with non-zero after :cquit', function() diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua @@ -1,37 +1,37 @@ local uv = vim.uv -local helpers = require('test.functional.helpers')(after_each) - -local assert_log = helpers.assert_log -local assert_nolog = helpers.assert_nolog -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local neq = helpers.neq -local ok = helpers.ok -local feed = helpers.feed -local fn = helpers.fn -local nvim_prog = helpers.nvim_prog -local request = helpers.request -local retry = helpers.retry -local rmdir = helpers.rmdir -local matches = helpers.matches -local api = helpers.api -local mkdir = helpers.mkdir +local t = require('test.functional.testutil')(after_each) + +local assert_log = t.assert_log +local assert_nolog = t.assert_nolog +local clear = t.clear +local command = t.command +local eq = t.eq +local neq = t.neq +local ok = t.ok +local feed = t.feed +local fn = t.fn +local nvim_prog = t.nvim_prog +local request = t.request +local retry = t.retry +local rmdir = t.rmdir +local matches = t.matches +local api = t.api +local mkdir = t.mkdir local sleep = vim.uv.sleep -local read_file = helpers.read_file +local read_file = t.read_file local trim = vim.trim -local currentdir = helpers.fn.getcwd -local assert_alive = helpers.assert_alive -local check_close = helpers.check_close -local expect_exit = helpers.expect_exit -local write_file = helpers.write_file +local currentdir = t.fn.getcwd +local assert_alive = t.assert_alive +local check_close = t.check_close +local expect_exit = t.expect_exit +local write_file = t.write_file local Screen = require('test.functional.ui.screen') -local feed_command = helpers.feed_command -local skip = helpers.skip -local is_os = helpers.is_os -local is_ci = helpers.is_ci -local spawn = helpers.spawn -local set_session = helpers.set_session +local feed_command = t.feed_command +local skip = t.skip +local is_os = t.is_os +local is_ci = t.is_ci +local spawn = t.spawn +local set_session = t.set_session describe('fileio', function() before_each(function() end) @@ -228,7 +228,7 @@ describe('fileio', function() local initial_content = 'foo' local backup_dir = 'Xtest_backupdir' - local sep = helpers.get_pathsep() + local sep = t.get_pathsep() local link_file_name = 'Xtest_startup_file2' local backup_file_name = backup_dir .. sep .. link_file_name .. '~' @@ -329,7 +329,7 @@ describe('tmpdir', function() before_each(function() -- Fake /tmp dir so that we can mess it up. - os_tmpdir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX') + os_tmpdir = vim.uv.fs_mkdtemp(vim.fs.dirname(t.tmpname()) .. '/nvim_XXXXXXXXXX') end) after_each(function() diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua @@ -1,40 +1,40 @@ -local helpers = require('test.functional.helpers')(after_each) -local thelpers = require('test.functional.terminal.helpers') - -local clear = helpers.clear -local eq = helpers.eq -local eval = helpers.eval -local exc_exec = helpers.exc_exec -local feed_command = helpers.feed_command -local feed = helpers.feed -local insert = helpers.insert -local neq = helpers.neq -local next_msg = helpers.next_msg -local testprg = helpers.testprg -local ok = helpers.ok -local source = helpers.source -local write_file = helpers.write_file -local mkdir = helpers.mkdir -local rmdir = helpers.rmdir -local assert_alive = helpers.assert_alive -local command = helpers.command -local fn = helpers.fn -local os_kill = helpers.os_kill -local retry = helpers.retry -local api = helpers.api +local t = require('test.functional.testutil')(after_each) +local tt = require('test.functional.terminal.testutil') + +local clear = t.clear +local eq = t.eq +local eval = t.eval +local exc_exec = t.exc_exec +local feed_command = t.feed_command +local feed = t.feed +local insert = t.insert +local neq = t.neq +local next_msg = t.next_msg +local testprg = t.testprg +local ok = t.ok +local source = t.source +local write_file = t.write_file +local mkdir = t.mkdir +local rmdir = t.rmdir +local assert_alive = t.assert_alive +local command = t.command +local fn = t.fn +local os_kill = t.os_kill +local retry = t.retry +local api = t.api local NIL = vim.NIL -local poke_eventloop = helpers.poke_eventloop -local get_pathsep = helpers.get_pathsep -local pathroot = helpers.pathroot -local exec_lua = helpers.exec_lua -local nvim_set = helpers.nvim_set -local expect_twostreams = helpers.expect_twostreams -local expect_msg_seq = helpers.expect_msg_seq -local pcall_err = helpers.pcall_err -local matches = helpers.matches +local poke_eventloop = t.poke_eventloop +local get_pathsep = t.get_pathsep +local pathroot = t.pathroot +local exec_lua = t.exec_lua +local nvim_set = t.nvim_set +local expect_twostreams = t.expect_twostreams +local expect_msg_seq = t.expect_msg_seq +local pcall_err = t.pcall_err +local matches = t.matches local Screen = require('test.functional.ui.screen') -local skip = helpers.skip -local is_os = helpers.is_os +local skip = t.skip +local is_os = t.is_os describe('jobs', function() local channel @@ -307,7 +307,7 @@ describe('jobs', function() it('preserves NULs', function() -- Make a file with NULs in it. - local filename = helpers.tmpname() + local filename = t.tmpname() write_file(filename, 'abc\0def\n') command("let j = jobstart(['cat', '" .. filename .. "'], g:job_opts)") @@ -732,7 +732,7 @@ describe('jobs', function() describe('jobwait()', function() before_each(function() if is_os('win') then - helpers.set_shell_powershell() + t.set_shell_powershell() end end) @@ -1182,7 +1182,7 @@ describe('jobs', function() end) it('does not close the same handle twice on exit #25086', function() - local filename = string.format('%s.lua', helpers.tmpname()) + local filename = string.format('%s.lua', t.tmpname()) write_file( filename, [[ @@ -1195,7 +1195,7 @@ describe('jobs', function() ]] ) - local screen = thelpers.setup_child_nvim({ + local screen = tt.setup_child_nvim({ '--cmd', 'set notermguicolors', '-i', @@ -1239,7 +1239,7 @@ describe('pty process teardown', function() skip(fn.executable('sleep') == 0, 'missing "sleep" command') -- Use a nested nvim (in :term) to test without --headless. fn.termopen({ - helpers.nvim_prog, + t.nvim_prog, '-u', 'NONE', '-i', diff --git a/test/functional/core/log_spec.lua b/test/functional/core/log_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local assert_log = helpers.assert_log -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local expect_exit = helpers.expect_exit -local request = helpers.request +local t = require('test.functional.testutil')(after_each) +local assert_log = t.assert_log +local clear = t.clear +local command = t.command +local eq = t.eq +local exec_lua = t.exec_lua +local expect_exit = t.expect_exit +local request = t.request describe('log', function() local testlog = 'Xtest_logging' diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua @@ -1,17 +1,17 @@ local uv = vim.uv -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local eq = helpers.eq -local matches = helpers.matches -local feed = helpers.feed -local eval = helpers.eval -local clear = helpers.clear -local fn = helpers.fn -local nvim_prog_abs = helpers.nvim_prog_abs -local write_file = helpers.write_file -local is_os = helpers.is_os -local skip = helpers.skip +local eq = t.eq +local matches = t.matches +local feed = t.feed +local eval = t.eval +local clear = t.clear +local fn = t.fn +local nvim_prog_abs = t.nvim_prog_abs +local write_file = t.write_file +local is_os = t.is_os +local skip = t.skip describe('command-line option', function() describe('-s', function() diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval -local feed = helpers.feed -local fn = helpers.fn -local insert = helpers.insert -local is_os = helpers.is_os -local mkdir = helpers.mkdir -local rmdir = helpers.rmdir -local write_file = helpers.write_file +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local eq = t.eq +local eval = t.eval +local feed = t.feed +local fn = t.fn +local insert = t.insert +local is_os = t.is_os +local mkdir = t.mkdir +local rmdir = t.rmdir +local write_file = t.write_file local function join_path(...) local pathsep = (is_os('win') and '\\' or '/') diff --git a/test/functional/core/remote_spec.lua b/test/functional/core/remote_spec.lua @@ -1,20 +1,20 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local exec_capture = helpers.exec_capture -local exec_lua = helpers.exec_lua -local expect = helpers.expect -local fn = helpers.fn -local insert = helpers.insert -local nvim_prog = helpers.nvim_prog -local new_argv = helpers.new_argv -local neq = helpers.neq -local set_session = helpers.set_session -local spawn = helpers.spawn -local tmpname = helpers.tmpname -local write_file = helpers.write_file +local t = require('test.functional.testutil')(after_each) + +local clear = t.clear +local command = t.command +local eq = t.eq +local exec_capture = t.exec_capture +local exec_lua = t.exec_lua +local expect = t.expect +local fn = t.fn +local insert = t.insert +local nvim_prog = t.nvim_prog +local new_argv = t.new_argv +local neq = t.neq +local set_session = t.set_session +local spawn = t.spawn +local tmpname = t.tmpname +local write_file = t.write_file describe('Remote', function() local fname, other_fname diff --git a/test/functional/core/spellfile_spec.lua b/test/functional/core/spellfile_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local clear = helpers.clear -local api = helpers.api -local exc_exec = helpers.exc_exec -local fn = helpers.fn -local rmdir = helpers.rmdir -local write_file = helpers.write_file -local mkdir = helpers.mkdir +local eq = t.eq +local clear = t.clear +local api = t.api +local exc_exec = t.exc_exec +local fn = t.fn +local rmdir = t.rmdir +local write_file = t.write_file +local mkdir = t.mkdir local testdir = 'Xtest-functional-spell-spellfile.d' diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua @@ -1,38 +1,38 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local assert_alive = helpers.assert_alive -local assert_log = helpers.assert_log -local clear = helpers.clear -local command = helpers.command -local ok = helpers.ok -local eq = helpers.eq -local matches = helpers.matches -local eval = helpers.eval -local exec = helpers.exec -local exec_capture = helpers.exec_capture -local exec_lua = helpers.exec_lua -local feed = helpers.feed -local fn = helpers.fn +local assert_alive = t.assert_alive +local assert_log = t.assert_log +local clear = t.clear +local command = t.command +local ok = t.ok +local eq = t.eq +local matches = t.matches +local eval = t.eval +local exec = t.exec +local exec_capture = t.exec_capture +local exec_lua = t.exec_lua +local feed = t.feed +local fn = t.fn local pesc = vim.pesc -local mkdir = helpers.mkdir -local mkdir_p = helpers.mkdir_p -local nvim_prog = helpers.nvim_prog -local nvim_set = helpers.nvim_set -local read_file = helpers.read_file -local retry = helpers.retry -local rmdir = helpers.rmdir +local mkdir = t.mkdir +local mkdir_p = t.mkdir_p +local nvim_prog = t.nvim_prog +local nvim_set = t.nvim_set +local read_file = t.read_file +local retry = t.retry +local rmdir = t.rmdir local sleep = vim.uv.sleep local startswith = vim.startswith -local write_file = helpers.write_file -local api = helpers.api -local alter_slashes = helpers.alter_slashes -local is_os = helpers.is_os -local dedent = helpers.dedent +local write_file = t.write_file +local api = t.api +local alter_slashes = t.alter_slashes +local is_os = t.is_os +local dedent = t.dedent local tbl_map = vim.tbl_map local tbl_filter = vim.tbl_filter local endswith = vim.endswith -local check_close = helpers.check_close +local check_close = t.check_close local testlog = 'Xtest-startupspec-log' @@ -467,7 +467,7 @@ describe('startup', function() | ]]) if not is_os('win') then - assert_log('Failed to get flags on descriptor 3: Bad file descriptor', testlog) + assert_log('Failed to get flags on descriptor 3: Bad file descriptor', testlog, 100) end end) @@ -994,7 +994,7 @@ describe('sysinit', function() local xdgdir = 'Xxdg' local vimdir = 'Xvim' local xhome = 'Xhome' - local pathsep = helpers.get_pathsep() + local pathsep = t.get_pathsep() before_each(function() rmdir(xdgdir) @@ -1055,7 +1055,7 @@ end) describe('user config init', function() local xhome = 'Xhome' - local pathsep = helpers.get_pathsep() + local pathsep = t.get_pathsep() local xconfig = xhome .. pathsep .. 'Xconfig' local xdata = xhome .. pathsep .. 'Xdata' local init_lua_path = table.concat({ xconfig, 'nvim', 'init.lua' }, pathsep) @@ -1218,7 +1218,7 @@ end) describe('runtime:', function() local xhome = 'Xhome' - local pathsep = helpers.get_pathsep() + local pathsep = t.get_pathsep() local xconfig = xhome .. pathsep .. 'Xconfig' local xdata = xhome .. pathsep .. 'Xdata' local xenv = { XDG_CONFIG_HOME = xconfig, XDG_DATA_HOME = xdata } @@ -1360,7 +1360,7 @@ end) describe('user session', function() local xhome = 'Xhome' - local pathsep = helpers.get_pathsep() + local pathsep = t.get_pathsep() local session_file = table.concat({ xhome, 'session.lua' }, pathsep) before_each(function() diff --git a/test/functional/editor/K_spec.lua b/test/functional/editor/K_spec.lua @@ -1,6 +1,5 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq, clear, eval, feed, api, retry = - helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.api, helpers.retry +local t = require('test.functional.testutil')(after_each) +local eq, clear, eval, feed, api, retry = t.eq, t.clear, t.eval, t.feed, t.api, t.retry describe('K', function() local test_file = 'K_spec_out' @@ -13,19 +12,19 @@ describe('K', function() end) it("invokes colon-prefixed 'keywordprg' as Vim command", function() - helpers.source([[ + t.source([[ let @a='fnord' set keywordprg=:put]]) -- K on the text "a" resolves to `:put a`. feed('ia<ESC>K') - helpers.expect([[ + t.expect([[ a fnord]]) end) it("invokes non-prefixed 'keywordprg' as shell command", function() - helpers.source([[ + t.source([[ let @a='fnord' set keywordprg=echo\ fnord>>]]) @@ -43,7 +42,7 @@ describe('K', function() end) it("<esc> kills the buffer for a running 'keywordprg' command", function() - helpers.source('set keywordprg=less') + t.source('set keywordprg=less') eval('writefile(["hello", "world"], "' .. test_file .. '")') feed('i' .. test_file .. '<esc>K') eq('t', eval('mode()')) @@ -57,7 +56,7 @@ describe('K', function() local bufnr = eval('bufnr()') feed('<esc>') eq('n', eval('mode()')) - helpers.neq(bufnr, eval('bufnr()')) + t.neq(bufnr, eval('bufnr()')) end) it('empty string falls back to :help #19298', function() diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local assert_alive = helpers.assert_alive -local clear, feed = helpers.clear, helpers.feed -local eval, eq, neq = helpers.eval, helpers.eq, helpers.neq -local feed_command, source, expect = helpers.feed_command, helpers.source, helpers.expect -local fn = helpers.fn -local command = helpers.command -local api = helpers.api -local poke_eventloop = helpers.poke_eventloop +local assert_alive = t.assert_alive +local clear, feed = t.clear, t.feed +local eval, eq, neq = t.eval, t.eq, t.neq +local feed_command, source, expect = t.feed_command, t.source, t.expect +local fn = t.fn +local command = t.command +local api = t.api +local poke_eventloop = t.poke_eventloop describe('completion', function() local screen diff --git a/test/functional/editor/count_spec.lua b/test/functional/editor/count_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local eval = helpers.eval -local feed = helpers.feed -local clear = helpers.clear -local command = helpers.command +local eq = t.eq +local eval = t.eval +local feed = t.feed +local clear = t.clear +local command = t.command describe('v:count/v:count1', function() before_each(function() diff --git a/test/functional/editor/ctrl_c_spec.lua b/test/functional/editor/ctrl_c_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, source = helpers.clear, helpers.feed, helpers.source -local command = helpers.command -local poke_eventloop = helpers.poke_eventloop +local clear, feed, source = t.clear, t.feed, t.source +local command = t.command +local poke_eventloop = t.poke_eventloop local sleep = vim.uv.sleep describe('CTRL-C (mapped)', function() @@ -16,7 +16,7 @@ describe('CTRL-C (mapped)', function() it('interrupts :global', function() -- Crashes luajit. - if helpers.skip_fragile(pending) then + if t.skip_fragile(pending) then return end diff --git a/test/functional/editor/fold_spec.lua b/test/functional/editor/fold_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local insert = helpers.insert -local exec = helpers.exec -local feed = helpers.feed -local expect = helpers.expect -local command = helpers.command -local fn = helpers.fn -local eq = helpers.eq -local neq = helpers.neq +local t = require('test.functional.testutil')(after_each) + +local clear = t.clear +local insert = t.insert +local exec = t.exec +local feed = t.feed +local expect = t.expect +local command = t.command +local fn = t.fn +local eq = t.eq +local neq = t.neq describe('Folding', function() local tempfname = 'Xtest-fold.txt' @@ -301,7 +301,7 @@ a]], it('updates correctly on :read', function() -- luacheck: ignore 621 - helpers.write_file( + t.write_file( tempfname, [[ a @@ -376,7 +376,7 @@ a]], end) it('splits folds according to >N and <N with foldexpr', function() - helpers.source([[ + t.source([[ function TestFoldExpr(lnum) let thisline = getline(a:lnum) if thisline == 'a' @@ -391,7 +391,7 @@ a]], return 0 endfunction ]]) - helpers.write_file( + t.write_file( tempfname, [[ b diff --git a/test/functional/editor/jump_spec.lua b/test/functional/editor/jump_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local dedent = helpers.dedent -local eq = helpers.eq -local fn = helpers.fn -local feed = helpers.feed -local exec_capture = helpers.exec_capture -local write_file = helpers.write_file -local api = helpers.api +local clear = t.clear +local command = t.command +local dedent = t.dedent +local eq = t.eq +local fn = t.fn +local feed = t.feed +local exec_capture = t.exec_capture +local write_file = t.write_file +local api = t.api describe('jumplist', function() local fname1 = 'Xtest-functional-normal-jump' diff --git a/test/functional/editor/lang_spec.lua b/test/functional/editor/lang_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, insert, eq = helpers.clear, helpers.insert, helpers.eq -local command, expect = helpers.command, helpers.expect -local feed, eval = helpers.feed, helpers.eval -local exc_exec = helpers.exc_exec +local t = require('test.functional.testutil')(after_each) +local clear, insert, eq = t.clear, t.insert, t.eq +local command, expect = t.command, t.expect +local feed, eval = t.feed, t.eval +local exc_exec = t.exc_exec describe('gu and gU', function() before_each(clear) diff --git a/test/functional/editor/langmap_spec.lua b/test/functional/editor/langmap_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq, neq, call = helpers.eq, helpers.neq, helpers.call -local eval, feed, clear = helpers.eval, helpers.feed, helpers.clear -local command, insert, expect = helpers.command, helpers.insert, helpers.expect -local feed_command = helpers.feed_command -local curwin = helpers.api.nvim_get_current_win +local eq, neq, call = t.eq, t.neq, t.call +local eval, feed, clear = t.eval, t.feed, t.clear +local command, insert, expect = t.command, t.insert, t.expect +local feed_command = t.feed_command +local curwin = t.api.nvim_get_current_win describe("'langmap'", function() before_each(function() @@ -133,7 +133,7 @@ describe("'langmap'", function() hello]]) end) it('command-line CTRL-R', function() - helpers.source([[ + t.source([[ let i_value = 0 let j_value = 0 call setreg('i', 'i_value') @@ -171,7 +171,7 @@ describe("'langmap'", function() end) it('prompt for number', function() command('set langmap=12,21') - helpers.source([[ + t.source([[ let gotten_one = 0 function Map() let answer = inputlist(['a', '1.', '2.', '3.']) @@ -214,10 +214,7 @@ describe("'langmap'", function() end feed('qa' .. command_string .. 'q') expect(expect_string) - eq( - expect_macro or helpers.fn.nvim_replace_termcodes(command_string, true, true, true), - eval('@a') - ) + eq(expect_macro or t.fn.nvim_replace_termcodes(command_string, true, true, true), eval('@a')) if setup_function then setup_function() end diff --git a/test/functional/editor/macro_spec.lua b/test/functional/editor/macro_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) - -local eq = helpers.eq -local eval = helpers.eval -local feed = helpers.feed -local clear = helpers.clear -local expect = helpers.expect -local command = helpers.command -local fn = helpers.fn -local api = helpers.api -local insert = helpers.insert +local t = require('test.functional.testutil')(after_each) + +local eq = t.eq +local eval = t.eval +local feed = t.feed +local clear = t.clear +local expect = t.expect +local command = t.command +local fn = t.fn +local api = t.api +local insert = t.insert describe('macros', function() before_each(function() diff --git a/test/functional/editor/mark_spec.lua b/test/functional/editor/mark_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local api = helpers.api -local clear = helpers.clear -local command = helpers.command -local fn = helpers.fn -local eq = helpers.eq -local feed = helpers.feed -local write_file = helpers.write_file -local pcall_err = helpers.pcall_err +local api = t.api +local clear = t.clear +local command = t.command +local fn = t.fn +local eq = t.eq +local feed = t.feed +local write_file = t.write_file +local pcall_err = t.pcall_err local cursor = function() - return helpers.api.nvim_win_get_cursor(0) + return t.api.nvim_win_get_cursor(0) end describe('named marks', function() @@ -39,59 +39,59 @@ describe('named marks', function() it('errors when set out of range with :mark', function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, '1000mark x') + local err = pcall_err(t.exec_capture, '1000mark x') eq('nvim_exec2(): Vim(mark):E16: Invalid range: 1000mark x', err) end) it('errors when set out of range with :k', function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, '1000kx') + local err = pcall_err(t.exec_capture, '1000kx') eq('nvim_exec2(): Vim(k):E16: Invalid range: 1000kx', err) end) it('errors on unknown mark name with :mark', function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, 'mark #') + local err = pcall_err(t.exec_capture, 'mark #') eq('nvim_exec2(): Vim(mark):E191: Argument must be a letter or forward/backward quote', err) end) it("errors on unknown mark name with '", function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, "normal! '#") + local err = pcall_err(t.exec_capture, "normal! '#") eq('nvim_exec2(): Vim(normal):E78: Unknown mark', err) end) it('errors on unknown mark name with `', function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, 'normal! `#') + local err = pcall_err(t.exec_capture, 'normal! `#') eq('nvim_exec2(): Vim(normal):E78: Unknown mark', err) end) it("errors when moving to a mark that is not set with '", function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, "normal! 'z") + local err = pcall_err(t.exec_capture, "normal! 'z") eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) - err = pcall_err(helpers.exec_capture, "normal! '.") + err = pcall_err(t.exec_capture, "normal! '.") eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) end) it('errors when moving to a mark that is not set with `', function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, 'normal! `z') + local err = pcall_err(t.exec_capture, 'normal! `z') eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) - err = pcall_err(helpers.exec_capture, 'normal! `>') + err = pcall_err(t.exec_capture, 'normal! `>') eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) end) it("errors when moving to a global mark that is not set with '", function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, "normal! 'Z") + local err = pcall_err(t.exec_capture, "normal! 'Z") eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) end) it('errors when moving to a global mark that is not set with `', function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, 'normal! `Z') + local err = pcall_err(t.exec_capture, 'normal! `Z') eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) end) @@ -166,7 +166,7 @@ describe('named marks', function() feed('mA') command('next') command('bw! ' .. file1) - local err = pcall_err(helpers.exec_capture, "normal! 'A") + local err = pcall_err(t.exec_capture, "normal! 'A") eq('nvim_exec2(): Vim(normal):E92: Buffer 1 not found', err) os.remove(file1) end) diff --git a/test/functional/editor/meta_key_spec.lua b/test/functional/editor/meta_key_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local command = helpers.command -local exec_lua = helpers.exec_lua -local eval = helpers.eval -local expect = helpers.expect -local fn = helpers.fn -local eq = helpers.eq +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local command = t.command +local exec_lua = t.exec_lua +local eval = t.eval +local expect = t.expect +local fn = t.fn +local eq = t.eq describe('meta-keys #8226 #13042', function() before_each(function() diff --git a/test/functional/editor/mode_cmdline_spec.lua b/test/functional/editor/mode_cmdline_spec.lua @@ -1,12 +1,11 @@ -- Cmdline-mode tests. -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, insert, fn, eq, feed = - helpers.clear, helpers.insert, helpers.fn, helpers.eq, helpers.feed -local eval = helpers.eval -local command = helpers.command -local api = helpers.api +local clear, insert, fn, eq, feed = t.clear, t.insert, t.fn, t.eq, t.feed +local eval = t.eval +local command = t.command +local api = t.api describe('cmdline', function() before_each(clear) diff --git a/test/functional/editor/mode_insert_spec.lua b/test/functional/editor/mode_insert_spec.lua @@ -1,14 +1,14 @@ -- Insert-mode tests. -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local expect = helpers.expect -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval -local curbuf_contents = helpers.curbuf_contents -local api = helpers.api +local clear, feed, insert = t.clear, t.feed, t.insert +local expect = t.expect +local command = t.command +local eq = t.eq +local eval = t.eval +local curbuf_contents = t.curbuf_contents +local api = t.api describe('insert-mode', function() before_each(function() @@ -232,10 +232,10 @@ describe('insert-mode', function() end local function test_cols(expected_cols) - local cols = { { helpers.fn.col('.'), helpers.fn.virtcol('.') } } + local cols = { { t.fn.col('.'), t.fn.virtcol('.') } } for _ = 2, #expected_cols do feed('<BS>') - table.insert(cols, { helpers.fn.col('.'), helpers.fn.virtcol('.') }) + table.insert(cols, { t.fn.col('.'), t.fn.virtcol('.') }) end eq(expected_cols, cols) end diff --git a/test/functional/editor/mode_normal_spec.lua b/test/functional/editor/mode_normal_spec.lua @@ -1,11 +1,11 @@ -- Normal mode tests. -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local feed = helpers.feed -local fn = helpers.fn -local command = helpers.command -local eq = helpers.eq +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local feed = t.feed +local fn = t.fn +local command = t.command +local eq = t.eq describe('Normal mode', function() before_each(clear) diff --git a/test/functional/editor/put_spec.lua b/test/functional/editor/put_spec.lua @@ -1,18 +1,18 @@ local Screen = require('test.functional.ui.screen') -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local insert = helpers.insert -local feed = helpers.feed -local expect = helpers.expect -local eq = helpers.eq +local clear = t.clear +local insert = t.insert +local feed = t.feed +local expect = t.expect +local eq = t.eq local map = vim.tbl_map local filter = vim.tbl_filter -local feed_command = helpers.feed_command -local command = helpers.command -local curbuf_contents = helpers.curbuf_contents -local fn = helpers.fn -local dedent = helpers.dedent +local feed_command = t.feed_command +local command = t.command +local curbuf_contents = t.curbuf_contents +local fn = t.fn +local dedent = t.dedent local function reset() command('bwipe! | new') @@ -75,7 +75,7 @@ describe('put command', function() extra_setup() end local orig_dotstr = fn.getreg('.') - helpers.ok(visual_marks_zero()) + t.ok(visual_marks_zero()) -- Make sure every test starts from the same conditions assert_no_change(test.exception_table, false) local was_cli = test.test_action() @@ -890,7 +890,7 @@ describe('put command', function() -- check bell is not set by nvim before the action screen:sleep(50) end - helpers.ok(not screen.bell and not screen.visualbell) + t.ok(not screen.bell and not screen.visualbell) actions() screen:expect { condition = function() diff --git a/test/functional/editor/search_spec.lua b/test/functional/editor/search_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local pcall_err = helpers.pcall_err +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local eq = t.eq +local pcall_err = t.pcall_err describe('search (/)', function() before_each(clear) diff --git a/test/functional/editor/tabpage_spec.lua b/test/functional/editor/tabpage_spec.lua @@ -1,17 +1,17 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local neq = helpers.neq -local feed = helpers.feed -local eval = helpers.eval -local exec = helpers.exec -local fn = helpers.fn -local api = helpers.api -local curwin = helpers.api.nvim_get_current_win -local assert_alive = helpers.assert_alive +local clear = t.clear +local command = t.command +local eq = t.eq +local neq = t.neq +local feed = t.feed +local eval = t.eval +local exec = t.exec +local fn = t.fn +local api = t.api +local curwin = t.api.nvim_get_current_win +local assert_alive = t.assert_alive describe('tabpage', function() before_each(clear) diff --git a/test/functional/editor/undo_spec.lua b/test/functional/editor/undo_spec.lua @@ -1,16 +1,16 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local command = helpers.command -local eval = helpers.eval -local expect = helpers.expect -local eq = helpers.eq -local feed = helpers.feed -local feed_command = helpers.feed_command -local insert = helpers.insert -local fn = helpers.fn -local exec = helpers.exec -local exec_lua = helpers.exec_lua +local t = require('test.functional.testutil')(after_each) + +local clear = t.clear +local command = t.command +local eval = t.eval +local expect = t.expect +local eq = t.eq +local feed = t.feed +local feed_command = t.feed_command +local insert = t.insert +local fn = t.fn +local exec = t.exec +local exec_lua = t.exec_lua local function lastmessage() local messages = fn.split(fn.execute('messages'), '\n') @@ -44,7 +44,7 @@ describe('u CTRL-R g- g+', function() local function undo_and_redo(hist_pos, undo, redo, expect_str) command('enew!') create_history(hist_pos) - local cur_contents = helpers.curbuf_contents() + local cur_contents = t.curbuf_contents() feed(undo) expect(expect_str) feed(redo) diff --git a/test/functional/ex_cmds/append_spec.lua b/test/functional/ex_cmds/append_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local dedent = helpers.dedent -local exec = helpers.exec -local feed = helpers.feed -local clear = helpers.clear -local fn = helpers.fn -local command = helpers.command -local api = helpers.api +local eq = t.eq +local dedent = t.dedent +local exec = t.exec +local feed = t.feed +local clear = t.clear +local fn = t.fn +local command = t.command +local api = t.api local Screen = require('test.functional.ui.screen') local cmdtest = function(cmd, prep, ret1) diff --git a/test/functional/ex_cmds/arg_spec.lua b/test/functional/ex_cmds/arg_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq, command, fn = helpers.eq, helpers.command, helpers.fn -local ok = helpers.ok -local matches = helpers.matches -local clear = helpers.clear +local t = require('test.functional.testutil')(after_each) +local eq, command, fn = t.eq, t.command, t.fn +local ok = t.ok +local matches = t.matches +local clear = t.clear describe(':argument', function() before_each(function() @@ -11,19 +11,19 @@ describe(':argument', function() it('does not restart :terminal buffer', function() command('terminal') - helpers.feed([[<C-\><C-N>]]) + t.feed([[<C-\><C-N>]]) command('argadd') - helpers.feed([[<C-\><C-N>]]) + t.feed([[<C-\><C-N>]]) local bufname_before = fn.bufname('%') local bufnr_before = fn.bufnr('%') matches('^term://', bufname_before) -- sanity command('argument 1') - helpers.feed([[<C-\><C-N>]]) + t.feed([[<C-\><C-N>]]) local bufname_after = fn.bufname('%') local bufnr_after = fn.bufnr('%') - eq('[' .. bufname_before .. ']', helpers.eval('trim(execute("args"))')) + eq('[' .. bufname_before .. ']', t.eval('trim(execute("args"))')) ok(fn.line('$') > 1) eq(bufname_before, bufname_after) eq(bufnr_before, bufnr_after) diff --git a/test/functional/ex_cmds/cd_spec.lua b/test/functional/ex_cmds/cd_spec.lua @@ -1,16 +1,16 @@ -- Specs for :cd, :tcd, :lcd and getcwd() -local helpers = require('test.functional.helpers')(after_each) - -local eq = helpers.eq -local call = helpers.call -local clear = helpers.clear -local command = helpers.command -local exc_exec = helpers.exc_exec -local pathsep = helpers.get_pathsep() -local skip = helpers.skip -local is_os = helpers.is_os -local mkdir = helpers.mkdir +local t = require('test.functional.testutil')(after_each) + +local eq = t.eq +local call = t.call +local clear = t.clear +local command = t.command +local exc_exec = t.exc_exec +local pathsep = t.get_pathsep() +local skip = t.skip +local is_os = t.is_os +local mkdir = t.mkdir -- These directories will be created for testing local directories = { @@ -289,14 +289,14 @@ describe('getcwd()', function() end) after_each(function() - helpers.rmdir(directories.global) + t.rmdir(directories.global) end) it('returns empty string if working directory does not exist', function() skip(is_os('win')) command('cd ' .. directories.global) command("call delete('../" .. directories.global .. "', 'd')") - eq('', helpers.eval('getcwd()')) + eq('', t.eval('getcwd()')) end) it("works with 'autochdir' after local directory was set (#9892)", function() diff --git a/test/functional/ex_cmds/cmd_map_spec.lua b/test/functional/ex_cmds/cmd_map_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local feed = helpers.feed -local eq = helpers.eq -local expect = helpers.expect -local eval = helpers.eval -local fn = helpers.fn -local insert = helpers.insert -local write_file = helpers.write_file -local exc_exec = helpers.exc_exec -local command = helpers.command +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local feed = t.feed +local eq = t.eq +local expect = t.expect +local eval = t.eval +local fn = t.fn +local insert = t.insert +local write_file = t.write_file +local exc_exec = t.exc_exec +local command = t.command local Screen = require('test.functional.ui.screen') describe('mappings with <Cmd>', function() diff --git a/test/functional/ex_cmds/debug_spec.lua b/test/functional/ex_cmds/debug_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local feed = helpers.feed -local clear = helpers.clear +local feed = t.feed +local clear = t.clear describe(':debug', function() local screen diff --git a/test/functional/ex_cmds/dict_notifications_spec.lua b/test/functional/ex_cmds/dict_notifications_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) -local assert_alive = helpers.assert_alive -local clear, source = helpers.clear, helpers.source -local api = helpers.api -local insert = helpers.insert -local eq, next_msg = helpers.eq, helpers.next_msg -local exc_exec = helpers.exc_exec -local exec_lua = helpers.exec_lua -local command = helpers.command -local eval = helpers.eval +local t = require('test.functional.testutil')(after_each) +local assert_alive = t.assert_alive +local clear, source = t.clear, t.source +local api = t.api +local insert = t.insert +local eq, next_msg = t.eq, t.next_msg +local exc_exec = t.exc_exec +local exec_lua = t.exec_lua +local command = t.command +local eval = t.eval describe('Vimscript dictionary notifications', function() local channel diff --git a/test/functional/ex_cmds/digraphs_spec.lua b/test/functional/ex_cmds/digraphs_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local feed = helpers.feed +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local feed = t.feed local Screen = require('test.functional.ui.screen') describe(':digraphs', function() diff --git a/test/functional/ex_cmds/drop_spec.lua b/test/functional/ex_cmds/drop_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local command = helpers.command +local t = require('test.functional.testutil')(after_each) +local command = t.command local Screen = require('test.functional.ui.screen') -local clear, feed, feed_command = helpers.clear, helpers.feed, helpers.feed_command -local exec = helpers.exec +local clear, feed, feed_command = t.clear, t.feed, t.feed_command +local exec = t.exec describe(':drop', function() local screen diff --git a/test/functional/ex_cmds/echo_spec.lua b/test/functional/ex_cmds/echo_spec.lua @@ -1,17 +1,17 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq +local eq = t.eq local NIL = vim.NIL -local eval = helpers.eval -local clear = helpers.clear -local api = helpers.api -local fn = helpers.fn -local source = helpers.source -local dedent = helpers.dedent -local command = helpers.command -local exc_exec = helpers.exc_exec -local exec_capture = helpers.exec_capture -local matches = helpers.matches +local eval = t.eval +local clear = t.clear +local api = t.api +local fn = t.fn +local source = t.source +local dedent = t.dedent +local command = t.command +local exc_exec = t.exc_exec +local exec_capture = t.exec_capture +local matches = t.matches describe(':echo :echon :echomsg :echoerr', function() local fn_tbl = { 'String', 'StringN', 'StringMsg', 'StringErr' } @@ -255,7 +255,7 @@ describe(':echo :echon :echomsg :echoerr', function() eval('add(l, l)') -- Regression: the below line used to crash (add returns original list and -- there was error in dumping partials). Tested explicitly in - -- test/unit/api/private_helpers_spec.lua. + -- test/unit/api/private_t_spec.lua. eval('add(l, function("Test1", l))') eq( dedent( diff --git a/test/functional/ex_cmds/edit_spec.lua b/test/functional/ex_cmds/edit_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq, command, fn = helpers.eq, helpers.command, helpers.fn -local ok = helpers.ok -local matches = helpers.matches -local clear = helpers.clear -local feed = helpers.feed +local t = require('test.functional.testutil')(after_each) +local eq, command, fn = t.eq, t.command, t.fn +local ok = t.ok +local matches = t.matches +local clear = t.clear +local feed = t.feed describe(':edit', function() before_each(function() diff --git a/test/functional/ex_cmds/encoding_spec.lua b/test/functional/ex_cmds/encoding_spec.lua @@ -1,6 +1,6 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, feed_command, feed = helpers.clear, helpers.feed_command, helpers.feed -local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval +local t = require('test.functional.testutil')(after_each) +local clear, feed_command, feed = t.clear, t.feed_command, t.feed +local eq, neq, eval = t.eq, t.neq, t.eval describe('&encoding', function() before_each(function() diff --git a/test/functional/ex_cmds/excmd_spec.lua b/test/functional/ex_cmds/excmd_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) -local command = helpers.command -local eq = helpers.eq -local clear = helpers.clear -local fn = helpers.fn -local pcall_err = helpers.pcall_err -local assert_alive = helpers.assert_alive +local t = require('test.functional.testutil')(after_each) +local command = t.command +local eq = t.eq +local clear = t.clear +local fn = t.fn +local pcall_err = t.pcall_err +local assert_alive = t.assert_alive describe('Ex cmds', function() before_each(function() diff --git a/test/functional/ex_cmds/file_spec.lua b/test/functional/ex_cmds/file_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local fn = helpers.fn -local rmdir = helpers.rmdir -local mkdir = helpers.mkdir +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local eq = t.eq +local fn = t.fn +local rmdir = t.rmdir +local mkdir = t.mkdir describe(':file', function() local swapdir = vim.uv.cwd() .. '/Xtest-file_spec' diff --git a/test/functional/ex_cmds/grep_spec.lua b/test/functional/ex_cmds/grep_spec.lua @@ -1,6 +1,5 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, feed_command, feed, ok, eval = - helpers.clear, helpers.feed_command, helpers.feed, helpers.ok, helpers.eval +local t = require('test.functional.testutil')(after_each) +local clear, feed_command, feed, ok, eval = t.clear, t.feed_command, t.feed, t.ok, t.eval describe(':grep', function() before_each(clear) diff --git a/test/functional/ex_cmds/help_spec.lua b/test/functional/ex_cmds/help_spec.lua @@ -1,19 +1,19 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local fn = helpers.fn -local api = helpers.api -local mkdir = helpers.mkdir -local rmdir = helpers.rmdir -local write_file = helpers.write_file +local clear = t.clear +local command = t.command +local eq = t.eq +local fn = t.fn +local api = t.api +local mkdir = t.mkdir +local rmdir = t.rmdir +local write_file = t.write_file describe(':help', function() before_each(clear) it('window closed makes cursor return to a valid win/buf #9773', function() - helpers.add_builddir_to_rtp() + t.add_builddir_to_rtp() command('help help') eq(1001, fn.win_getid()) command('quit') diff --git a/test/functional/ex_cmds/highlight_spec.lua b/test/functional/ex_cmds/highlight_spec.lua @@ -1,11 +1,11 @@ local Screen = require('test.functional.ui.screen') -local helpers = require('test.functional.helpers')(after_each) -local eq, command = helpers.eq, helpers.command -local clear = helpers.clear -local eval, exc_exec = helpers.eval, helpers.exc_exec -local exec = helpers.exec -local fn = helpers.fn -local api = helpers.api +local t = require('test.functional.testutil')(after_each) +local eq, command = t.eq, t.command +local clear = t.clear +local eval, exc_exec = t.eval, t.exc_exec +local exec = t.exec +local fn = t.fn +local api = t.api describe(':highlight', function() local screen diff --git a/test/functional/ex_cmds/ls_spec.lua b/test/functional/ex_cmds/ls_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval -local feed = helpers.feed -local api = helpers.api -local testprg = helpers.testprg -local retry = helpers.retry +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local eq = t.eq +local eval = t.eval +local feed = t.feed +local api = t.api +local testprg = t.testprg +local retry = t.retry describe(':ls', function() before_each(function() diff --git a/test/functional/ex_cmds/make_spec.lua b/test/functional/ex_cmds/make_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eval = helpers.eval -local has_powershell = helpers.has_powershell -local matches = helpers.matches -local api = helpers.api -local testprg = helpers.testprg +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eval = t.eval +local has_powershell = t.has_powershell +local matches = t.matches +local api = t.api +local testprg = t.testprg describe(':make', function() clear() @@ -18,7 +18,7 @@ describe(':make', function() return end before_each(function() - helpers.set_shell_powershell() + t.set_shell_powershell() end) it('captures stderr & non zero exit code #14349', function() diff --git a/test/functional/ex_cmds/map_spec.lua b/test/functional/ex_cmds/map_spec.lua @@ -1,16 +1,16 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local eq = helpers.eq -local exec = helpers.exec -local exec_capture = helpers.exec_capture -local feed = helpers.feed -local api = helpers.api -local clear = helpers.clear -local command = helpers.command -local expect = helpers.expect -local insert = helpers.insert -local eval = helpers.eval +local eq = t.eq +local exec = t.exec +local exec_capture = t.exec_capture +local feed = t.feed +local api = t.api +local clear = t.clear +local command = t.command +local expect = t.expect +local insert = t.insert +local eval = t.eval describe(':*map', function() before_each(clear) diff --git a/test/functional/ex_cmds/menu_spec.lua b/test/functional/ex_cmds/menu_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, command = helpers.clear, helpers.command -local expect, feed = helpers.expect, helpers.feed -local eq, eval = helpers.eq, helpers.eval -local fn = helpers.fn +local t = require('test.functional.testutil')(after_each) +local clear, command = t.clear, t.command +local expect, feed = t.expect, t.feed +local eq, eval = t.eq, t.eval +local fn = t.fn describe(':emenu', function() before_each(function() diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua @@ -1,20 +1,20 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local get_pathsep = helpers.get_pathsep -local eq = helpers.eq -local neq = helpers.neq -local fn = helpers.fn -local matches = helpers.matches +local clear = t.clear +local command = t.command +local get_pathsep = t.get_pathsep +local eq = t.eq +local neq = t.neq +local fn = t.fn +local matches = t.matches local pesc = vim.pesc -local rmdir = helpers.rmdir +local rmdir = t.rmdir local sleep = vim.uv.sleep -local api = helpers.api -local skip = helpers.skip -local is_os = helpers.is_os -local mkdir = helpers.mkdir +local api = t.api +local skip = t.skip +local is_os = t.is_os +local mkdir = t.mkdir local file_prefix = 'Xtest-functional-ex_cmds-mksession_spec' diff --git a/test/functional/ex_cmds/mkview_spec.lua b/test/functional/ex_cmds/mkview_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local command = helpers.command -local get_pathsep = helpers.get_pathsep -local eq = helpers.eq -local fn = helpers.fn -local rmdir = helpers.rmdir -local mkdir = helpers.mkdir +local clear = t.clear +local command = t.command +local get_pathsep = t.get_pathsep +local eq = t.eq +local fn = t.fn +local rmdir = t.rmdir +local mkdir = t.mkdir local file_prefix = 'Xtest-functional-ex_cmds-mkview_spec' diff --git a/test/functional/ex_cmds/normal_spec.lua b/test/functional/ex_cmds/normal_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local fn = helpers.fn -local feed = helpers.feed -local expect = helpers.expect -local eq = helpers.eq -local eval = helpers.eval +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local fn = t.fn +local feed = t.feed +local expect = t.expect +local eq = t.eq +local eval = t.eval before_each(clear) diff --git a/test/functional/ex_cmds/oldfiles_spec.lua b/test/functional/ex_cmds/oldfiles_spec.lua @@ -1,13 +1,13 @@ local Screen = require('test.functional.ui.screen') -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local command = helpers.command -local expect_exit = helpers.expect_exit -local api, eq, feed_command = helpers.api, helpers.eq, helpers.feed_command -local feed, poke_eventloop = helpers.feed, helpers.poke_eventloop -local ok = helpers.ok -local eval = helpers.eval +local clear = t.clear +local command = t.command +local expect_exit = t.expect_exit +local api, eq, feed_command = t.api, t.eq, t.feed_command +local feed, poke_eventloop = t.feed, t.poke_eventloop +local ok = t.ok +local eval = t.eval local shada_file = 'Xtest.shada' @@ -66,12 +66,12 @@ describe(':oldfiles', function() feed_command('rshada!') local function get_oldfiles(cmd) - local t = eval([[split(execute(']] .. cmd .. [['), "\n")]]) - for i, _ in ipairs(t) do - t[i] = t[i]:gsub('^%d+:%s+', '') + local q = eval([[split(execute(']] .. cmd .. [['), "\n")]]) + for i, _ in ipairs(q) do + q[i] = q[i]:gsub('^%d+:%s+', '') end - table.sort(t) - return t + table.sort(q) + return q end local oldfiles = get_oldfiles('oldfiles') @@ -109,7 +109,7 @@ describe(':browse oldfiles', function() -- Ensure v:oldfiles isn't busted. Since things happen so fast, -- the ordering of v:oldfiles is unstable (it uses qsort() under-the-hood). -- Let's verify the contents and the length of v:oldfiles before moving on. - oldfiles = helpers.api.nvim_get_vvar('oldfiles') + oldfiles = t.api.nvim_get_vvar('oldfiles') eq(2, #oldfiles) ok(filename == oldfiles[1] or filename == oldfiles[2]) ok(filename2 == oldfiles[1] or filename2 == oldfiles[2]) diff --git a/test/functional/ex_cmds/print_commands_spec.lua b/test/functional/ex_cmds/print_commands_spec.lua @@ -1,5 +1,5 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, eq, command, fn = helpers.clear, helpers.eq, helpers.command, helpers.fn +local t = require('test.functional.testutil')(after_each) +local clear, eq, command, fn = t.clear, t.eq, t.command, t.fn describe(':z^', function() before_each(clear) diff --git a/test/functional/ex_cmds/profile_spec.lua b/test/functional/ex_cmds/profile_spec.lua @@ -1,14 +1,14 @@ require('os') local uv = vim.uv -local helpers = require('test.functional.helpers')(after_each) -local eval = helpers.eval -local command = helpers.command -local eq, neq = helpers.eq, helpers.neq -local tempfile = helpers.tmpname() -local source = helpers.source -local matches = helpers.matches -local read_file = helpers.read_file +local t = require('test.functional.testutil')(after_each) +local eval = t.eval +local command = t.command +local eq, neq = t.eq, t.neq +local tempfile = t.tmpname() +local source = t.source +local matches = t.matches +local read_file = t.read_file -- tmpname() also creates the file on POSIX systems. Remove it again. -- We just need the name, ignoring any race conditions. @@ -25,10 +25,10 @@ local function assert_file_exists_not(filepath) end describe(':profile', function() - before_each(helpers.clear) + before_each(t.clear) after_each(function() - helpers.expect_exit(command, 'qall!') + t.expect_exit(command, 'qall!') if uv.fs_stat(tempfile).uid ~= nil then os.remove(tempfile) end diff --git a/test/functional/ex_cmds/quickfix_commands_spec.lua b/test/functional/ex_cmds/quickfix_commands_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local feed = helpers.feed -local eq = helpers.eq -local clear = helpers.clear -local fn = helpers.fn -local command = helpers.command -local exc_exec = helpers.exc_exec -local write_file = helpers.write_file -local api = helpers.api -local source = helpers.source +local feed = t.feed +local eq = t.eq +local clear = t.clear +local fn = t.fn +local command = t.command +local exc_exec = t.exc_exec +local write_file = t.write_file +local api = t.api +local source = t.source local file_base = 'Xtest-functional-ex_cmds-quickfix_commands' diff --git a/test/functional/ex_cmds/quit_spec.lua b/test/functional/ex_cmds/quit_spec.lua @@ -1,5 +1,5 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear +local t = require('test.functional.testutil')(after_each) +local clear = t.clear describe(':qa', function() before_each(function() diff --git a/test/functional/ex_cmds/script_spec.lua b/test/functional/ex_cmds/script_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local neq = helpers.neq -local command = helpers.command -local exec_capture = helpers.exec_capture -local write_file = helpers.write_file -local api = helpers.api -local clear = helpers.clear -local dedent = helpers.dedent -local exc_exec = helpers.exc_exec -local missing_provider = helpers.missing_provider +local eq = t.eq +local neq = t.neq +local command = t.command +local exec_capture = t.exec_capture +local write_file = t.write_file +local api = t.api +local clear = t.clear +local dedent = t.dedent +local exc_exec = t.exc_exec +local missing_provider = t.missing_provider local tmpfile = 'X_ex_cmds_script' diff --git a/test/functional/ex_cmds/sign_spec.lua b/test/functional/ex_cmds/sign_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, eq, assert_alive = helpers.clear, helpers.eq, helpers.assert_alive -local command = helpers.command -local api = helpers.api +local t = require('test.functional.testutil')(after_each) +local clear, eq, assert_alive = t.clear, t.eq, t.assert_alive +local command = t.command +local api = t.api describe('sign', function() before_each(clear) diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua @@ -1,23 +1,23 @@ -local helpers = require('test.functional.helpers')(after_each) -local command = helpers.command -local insert = helpers.insert -local eq = helpers.eq -local clear = helpers.clear -local api = helpers.api -local feed = helpers.feed -local feed_command = helpers.feed_command -local write_file = helpers.write_file -local tmpname = helpers.tmpname -local exec = helpers.exec -local exc_exec = helpers.exc_exec -local exec_lua = helpers.exec_lua -local eval = helpers.eval -local exec_capture = helpers.exec_capture -local neq = helpers.neq -local matches = helpers.matches -local mkdir = helpers.mkdir -local rmdir = helpers.rmdir -local is_os = helpers.is_os +local t = require('test.functional.testutil')(after_each) +local command = t.command +local insert = t.insert +local eq = t.eq +local clear = t.clear +local api = t.api +local feed = t.feed +local feed_command = t.feed_command +local write_file = t.write_file +local tmpname = t.tmpname +local exec = t.exec +local exc_exec = t.exc_exec +local exec_lua = t.exec_lua +local eval = t.eval +local exec_capture = t.exec_capture +local neq = t.neq +local matches = t.matches +local mkdir = t.mkdir +local rmdir = t.rmdir +local is_os = t.is_os describe(':source', function() before_each(function() diff --git a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua @@ -1,29 +1,29 @@ local Screen = require('test.functional.ui.screen') -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local uv = vim.uv -local eq, eval, expect, exec = helpers.eq, helpers.eval, helpers.expect, helpers.exec -local assert_alive = helpers.assert_alive -local clear = helpers.clear -local command = helpers.command -local feed = helpers.feed -local fn = helpers.fn -local nvim_prog = helpers.nvim_prog -local ok = helpers.ok -local rmdir = helpers.rmdir -local new_argv = helpers.new_argv -local new_pipename = helpers.new_pipename +local eq, eval, expect, exec = t.eq, t.eval, t.expect, t.exec +local assert_alive = t.assert_alive +local clear = t.clear +local command = t.command +local feed = t.feed +local fn = t.fn +local nvim_prog = t.nvim_prog +local ok = t.ok +local rmdir = t.rmdir +local new_argv = t.new_argv +local new_pipename = t.new_pipename local pesc = vim.pesc -local os_kill = helpers.os_kill -local set_session = helpers.set_session -local spawn = helpers.spawn -local async_meths = helpers.async_meths -local expect_msg_seq = helpers.expect_msg_seq -local pcall_err = helpers.pcall_err -local mkdir = helpers.mkdir -local poke_eventloop = helpers.poke_eventloop -local api = helpers.api -local retry = helpers.retry -local write_file = helpers.write_file +local os_kill = t.os_kill +local set_session = t.set_session +local spawn = t.spawn +local async_meths = t.async_meths +local expect_msg_seq = t.expect_msg_seq +local pcall_err = t.pcall_err +local mkdir = t.mkdir +local poke_eventloop = t.poke_eventloop +local api = t.api +local retry = t.retry +local write_file = t.write_file describe(':recover', function() before_each(clear) @@ -110,7 +110,7 @@ describe("preserve and (R)ecover with custom 'directory'", function() end) it('killing TUI process without :preserve #22096', function() - helpers.skip(helpers.is_os('win')) + t.skip(t.is_os('win')) local screen0 = Screen.new() screen0:attach() local child_server = new_pipename() @@ -118,7 +118,7 @@ describe("preserve and (R)ecover with custom 'directory'", function() env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, }) screen0:expect({ any = pesc('[No Name]') }) -- Wait for the child process to start. - local child_session = helpers.connect(child_server) + local child_session = t.connect(child_server) set_session(child_session) local swappath1 = setup_swapname() set_session(nvim0) diff --git a/test/functional/ex_cmds/syntax_spec.lua b/test/functional/ex_cmds/syntax_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local clear = helpers.clear -local exc_exec = helpers.exc_exec +local eq = t.eq +local clear = t.clear +local exc_exec = t.exc_exec describe(':syntax', function() before_each(clear) diff --git a/test/functional/ex_cmds/trust_spec.lua b/test/functional/ex_cmds/trust_spec.lua @@ -1,27 +1,27 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local clear = helpers.clear -local command = helpers.command -local exec_capture = helpers.exec_capture -local matches = helpers.matches -local pathsep = helpers.get_pathsep() -local is_os = helpers.is_os -local fn = helpers.fn +local eq = t.eq +local clear = t.clear +local command = t.command +local exec_capture = t.exec_capture +local matches = t.matches +local pathsep = t.get_pathsep() +local is_os = t.is_os +local fn = t.fn describe(':trust', function() local xstate = 'Xstate' setup(function() - helpers.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) + t.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) end) teardown(function() - helpers.rmdir(xstate) + t.rmdir(xstate) end) before_each(function() - helpers.write_file('test_file', 'test') + t.write_file('test_file', 'test') clear { env = { XDG_STATE_HOME = xstate } } end) @@ -31,37 +31,37 @@ describe(':trust', function() it('trust then deny then remove a file using current buffer', function() local cwd = fn.getcwd() - local hash = fn.sha256(helpers.read_file('test_file')) + local hash = fn.sha256(t.read_file('test_file')) command('edit test_file') matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust')) - local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') + local trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny')) - trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') + trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove')) - trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') + trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) it('deny then trust then remove a file using current buffer', function() local cwd = fn.getcwd() - local hash = fn.sha256(helpers.read_file('test_file')) + local hash = fn.sha256(t.read_file('test_file')) command('edit test_file') matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny')) - local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') + local trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust')) - trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') + trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove')) - trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') + trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) @@ -69,14 +69,14 @@ describe(':trust', function() local cwd = fn.getcwd() matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny test_file')) - local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') + local trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) matches( '^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove test_file') ) - trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') + trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) end) diff --git a/test/functional/ex_cmds/undojoin_spec.lua b/test/functional/ex_cmds/undojoin_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local clear = helpers.clear -local insert = helpers.insert -local feed = helpers.feed -local expect = helpers.expect -local feed_command = helpers.feed_command -local exc_exec = helpers.exc_exec +local eq = t.eq +local clear = t.clear +local insert = t.insert +local feed = t.feed +local expect = t.expect +local feed_command = t.feed_command +local exc_exec = t.exc_exec describe(':undojoin command', function() before_each(function() diff --git a/test/functional/ex_cmds/verbose_spec.lua b/test/functional/ex_cmds/verbose_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local exec = helpers.exec -local exec_capture = helpers.exec_capture -local write_file = helpers.write_file -local call_viml_function = helpers.api.nvim_call_function +local clear = t.clear +local eq = t.eq +local exec = t.exec +local exec_capture = t.exec_capture +local write_file = t.write_file +local call_viml_function = t.api.nvim_call_function local function last_set_tests(cmd) local script_location, script_file @@ -15,7 +15,7 @@ local function last_set_tests(cmd) script_file = 'test_verbose.lua' local current_dir = call_viml_function('getcwd', {}) current_dir = call_viml_function('fnamemodify', { current_dir, ':~' }) - script_location = table.concat { current_dir, helpers.get_pathsep(), script_file } + script_location = table.concat { current_dir, t.get_pathsep(), script_file } write_file( script_file, diff --git a/test/functional/ex_cmds/wincmd_spec.lua b/test/functional/ex_cmds/wincmd_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local fn = helpers.fn -local command = helpers.command +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eq = t.eq +local fn = t.fn +local command = t.command it(':wincmd accepts a count', function() clear() diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local eq, eval, clear, write_file, source, insert = - helpers.eq, helpers.eval, helpers.clear, helpers.write_file, helpers.source, helpers.insert -local pcall_err = helpers.pcall_err -local command = helpers.command -local feed_command = helpers.feed_command -local fn = helpers.fn -local api = helpers.api -local skip = helpers.skip -local is_os = helpers.is_os -local is_ci = helpers.is_ci + t.eq, t.eval, t.clear, t.write_file, t.source, t.insert +local pcall_err = t.pcall_err +local command = t.command +local feed_command = t.feed_command +local fn = t.fn +local api = t.api +local skip = t.skip +local is_os = t.is_os +local is_ci = t.is_ci local fname = 'Xtest-functional-ex_cmds-write' local fname_bak = fname .. '~' diff --git a/test/functional/ex_cmds/wundo_spec.lua b/test/functional/ex_cmds/wundo_spec.lua @@ -1,13 +1,8 @@ -- Specs for :wundo and underlying functions -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local command, clear, eval, spawn, nvim_prog, set_session = - helpers.command, - helpers.clear, - helpers.eval, - helpers.spawn, - helpers.nvim_prog, - helpers.set_session + t.command, t.clear, t.eval, t.spawn, t.nvim_prog, t.set_session describe(':wundo', function() before_each(clear) diff --git a/test/functional/ex_cmds/wviminfo_spec.lua b/test/functional/ex_cmds/wviminfo_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command, eq, neq, write_file = helpers.command, helpers.eq, helpers.neq, helpers.write_file -local read_file = helpers.read_file -local is_os = helpers.is_os +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command, eq, neq, write_file = t.command, t.eq, t.neq, t.write_file +local read_file = t.read_file +local is_os = t.is_os describe(':wshada', function() local shada_file = 'wshada_test' diff --git a/test/functional/example_spec.lua b/test/functional/example_spec.lua @@ -1,12 +1,12 @@ -- To run this test: -- TEST_FILE=test/functional/example_spec.lua make functionaltest -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local feed = helpers.feed +local clear = t.clear +local command = t.command +local eq = t.eq +local feed = t.feed describe('example', function() local screen diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua @@ -1,1042 +0,0 @@ -local uv = vim.uv -local global_helpers = require('test.helpers') - -local Session = require('test.client.session') -local uv_stream = require('test.client.uv_stream') -local SocketStream = uv_stream.SocketStream -local ChildProcessStream = uv_stream.ChildProcessStream - -local check_cores = global_helpers.check_cores -local check_logs = global_helpers.check_logs -local dedent = global_helpers.dedent -local eq = global_helpers.eq -local is_os = global_helpers.is_os -local ok = global_helpers.ok -local sleep = uv.sleep -local fail = global_helpers.fail - ---- @class test.functional.helpers: test.helpers -local module = vim.deepcopy(global_helpers) - -local runtime_set = 'set runtimepath^=./build/lib/nvim/' -module.nvim_prog = (os.getenv('NVIM_PRG') or global_helpers.paths.test_build_dir .. '/bin/nvim') --- Default settings for the test session. -module.nvim_set = ( - 'set shortmess+=IS background=light termguicolors noswapfile noautoindent startofline' - .. ' laststatus=1 undodir=. directory=. viewdir=. backupdir=.' - .. ' belloff= wildoptions-=pum joinspaces noshowcmd noruler nomore redrawdebug=invalid' -) -module.nvim_argv = { - module.nvim_prog, - '-u', - 'NONE', - '-i', - 'NONE', - -- XXX: find treesitter parsers. - '--cmd', - runtime_set, - '--cmd', - module.nvim_set, - -- Remove default user commands and mappings. - '--cmd', - 'comclear | mapclear | mapclear!', - -- Make screentest work after changing to the new default color scheme - -- Source 'vim' color scheme without side effects - -- TODO: rewrite tests - '--cmd', - 'lua dofile("runtime/colors/vim.lua")', - '--cmd', - 'unlet g:colors_name', - '--embed', -} - --- Directory containing nvim. -module.nvim_dir = module.nvim_prog:gsub('[/\\][^/\\]+$', '') -if module.nvim_dir == module.nvim_prog then - module.nvim_dir = '.' -end - -local prepend_argv --- @type string[]? - -if os.getenv('VALGRIND') then - local log_file = os.getenv('VALGRIND_LOG') or 'valgrind-%p.log' - prepend_argv = { - 'valgrind', - '-q', - '--tool=memcheck', - '--leak-check=yes', - '--track-origins=yes', - '--show-possibly-lost=no', - '--suppressions=src/.valgrind.supp', - '--log-file=' .. log_file, - } - if os.getenv('GDB') then - table.insert(prepend_argv, '--vgdb=yes') - table.insert(prepend_argv, '--vgdb-error=0') - end -elseif os.getenv('GDB') then - local gdbserver_port = os.getenv('GDBSERVER_PORT') or '7777' - prepend_argv = { 'gdbserver', 'localhost:' .. gdbserver_port } -end - -if prepend_argv then - local new_nvim_argv = {} --- @type string[] - local len = #prepend_argv - for i = 1, len do - new_nvim_argv[i] = prepend_argv[i] - end - for i = 1, #module.nvim_argv do - new_nvim_argv[i + len] = module.nvim_argv[i] - end - module.nvim_argv = new_nvim_argv - module.prepend_argv = prepend_argv -end - -local session --- @type test.Session? -local loop_running --- @type boolean? -local last_error --- @type string? -local method_error --- @type string? - -if not is_os('win') then - local sigpipe_handler = assert(uv.new_signal()) - uv.signal_start(sigpipe_handler, 'sigpipe', function() - print('warning: got SIGPIPE signal. Likely related to a crash in nvim') - end) -end - -function module.get_session() - return session -end - -function module.set_session(s) - session = s -end - ---- @param method string ---- @param ... any ---- @return any -function module.request(method, ...) - assert(session) - local status, rv = session:request(method, ...) - if not status then - if loop_running then - --- @type string - last_error = rv[2] - session:stop() - else - error(rv[2]) - end - end - return rv -end - ---- @param method string ---- @param ... any ---- @return any -function module.request_lua(method, ...) - return module.exec_lua([[return vim.api[...](select(2, ...))]], method, ...) -end - ---- @param timeout? integer ---- @return string? -function module.next_msg(timeout) - assert(session) - return session:next_message(timeout or 10000) -end - -function module.expect_twostreams(msgs1, msgs2) - local pos1, pos2 = 1, 1 - while pos1 <= #msgs1 or pos2 <= #msgs2 do - local msg = module.next_msg() - if pos1 <= #msgs1 and pcall(eq, msgs1[pos1], msg) then - pos1 = pos1 + 1 - elseif pos2 <= #msgs2 then - eq(msgs2[pos2], msg) - pos2 = pos2 + 1 - else - -- already failed, but show the right error message - eq(msgs1[pos1], msg) - end - end -end - --- Expects a sequence of next_msg() results. If multiple sequences are --- passed they are tried until one succeeds, in order of shortest to longest. --- --- Can be called with positional args (list of sequences only): --- expect_msg_seq(seq1, seq2, ...) --- or keyword args: --- expect_msg_seq{ignore={...}, seqs={seq1, seq2, ...}} --- --- ignore: List of ignored event names. --- seqs: List of one or more potential event sequences. -function module.expect_msg_seq(...) - if select('#', ...) < 1 then - error('need at least 1 argument') - end - local arg1 = select(1, ...) - if (arg1['seqs'] and select('#', ...) > 1) or type(arg1) ~= 'table' then - error('invalid args') - end - local ignore = arg1['ignore'] and arg1['ignore'] or {} - --- @type string[] - local seqs = arg1['seqs'] and arg1['seqs'] or { ... } - if type(ignore) ~= 'table' then - error("'ignore' arg must be a list of strings") - end - table.sort(seqs, function(a, b) -- Sort ascending, by (shallow) length. - return #a < #b - end) - - local actual_seq = {} - local nr_ignored = 0 - local final_error = '' - local function cat_err(err1, err2) - if err1 == nil then - return err2 - end - return string.format('%s\n%s\n%s', err1, string.rep('=', 78), err2) - end - local msg_timeout = module.load_adjust(10000) -- Big timeout for ASAN/valgrind. - for anum = 1, #seqs do - local expected_seq = seqs[anum] - -- Collect enough messages to compare the next expected sequence. - while #actual_seq < #expected_seq do - local msg = module.next_msg(msg_timeout) - local msg_type = msg and msg[2] or nil - if msg == nil then - error( - cat_err( - final_error, - string.format( - 'got %d messages (ignored %d), expected %d', - #actual_seq, - nr_ignored, - #expected_seq - ) - ) - ) - elseif vim.tbl_contains(ignore, msg_type) then - nr_ignored = nr_ignored + 1 - else - table.insert(actual_seq, msg) - end - end - local status, result = pcall(eq, expected_seq, actual_seq) - if status then - return result - end - local message = result - if type(result) == 'table' then - -- 'eq' returns several things - --- @type string - message = result.message - end - final_error = cat_err(final_error, message) - end - error(final_error) -end - -local function call_and_stop_on_error(lsession, ...) - local status, result = Session.safe_pcall(...) -- luacheck: ignore - if not status then - lsession:stop() - last_error = result - return '' - end - return result -end - -function module.set_method_error(err) - method_error = err -end - ---- @param lsession test.Session ---- @param request_cb function? ---- @param notification_cb function? ---- @param setup_cb function? ---- @param timeout integer ---- @return {[1]: integer, [2]: string} -function module.run_session(lsession, request_cb, notification_cb, setup_cb, timeout) - local on_request --- @type function? - local on_notification --- @type function? - local on_setup --- @type function? - - if request_cb then - function on_request(method, args) - method_error = nil - local result = call_and_stop_on_error(lsession, request_cb, method, args) - if method_error ~= nil then - return method_error, true - end - return result - end - end - - if notification_cb then - function on_notification(method, args) - call_and_stop_on_error(lsession, notification_cb, method, args) - end - end - - if setup_cb then - function on_setup() - call_and_stop_on_error(lsession, setup_cb) - end - end - - loop_running = true - lsession:run(on_request, on_notification, on_setup, timeout) - loop_running = false - if last_error then - local err = last_error - last_error = nil - error(err) - end - - return lsession.eof_err -end - -function module.run(request_cb, notification_cb, setup_cb, timeout) - assert(session) - return module.run_session(session, request_cb, notification_cb, setup_cb, timeout) -end - -function module.stop() - assert(session):stop() -end - -function module.nvim_prog_abs() - -- system(['build/bin/nvim']) does not work for whatever reason. It must - -- be executable searched in $PATH or something starting with / or ./. - if module.nvim_prog:match('[/\\]') then - return module.request('nvim_call_function', 'fnamemodify', { module.nvim_prog, ':p' }) - else - return module.nvim_prog - end -end - --- Use for commands which expect nvim to quit. --- The first argument can also be a timeout. -function module.expect_exit(fn_or_timeout, ...) - local eof_err_msg = 'EOF was received from Nvim. Likely the Nvim process crashed.' - if type(fn_or_timeout) == 'function' then - eq(eof_err_msg, module.pcall_err(fn_or_timeout, ...)) - else - eq( - eof_err_msg, - module.pcall_err(function(timeout, fn, ...) - fn(...) - assert(session) - while session:next_message(timeout) do - end - if session.eof_err then - error(session.eof_err[2]) - end - end, fn_or_timeout, ...) - ) - end -end - ---- Executes a Vimscript function via Lua. ---- Fails on Vimscript error, but does not update v:errmsg. ---- @param name string ---- @param ... any ---- @return any -function module.call_lua(name, ...) - return module.exec_lua([[return vim.call(...)]], name, ...) -end - ---- Sends user input to Nvim. ---- Does not fail on Vimscript error, but v:errmsg will be updated. ---- @param input string -local function nvim_feed(input) - while #input > 0 do - local written = module.request('nvim_input', input) - if written == nil then - module.assert_alive() - error('crash? (nvim_input returned nil)') - end - input = input:sub(written + 1) - end -end - ---- @param ... string -function module.feed(...) - for _, v in ipairs({ ... }) do - nvim_feed(dedent(v)) - end -end - ----@param ... string[]? ----@return string[] -function module.merge_args(...) - local i = 1 - local argv = {} --- @type string[] - for anum = 1, select('#', ...) do - --- @type string[]? - local args = select(anum, ...) - if args then - for _, arg in ipairs(args) do - argv[i] = arg - i = i + 1 - end - end - end - return argv -end - ---- Removes Nvim startup args from `args` matching items in `args_rm`. ---- ---- - Special case: "-u", "-i", "--cmd" are treated specially: their "values" are also removed. ---- - Special case: "runtimepath" will remove only { '--cmd', 'set runtimepath^=…', } ---- ---- Example: ---- args={'--headless', '-u', 'NONE'} ---- args_rm={'--cmd', '-u'} ---- Result: ---- {'--headless'} ---- ---- All matching cases are removed. ---- ---- Example: ---- args={'--cmd', 'foo', '-N', '--cmd', 'bar'} ---- args_rm={'--cmd', '-u'} ---- Result: ---- {'-N'} ---- @param args string[] ---- @param args_rm string[] ---- @return string[] -local function remove_args(args, args_rm) - local new_args = {} --- @type string[] - local skip_following = { '-u', '-i', '-c', '--cmd', '-s', '--listen' } - if not args_rm or #args_rm == 0 then - return { unpack(args) } - end - for _, v in ipairs(args_rm) do - assert(type(v) == 'string') - end - local last = '' - for _, arg in ipairs(args) do - if vim.tbl_contains(skip_following, last) then - last = '' - elseif vim.tbl_contains(args_rm, arg) then - last = arg - elseif arg == runtime_set and vim.tbl_contains(args_rm, 'runtimepath') then - table.remove(new_args) -- Remove the preceding "--cmd". - last = '' - else - table.insert(new_args, arg) - end - end - return new_args -end - -function module.check_close() - if not session then - return - end - local start_time = uv.now() - session:close() - uv.update_time() -- Update cached value of luv.now() (libuv: uv_now()). - local end_time = uv.now() - local delta = end_time - start_time - if delta > 500 then - print( - 'nvim took ' - .. delta - .. ' milliseconds to exit after last test\n' - .. 'This indicates a likely problem with the test even if it passed!\n' - ) - io.stdout:flush() - end - session = nil -end - ---- @param argv string[] ---- @param merge boolean? ---- @param env string[]? ---- @param keep boolean ---- @param io_extra uv.uv_pipe_t? used for stdin_fd, see :help ui-option ---- @return test.Session -function module.spawn(argv, merge, env, keep, io_extra) - if not keep then - module.check_close() - end - - local child_stream = - ChildProcessStream.spawn(merge and module.merge_args(prepend_argv, argv) or argv, env, io_extra) - return Session.new(child_stream) -end - --- Creates a new Session connected by domain socket (named pipe) or TCP. -function module.connect(file_or_address) - local addr, port = string.match(file_or_address, '(.*):(%d+)') - local stream = (addr and port) and SocketStream.connect(addr, port) - or SocketStream.open(file_or_address) - return Session.new(stream) -end - --- Starts (and returns) a new global Nvim session. --- --- Parameters are interpreted as startup args, OR a map with these keys: --- args: List: Args appended to the default `nvim_argv` set. --- args_rm: List: Args removed from the default set. All cases are --- removed, e.g. args_rm={'--cmd'} removes all cases of "--cmd" --- (and its value) from the default set. --- env: Map: Defines the environment of the new session. --- --- Example: --- clear('-e') --- clear{args={'-e'}, args_rm={'-i'}, env={TERM=term}} -function module.clear(...) - module.set_session(module.spawn_argv(false, ...)) - return module.get_session() -end - ---- same params as clear, but does returns the session instead ---- of replacing the default session ---- @return test.Session -function module.spawn_argv(keep, ...) - local argv, env, io_extra = module.new_argv(...) - return module.spawn(argv, nil, env, keep, io_extra) -end - ---- @class test.new_argv.Opts ---- @field args? string[] ---- @field args_rm? string[] ---- @field env? table<string,string> ---- @field io_extra? uv.uv_pipe_t - ---- Builds an argument list for use in clear(). ---- ---- @see clear() for parameters. ---- @param ... string ---- @return string[] ---- @return string[]? ---- @return uv.uv_pipe_t? -function module.new_argv(...) - local args = { unpack(module.nvim_argv) } - table.insert(args, '--headless') - if _G._nvim_test_id then - -- Set the server name to the test-id for logging. #8519 - table.insert(args, '--listen') - table.insert(args, _G._nvim_test_id) - end - local new_args --- @type string[] - local io_extra --- @type uv.uv_pipe_t? - local env --- @type string[]? - --- @type test.new_argv.Opts|string - local opts = select(1, ...) - if type(opts) ~= 'table' then - new_args = { ... } - else - args = remove_args(args, opts.args_rm) - if opts.env then - local env_opt = {} --- @type table<string,string> - for k, v in pairs(opts.env) do - assert(type(k) == 'string') - assert(type(v) == 'string') - env_opt[k] = v - end - for _, k in ipairs({ - 'HOME', - 'ASAN_OPTIONS', - 'TSAN_OPTIONS', - 'MSAN_OPTIONS', - 'LD_LIBRARY_PATH', - 'PATH', - 'NVIM_LOG_FILE', - 'NVIM_RPLUGIN_MANIFEST', - 'GCOV_ERROR_FILE', - 'XDG_DATA_DIRS', - 'TMPDIR', - 'VIMRUNTIME', - }) do - -- Set these from the environment unless the caller defined them. - if not env_opt[k] then - env_opt[k] = os.getenv(k) - end - end - env = {} - for k, v in pairs(env_opt) do - env[#env + 1] = k .. '=' .. v - end - end - new_args = opts.args or {} - io_extra = opts.io_extra - end - for _, arg in ipairs(new_args) do - table.insert(args, arg) - end - return args, env, io_extra -end - ---- @param ... string -function module.insert(...) - nvim_feed('i') - for _, v in ipairs({ ... }) do - local escaped = v:gsub('<', '<lt>') - module.feed(escaped) - end - nvim_feed('<ESC>') -end - ---- Executes an ex-command by user input. Because nvim_input() is used, Vimscript ---- errors will not manifest as client (lua) errors. Use command() for that. ---- @param ... string -function module.feed_command(...) - for _, v in ipairs({ ... }) do - if v:sub(1, 1) ~= '/' then - -- not a search command, prefix with colon - nvim_feed(':') - end - nvim_feed(v:gsub('<', '<lt>')) - nvim_feed('<CR>') - end -end - --- @deprecated use nvim_exec2() -function module.source(code) - module.exec(dedent(code)) -end - -function module.has_powershell() - return module.eval('executable("' .. (is_os('win') and 'powershell' or 'pwsh') .. '")') == 1 -end - ---- Sets Nvim shell to powershell. ---- ---- @param fake (boolean) If true, a fake will be used if powershell is not ---- found on the system. ---- @returns true if powershell was found on the system, else false. -function module.set_shell_powershell(fake) - local found = module.has_powershell() - if not fake then - assert(found) - end - local shell = found and (is_os('win') and 'powershell' or 'pwsh') or module.testprg('pwsh-test') - local cmd = 'Remove-Item -Force ' - .. table.concat( - is_os('win') and { 'alias:cat', 'alias:echo', 'alias:sleep', 'alias:sort', 'alias:tee' } - or { 'alias:echo' }, - ',' - ) - .. ';' - module.exec([[ - let &shell = ']] .. shell .. [[' - set shellquote= shellxquote= - let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ' - let &shellcmdflag .= '[Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.UTF8Encoding]::new();' - let &shellcmdflag .= '$PSDefaultParameterValues[''Out-File:Encoding'']=''utf8'';' - let &shellcmdflag .= ']] .. cmd .. [[' - let &shellredir = '2>&1 | %%{ "$_" } | Out-File %s; exit $LastExitCode' - let &shellpipe = '2>&1 | %%{ "$_" } | tee %s; exit $LastExitCode' - ]]) - return found -end - ----@param func function ----@return table<string,function> -function module.create_callindex(func) - return setmetatable({}, { - --- @param tbl table<any,function> - --- @param arg1 string - --- @return function - __index = function(tbl, arg1) - local ret = function(...) - return func(arg1, ...) - end - tbl[arg1] = ret - return ret - end, - }) -end - ---- @param method string ---- @param ... any -function module.nvim_async(method, ...) - assert(session):notify(method, ...) -end - ---- Executes a Vimscript function via RPC. ---- Fails on Vimscript error, but does not update v:errmsg. ---- @param name string ---- @param ... any ---- @return any -function module.call(name, ...) - return module.request('nvim_call_function', name, { ... }) -end - -module.async_meths = module.create_callindex(module.nvim_async) - -module.rpc = { - fn = module.create_callindex(module.call), - api = module.create_callindex(module.request), -} - -module.lua = { - fn = module.create_callindex(module.call_lua), - api = module.create_callindex(module.request_lua), -} - -module.describe_lua_and_rpc = function(describe) - return function(what, tests) - local function d(flavour) - describe(string.format('%s (%s)', what, flavour), function(...) - return tests(module[flavour].api, ...) - end) - end - - d('rpc') - d('lua') - end -end - ---- add for typing. The for loop after will overwrite this -module.api = vim.api -module.fn = vim.fn - -for name, fns in pairs(module.rpc) do - --- @diagnostic disable-next-line:no-unknown - module[name] = fns -end - --- Executes an ex-command. Vimscript errors manifest as client (lua) errors, but --- v:errmsg will not be updated. -module.command = module.api.nvim_command - --- Evaluates a Vimscript expression. --- Fails on Vimscript error, but does not update v:errmsg. -module.eval = module.api.nvim_eval - -function module.poke_eventloop() - -- Execute 'nvim_eval' (a deferred function) to - -- force at least one main_loop iteration - module.api.nvim_eval('1') -end - -function module.buf_lines(bufnr) - return module.exec_lua('return vim.api.nvim_buf_get_lines((...), 0, -1, false)', bufnr) -end - ----@see buf_lines() -function module.curbuf_contents() - module.poke_eventloop() -- Before inspecting the buffer, do whatever. - return table.concat(module.api.nvim_buf_get_lines(0, 0, -1, true), '\n') -end - -function module.expect(contents) - return eq(dedent(contents), module.curbuf_contents()) -end - -function module.expect_any(contents) - contents = dedent(contents) - return ok(nil ~= string.find(module.curbuf_contents(), contents, 1, true)) -end - ---- @param expected any[] ---- @param received any[] ---- @param kind string ---- @return any -function module.expect_events(expected, received, kind) - if not pcall(eq, expected, received) then - local msg = 'unexpected ' .. kind .. ' received.\n\n' - - msg = msg .. 'received events:\n' - for _, e in ipairs(received) do - msg = msg .. ' ' .. vim.inspect(e) .. ';\n' - end - msg = msg .. '\nexpected events:\n' - for _, e in ipairs(expected) do - msg = msg .. ' ' .. vim.inspect(e) .. ';\n' - end - fail(msg) - end - return received -end - --- Checks that the Nvim session did not terminate. -function module.assert_alive() - assert(2 == module.eval('1+1'), 'crash? request failed') -end - --- Asserts that buffer is loaded and visible in the current tabpage. -function module.assert_visible(bufnr, visible) - assert(type(visible) == 'boolean') - eq(visible, module.api.nvim_buf_is_loaded(bufnr)) - if visible then - assert( - -1 ~= module.fn.bufwinnr(bufnr), - 'expected buffer to be visible in current tabpage: ' .. tostring(bufnr) - ) - else - assert( - -1 == module.fn.bufwinnr(bufnr), - 'expected buffer NOT visible in current tabpage: ' .. tostring(bufnr) - ) - end -end - ---- @param path string -local function do_rmdir(path) - local stat = uv.fs_stat(path) - if stat == nil then - return - end - if stat.type ~= 'directory' then - error(string.format('rmdir: not a directory: %s', path)) - end - for file in vim.fs.dir(path) do - if file ~= '.' and file ~= '..' then - local abspath = path .. '/' .. file - if global_helpers.isdir(abspath) then - do_rmdir(abspath) -- recurse - else - local ret, err = os.remove(abspath) - if not ret then - if not session then - error('os.remove: ' .. err) - else - -- Try Nvim delete(): it handles `readonly` attribute on Windows, - -- and avoids Lua cross-version/platform incompatibilities. - if -1 == module.call('delete', abspath) then - local hint = (is_os('win') and ' (hint: try :%bwipeout! before rmdir())' or '') - error('delete() failed' .. hint .. ': ' .. abspath) - end - end - end - end - end - end - local ret, err = uv.fs_rmdir(path) - if not ret then - error('luv.fs_rmdir(' .. path .. '): ' .. err) - end -end - -local start_dir = uv.cwd() - -function module.rmdir(path) - local ret, _ = pcall(do_rmdir, path) - if not ret and is_os('win') then - -- Maybe "Permission denied"; try again after changing the nvim - -- process to the top-level directory. - module.command([[exe 'cd '.fnameescape(']] .. start_dir .. "')") - ret, _ = pcall(do_rmdir, path) - end - -- During teardown, the nvim process may not exit quickly enough, then rmdir() - -- will fail (on Windows). - if not ret then -- Try again. - sleep(1000) - do_rmdir(path) - end -end - -function module.exc_exec(cmd) - module.command(([[ - try - execute "%s" - catch - let g:__exception = v:exception - endtry - ]]):format(cmd:gsub('\n', '\\n'):gsub('[\\"]', '\\%0'))) - local ret = module.eval('get(g:, "__exception", 0)') - module.command('unlet! g:__exception') - return ret -end - ---- @param cond boolean ---- @param reason? string ---- @return boolean -function module.skip(cond, reason) - if cond then - --- @type fun(reason: string) - local pending = getfenv(2).pending - pending(reason or 'FIXME') - return true - end - return false -end - --- Calls pending() and returns `true` if the system is too slow to --- run fragile or expensive tests. Else returns `false`. -function module.skip_fragile(pending_fn, cond) - if pending_fn == nil or type(pending_fn) ~= type(function() end) then - error('invalid pending_fn') - end - if cond then - pending_fn('skipped (test is fragile on this system)', function() end) - return true - elseif os.getenv('TEST_SKIP_FRAGILE') then - pending_fn('skipped (TEST_SKIP_FRAGILE)', function() end) - return true - end - return false -end - -function module.exec(code) - module.api.nvim_exec2(code, {}) -end - ---- @param code string ---- @return string -function module.exec_capture(code) - return module.api.nvim_exec2(code, { output = true }).output -end - ---- @param code string ---- @return any -function module.exec_lua(code, ...) - return module.api.nvim_exec_lua(code, { ... }) -end - -function module.get_pathsep() - return is_os('win') and '\\' or '/' -end - ---- Gets the filesystem root dir, namely "/" or "C:/". -function module.pathroot() - local pathsep = package.config:sub(1, 1) - return is_os('win') and (module.nvim_dir:sub(1, 2) .. pathsep) or '/' -end - ---- Gets the full `…/build/bin/{name}` path of a test program produced by ---- `test/functional/fixtures/CMakeLists.txt`. ---- ---- @param name (string) Name of the test program. -function module.testprg(name) - local ext = module.is_os('win') and '.exe' or '' - return ('%s/%s%s'):format(module.nvim_dir, name, ext) -end - -function module.is_asan() - local version = module.eval('execute("verbose version")') - return version:match('-fsanitize=[a-z,]*address') -end - --- Returns a valid, platform-independent Nvim listen address. --- Useful for communicating with child instances. -function module.new_pipename() - -- HACK: Start a server temporarily, get the name, then stop it. - local pipename = module.eval('serverstart()') - module.fn.serverstop(pipename) - -- Remove the pipe so that trying to connect to it without a server listening - -- will be an error instead of a hang. - os.remove(pipename) - return pipename -end - ---- @param provider string ---- @return string|boolean? -function module.missing_provider(provider) - if provider == 'ruby' or provider == 'perl' then - --- @type string? - local e = module.exec_lua("return {require('vim.provider." .. provider .. "').detect()}")[2] - return e ~= '' and e or false - elseif provider == 'node' then - --- @type string? - local e = module.fn['provider#node#Detect']()[2] - return e ~= '' and e or false - elseif provider == 'python' then - return module.exec_lua([[return {require('vim.provider.python').detect_by_module('neovim')}]])[2] - end - assert(false, 'Unknown provider: ' .. provider) -end - ---- @param obj string|table ---- @return any -function module.alter_slashes(obj) - if not is_os('win') then - return obj - end - if type(obj) == 'string' then - local ret = obj:gsub('/', '\\') - return ret - elseif type(obj) == 'table' then - --- @cast obj table<any,any> - local ret = {} --- @type table<any,any> - for k, v in pairs(obj) do - ret[k] = module.alter_slashes(v) - end - return ret - end - assert(false, 'expected string or table of strings, got ' .. type(obj)) -end - -local load_factor = 1 -if global_helpers.is_ci() then - -- Compute load factor only once (but outside of any tests). - module.clear() - module.request('nvim_command', 'source test/old/testdir/load.vim') - load_factor = module.request('nvim_eval', 'g:test_load_factor') -end - ---- @param num number ---- @return number -function module.load_adjust(num) - return math.ceil(num * load_factor) -end - ---- @param ctx table<string,any> ---- @return table -function module.parse_context(ctx) - local parsed = {} --- @type table<string,any> - for _, item in ipairs({ 'regs', 'jumps', 'bufs', 'gvars' }) do - --- @param v any - parsed[item] = vim.tbl_filter(function(v) - return type(v) == 'table' - end, module.call('msgpackparse', ctx[item])) - end - parsed['bufs'] = parsed['bufs'][1] - --- @param v any - return vim.tbl_map(function(v) - if #v == 0 then - return nil - end - return v - end, parsed) -end - -function module.add_builddir_to_rtp() - -- Add runtime from build dir for doc/tags (used with :help). - module.command(string.format([[set rtp+=%s/runtime]], module.paths.test_build_dir)) -end - ---- Kill (reap) a process by PID. ---- @param pid string ---- @return boolean? -function module.os_kill(pid) - return os.execute( - ( - is_os('win') and 'taskkill /f /t /pid ' .. pid .. ' > nul' - or 'kill -9 ' .. pid .. ' > /dev/null' - ) - ) -end - ---- Create folder with non existing parents ---- @param path string ---- @return boolean? -function module.mkdir_p(path) - return os.execute((is_os('win') and 'mkdir ' .. path or 'mkdir -p ' .. path)) -end - ---- @return test.functional.helpers -return function(after_each) - if after_each then - after_each(function() - check_logs() - check_cores('build/bin/nvim') - if session then - local msg = session:next_message(0) - if msg then - if msg[1] == 'notification' and msg[2] == 'nvim_error_event' then - error(msg[3][2]) - end - end - end - end) - end - return module -end diff --git a/test/functional/legacy/002_filename_recognition_spec.lua b/test/functional/legacy/002_filename_recognition_spec.lua @@ -1,9 +1,9 @@ -- Test if URLs are recognized as filenames by commands such as "gf". Here -- we'll use `expand("<cfile>")` since "gf" would need to open the file. -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local feed_command, expect = helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local feed_command, expect = t.feed_command, t.expect describe('filename recognition', function() setup(clear) diff --git a/test/functional/legacy/004_bufenter_with_modelines_spec.lua b/test/functional/legacy/004_bufenter_with_modelines_spec.lua @@ -1,9 +1,9 @@ -- Test for autocommand that changes current buffer on BufEnter event. -- Check if modelines are interpreted for the correct buffer. -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local feed_command, expect = helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local feed_command, expect = t.feed_command, t.expect describe('BufEnter with modelines', function() setup(clear) diff --git a/test/functional/legacy/005_bufleave_delete_buffer_spec.lua b/test/functional/legacy/005_bufleave_delete_buffer_spec.lua @@ -1,10 +1,10 @@ -- Test for autocommand that deletes the current buffer on BufLeave event. -- Also test deleting the last buffer, should give a new, empty buffer. -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local command, expect = helpers.command, helpers.expect -local poke_eventloop = helpers.poke_eventloop +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local command, expect = t.command, t.expect +local poke_eventloop = t.poke_eventloop describe('test5', function() setup(clear) diff --git a/test/functional/legacy/007_ball_buffer_list_spec.lua b/test/functional/legacy/007_ball_buffer_list_spec.lua @@ -1,8 +1,8 @@ -- Test for autocommand that changes the buffer list, when doing ":ball". -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local feed_command, expect = helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local feed_command, expect = t.feed_command, t.expect describe(':ball', function() setup(clear) diff --git a/test/functional/legacy/008_autocommands_spec.lua b/test/functional/legacy/008_autocommands_spec.lua @@ -1,13 +1,12 @@ -- Test for BufWritePre autocommand that deletes or unloads the buffer. -- Test for BufUnload autocommand that unloads all other buffers. -local helpers = require('test.functional.helpers')(after_each) -local source = helpers.source -local clear, command, expect, eq, eval = - helpers.clear, helpers.command, helpers.expect, helpers.eq, helpers.eval -local write_file, dedent = helpers.write_file, helpers.dedent -local read_file = helpers.read_file -local expect_exit = helpers.expect_exit +local t = require('test.functional.testutil')(after_each) +local source = t.source +local clear, command, expect, eq, eval = t.clear, t.command, t.expect, t.eq, t.eval +local write_file, dedent = t.write_file, t.dedent +local read_file = t.read_file +local expect_exit = t.expect_exit describe('autocommands that delete and unload buffers:', function() local test_file = 'Xtest-008_autocommands.out' diff --git a/test/functional/legacy/011_autocommands_spec.lua b/test/functional/legacy/011_autocommands_spec.lua @@ -12,19 +12,12 @@ -- Use a FileChangedShell autocommand to avoid a prompt for "Xtestfile.gz" -- being modified outside of Vim (noticed on Solaris). -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local clear, feed_command, expect, eq, neq, dedent, write_file, feed = - helpers.clear, - helpers.feed_command, - helpers.expect, - helpers.eq, - helpers.neq, - helpers.dedent, - helpers.write_file, - helpers.feed -local command = helpers.command -local read_file = helpers.read_file -local is_os = helpers.is_os + t.clear, t.feed_command, t.expect, t.eq, t.neq, t.dedent, t.write_file, t.feed +local command = t.command +local read_file = t.read_file +local is_os = t.is_os local function has_gzip() local null = is_os('win') and 'nul' or '/dev/null' diff --git a/test/functional/legacy/012_directory_spec.lua b/test/functional/legacy/012_directory_spec.lua @@ -3,19 +3,19 @@ -- - "./dir", in directory relative to file -- - "dir", in directory relative to current dir -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local neq = helpers.neq -local poke_eventloop = helpers.poke_eventloop -local fn = helpers.fn -local api = helpers.api -local clear = helpers.clear -local insert = helpers.insert -local command = helpers.command -local write_file = helpers.write_file -local expect_exit = helpers.expect_exit -local mkdir = helpers.mkdir +local eq = t.eq +local neq = t.neq +local poke_eventloop = t.poke_eventloop +local fn = t.fn +local api = t.api +local clear = t.clear +local insert = t.insert +local command = t.command +local write_file = t.write_file +local expect_exit = t.expect_exit +local mkdir = t.mkdir local function ls_dir_sorted(dirname) local files = {} @@ -44,8 +44,8 @@ describe("'directory' option", function() end) teardown(function() expect_exit(command, 'qall!') - helpers.rmdir('Xtest.je') - helpers.rmdir('Xtest2') + t.rmdir('Xtest.je') + t.rmdir('Xtest2') os.remove('Xtest1') end) diff --git a/test/functional/legacy/015_alignment_spec.lua b/test/functional/legacy/015_alignment_spec.lua @@ -2,9 +2,9 @@ -- Also test formatting a paragraph. -- Also test undo after ":%s" and formatting. -local helpers = require('test.functional.helpers')(after_each) -local feed, insert = helpers.feed, helpers.insert -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local feed, insert = t.feed, t.insert +local clear, feed_command, expect = t.clear, t.feed_command, t.expect describe('alignment', function() setup(clear) diff --git a/test/functional/legacy/018_unset_smart_indenting_spec.lua b/test/functional/legacy/018_unset_smart_indenting_spec.lua @@ -1,12 +1,12 @@ -- Tests for not doing smart indenting when it isn't set. -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local feed = helpers.feed -local clear = helpers.clear -local insert = helpers.insert -local expect = helpers.expect -local feed_command = helpers.feed_command +local feed = t.feed +local clear = t.clear +local insert = t.insert +local expect = t.expect +local feed_command = t.feed_command describe('unset smart indenting', function() before_each(clear) diff --git a/test/functional/legacy/019_smarttab_expandtab_spec.lua b/test/functional/legacy/019_smarttab_expandtab_spec.lua @@ -1,9 +1,9 @@ -- Tests for "r<Tab>" with 'smarttab' and 'expandtab' set/not set. -- Also test that dv_ works correctly -local helpers = require('test.functional.helpers')(after_each) -local feed, insert = helpers.feed, helpers.insert -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local feed, insert = t.feed, t.insert +local clear, feed_command, expect = t.clear, t.feed_command, t.expect describe([[performing "r<Tab>" with 'smarttab' and 'expandtab' set/not set, and "dv_"]], function() setup(clear) diff --git a/test/functional/legacy/020_blockwise_visual_spec.lua b/test/functional/legacy/020_blockwise_visual_spec.lua @@ -2,9 +2,9 @@ -- First test for undo working properly when executing commands from a register. -- Also test this in an empty buffer. -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local feed_command, expect = helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local feed_command, expect = t.feed_command, t.expect describe('blockwise visual', function() setup(clear) diff --git a/test/functional/legacy/021_control_wi_spec.lua b/test/functional/legacy/021_control_wi_spec.lua @@ -1,8 +1,8 @@ -- Tests for [ CTRL-I with a count and CTRL-W CTRL-I with a count -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local feed_command, expect = helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local feed_command, expect = t.feed_command, t.expect describe('CTRL-W CTRL-I', function() setup(clear) diff --git a/test/functional/legacy/023_edit_arguments_spec.lua b/test/functional/legacy/023_edit_arguments_spec.lua @@ -1,9 +1,9 @@ -- Tests for complicated + argument to :edit command -local helpers = require('test.functional.helpers')(after_each) -local clear, insert = helpers.clear, helpers.insert -local command, expect = helpers.command, helpers.expect -local poke_eventloop = helpers.poke_eventloop +local t = require('test.functional.testutil')(after_each) +local clear, insert = t.clear, t.insert +local command, expect = t.command, t.expect +local poke_eventloop = t.poke_eventloop describe(':edit', function() setup(clear) diff --git a/test/functional/legacy/025_jump_tag_hidden_spec.lua b/test/functional/legacy/025_jump_tag_hidden_spec.lua @@ -1,9 +1,9 @@ -- Test for jumping to a tag with 'hidden' set, with symbolic link in path of tag. -- This only works for Unix, because of the symbolic link. -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local feed_command, expect = helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local feed_command, expect = t.feed_command, t.expect describe('jump to a tag with hidden set', function() setup(clear) @@ -23,7 +23,7 @@ describe('jump to a tag with hidden set', function() feed_command('set hidden') -- Create a link from test25.dir to the current directory. - if helpers.is_os('win') then + if t.is_os('win') then feed_command('!rd /q/s test25.dir') feed_command('!mklink /j test25.dir .') else @@ -33,7 +33,7 @@ describe('jump to a tag with hidden set', function() -- Create tags.text, with the current directory name inserted. feed_command('/tags line') - feed_command('r !' .. (helpers.is_os('win') and 'cd' or 'pwd')) + feed_command('r !' .. (t.is_os('win') and 'cd' or 'pwd')) feed('d$/test<cr>') feed('hP:.w! tags.test<cr>') @@ -44,7 +44,7 @@ describe('jump to a tag with hidden set', function() feed('G<C-]> x:yank a<cr>') feed_command("call delete('tags.test')") feed_command("call delete('Xxx')") - if helpers.is_os('win') then + if t.is_os('win') then feed_command('!rd /q test25.dir') else feed_command('!rm -f test25.dir') diff --git a/test/functional/legacy/026_execute_while_if_spec.lua b/test/functional/legacy/026_execute_while_if_spec.lua @@ -1,11 +1,11 @@ -- Test for :execute, :while and :if -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local expect = helpers.expect -local source = helpers.source -local command = helpers.command +local clear = t.clear +local expect = t.expect +local source = t.source +local command = t.command describe(':execute, :while and :if', function() setup(clear) diff --git a/test/functional/legacy/028_source_ctrl_v_spec.lua b/test/functional/legacy/028_source_ctrl_v_spec.lua @@ -1,8 +1,8 @@ -- Test for sourcing a file with CTRL-V's at the end of the line -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local feed_command, expect = helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local feed_command, expect = t.feed_command, t.expect describe('CTRL-V at the end of the line', function() setup(clear) diff --git a/test/functional/legacy/029_join_spec.lua b/test/functional/legacy/029_join_spec.lua @@ -1,12 +1,12 @@ -- Test for joining lines with marks in them (and with 'joinspaces' set/reset) -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local feed = helpers.feed -local clear = helpers.clear -local insert = helpers.insert -local expect = helpers.expect -local feed_command = helpers.feed_command +local feed = t.feed +local clear = t.clear +local insert = t.insert +local expect = t.expect +local feed_command = t.feed_command describe('joining lines', function() before_each(clear) diff --git a/test/functional/legacy/030_fileformats_spec.lua b/test/functional/legacy/030_fileformats_spec.lua @@ -1,9 +1,9 @@ -- Test for a lot of variations of the 'fileformats' option -local helpers = require('test.functional.helpers')(after_each) -local feed, clear, command = helpers.feed, helpers.clear, helpers.command -local eq, write_file = helpers.eq, helpers.write_file -local poke_eventloop = helpers.poke_eventloop +local t = require('test.functional.testutil')(after_each) +local feed, clear, command = t.feed, t.clear, t.command +local eq, write_file = t.eq, t.write_file +local poke_eventloop = t.poke_eventloop describe('fileformats option', function() setup(function() @@ -254,7 +254,7 @@ describe('fileformats option', function() command('set nobinary ff&') -- Assert buffer contents. This has to be done manually as - -- helpers.expect() calls helpers.dedent() which messes up the white space + -- t.expect() calls t.dedent() which messes up the white space -- and carriage returns. eq( 'unix\n'.. @@ -387,6 +387,6 @@ describe('fileformats option', function() '10\n'.. 'unix\n'.. 'unix', - helpers.curbuf_contents()) + t.curbuf_contents()) end) end) diff --git a/test/functional/legacy/031_close_commands_spec.lua b/test/functional/legacy/031_close_commands_spec.lua @@ -9,15 +9,15 @@ -- :buf -- :edit -local helpers = require('test.functional.helpers')(after_each) - -local feed = helpers.feed -local clear = helpers.clear -local source = helpers.source -local insert = helpers.insert -local expect = helpers.expect -local feed_command = helpers.feed_command -local expect_exit = helpers.expect_exit +local t = require('test.functional.testutil')(after_each) + +local feed = t.feed +local clear = t.clear +local source = t.source +local insert = t.insert +local expect = t.expect +local feed_command = t.feed_command +local expect_exit = t.expect_exit describe('Commands that close windows and/or buffers', function() local function cleanup() diff --git a/test/functional/legacy/033_lisp_indent_spec.lua b/test/functional/legacy/033_lisp_indent_spec.lua @@ -1,10 +1,10 @@ -- Test for 'lisp' -- If the lisp feature is not enabled, this will fail! -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local command, expect = helpers.command, helpers.expect -local poke_eventloop = helpers.poke_eventloop +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local command, expect = t.command, t.expect +local poke_eventloop = t.poke_eventloop describe('lisp indent', function() setup(clear) diff --git a/test/functional/legacy/034_user_function_spec.lua b/test/functional/legacy/034_user_function_spec.lua @@ -3,9 +3,9 @@ -- Also test that a builtin function cannot be replaced. -- Also test for regression when calling arbitrary expression. -local helpers = require('test.functional.helpers')(after_each) -local feed, insert, source = helpers.feed, helpers.insert, helpers.source -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local feed, insert, source = t.feed, t.insert, t.source +local clear, feed_command, expect = t.clear, t.feed_command, t.expect describe( 'user functions, expr-mappings, overwrite protected builtin functions and regression on calling expressions', diff --git a/test/functional/legacy/035_increment_and_decrement_spec.lua b/test/functional/legacy/035_increment_and_decrement_spec.lua @@ -1,9 +1,9 @@ -- Test Ctrl-A and Ctrl-X, which increment and decrement decimal, hexadecimal, -- and octal numbers. -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local feed_command, expect = helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local feed_command, expect = t.feed_command, t.expect describe('increment and decrement commands', function() setup(clear) diff --git a/test/functional/legacy/036_regexp_character_classes_spec.lua b/test/functional/legacy/036_regexp_character_classes_spec.lua @@ -1,8 +1,8 @@ -- Test character classes in regexp using regexpengine 0, 1, 2. -local helpers = require('test.functional.helpers')(after_each) -local clear, command, expect = helpers.clear, helpers.command, helpers.expect -local source, write_file = helpers.source, helpers.write_file +local t = require('test.functional.testutil')(after_each) +local clear, command, expect = t.clear, t.command, t.expect +local source, write_file = t.source, t.write_file local function sixlines(text) local result = '' @@ -13,14 +13,14 @@ local function sixlines(text) end local function diff(text, nodedent) - local fname = helpers.tmpname() + local fname = t.tmpname() command('w! ' .. fname) - helpers.poke_eventloop() + t.poke_eventloop() local data = io.open(fname):read('*all') if nodedent then - helpers.eq(text, data) + t.eq(text, data) else - helpers.eq(helpers.dedent(text), data) + t.eq(t.dedent(text), data) end os.remove(fname) end diff --git a/test/functional/legacy/038_virtual_replace_spec.lua b/test/functional/legacy/038_virtual_replace_spec.lua @@ -1,8 +1,8 @@ -- Test Virtual replace mode. -local helpers = require('test.functional.helpers')(after_each) -local feed = helpers.feed -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local feed = t.feed +local clear, feed_command, expect = t.clear, t.feed_command, t.expect describe('Virtual replace mode', function() setup(clear) diff --git a/test/functional/legacy/039_visual_block_mode_commands_spec.lua b/test/functional/legacy/039_visual_block_mode_commands_spec.lua @@ -1,11 +1,11 @@ -- Test Visual block mode commands -- And test "U" in Visual mode, also on German sharp S. -local helpers = require('test.functional.helpers')(after_each) -local nvim, eq = helpers.api, helpers.eq -local insert, feed = helpers.insert, helpers.feed -local clear, expect = helpers.clear, helpers.expect -local feed_command = helpers.feed_command +local t = require('test.functional.testutil')(after_each) +local nvim, eq = t.api, t.eq +local insert, feed = t.insert, t.feed +local clear, expect = t.clear, t.expect +local feed_command = t.feed_command describe('Visual block mode', function() before_each(function() diff --git a/test/functional/legacy/043_magic_settings_spec.lua b/test/functional/legacy/043_magic_settings_spec.lua @@ -1,8 +1,8 @@ -- Tests for regexp with various magic settings. -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local feed_command, expect = helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local feed_command, expect = t.feed_command, t.expect describe('regexp with magic settings', function() setup(clear) diff --git a/test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua b/test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua @@ -3,9 +3,9 @@ -- -- This test contains both "test44" and "test99" from the old test suite. -local helpers = require('test.functional.helpers')(after_each) -local feed, insert = helpers.feed, helpers.insert -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local feed, insert = t.feed, t.insert +local clear, feed_command, expect = t.clear, t.feed_command, t.expect -- Runs the test protocol with the given 'regexpengine' setting. In the old test -- suite the test protocol was duplicated in test44 and test99, the only diff --git a/test/functional/legacy/046_multi_line_regexps_spec.lua b/test/functional/legacy/046_multi_line_regexps_spec.lua @@ -1,9 +1,9 @@ -- vim: set foldmethod=marker foldmarker=[[,]] : -- Tests for multi-line regexps with ":s" -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local expect = helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local expect = t.expect describe('multi-line regexp', function() setup(clear) diff --git a/test/functional/legacy/054_buffer_local_autocommands_spec.lua b/test/functional/legacy/054_buffer_local_autocommands_spec.lua @@ -1,10 +1,10 @@ -- Some tests for buffer-local autocommands -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local expect = helpers.expect -local command = helpers.command +local clear = t.clear +local expect = t.expect +local command = t.command local fname = 'Xtest-functional-legacy-054' diff --git a/test/functional/legacy/055_list_and_dict_types_spec.lua b/test/functional/legacy/055_list_and_dict_types_spec.lua @@ -1,8 +1,8 @@ -- Tests for List and Dictionary types. -local helpers = require('test.functional.helpers')(after_each) -local feed, source = helpers.feed, helpers.source -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local feed, source = t.feed, t.source +local clear, feed_command, expect = t.clear, t.feed_command, t.expect describe('list and dictionary types', function() before_each(clear) diff --git a/test/functional/legacy/056_script_local_function_spec.lua b/test/functional/legacy/056_script_local_function_spec.lua @@ -1,9 +1,9 @@ -- vim: set foldmethod=marker foldmarker=[[,]] : -- Test for script-local function. -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local expect = helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local expect = t.expect describe('source function', function() setup(clear) diff --git a/test/functional/legacy/057_sort_spec.lua b/test/functional/legacy/057_sort_spec.lua @@ -1,10 +1,10 @@ -- Tests for :sort command. -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local insert, command, clear, expect, eq, poke_eventloop = - helpers.insert, helpers.command, helpers.clear, helpers.expect, helpers.eq, helpers.poke_eventloop -local exc_exec = helpers.exc_exec + t.insert, t.command, t.clear, t.expect, t.eq, t.poke_eventloop +local exc_exec = t.exc_exec describe(':sort', function() local text = [[ diff --git a/test/functional/legacy/060_exists_and_has_functions_spec.lua b/test/functional/legacy/060_exists_and_has_functions_spec.lua @@ -1,9 +1,9 @@ -- Tests for the exists() and has() functions. -local helpers = require('test.functional.helpers')(after_each) -local source = helpers.source -local clear, expect = helpers.clear, helpers.expect -local write_file = helpers.write_file +local t = require('test.functional.testutil')(after_each) +local source = t.source +local clear, expect = t.clear, t.expect +local write_file = t.write_file describe('exists() and has() functions', function() setup(function() diff --git a/test/functional/legacy/061_undo_tree_spec.lua b/test/functional/legacy/061_undo_tree_spec.lua @@ -1,18 +1,18 @@ -- Tests for undo tree and :earlier and :later. -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local feed_command = helpers.feed_command -local write_file = helpers.write_file -local command = helpers.command -local source = helpers.source -local expect = helpers.expect -local clear = helpers.clear -local feed = helpers.feed -local eval = helpers.eval -local eq = helpers.eq +local feed_command = t.feed_command +local write_file = t.write_file +local command = t.command +local source = t.source +local expect = t.expect +local clear = t.clear +local feed = t.feed +local eval = t.eval +local eq = t.eq local function expect_empty_buffer() - -- The space will be removed by helpers.dedent but is needed because dedent + -- The space will be removed by t.dedent but is needed because dedent -- will fail if it can not find the common indent of the given lines. return expect(' ') end @@ -99,7 +99,7 @@ describe('undo tree:', function() expect_line('123456abc') end - helpers.retry(2, nil, test_earlier_later) + t.retry(2, nil, test_earlier_later) end) it('file-write specifications', function() diff --git a/test/functional/legacy/063_match_and_matchadd_spec.lua b/test/functional/legacy/063_match_and_matchadd_spec.lua @@ -1,10 +1,10 @@ -- Tests for adjusting window and contents -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, command = helpers.clear, helpers.command -local insert = helpers.insert +local clear, command = t.clear, t.command +local insert = t.insert describe('063: Test for ":match", "matchadd()" and related functions', function() setup(clear) diff --git a/test/functional/legacy/065_float_and_logic_operators_spec.lua b/test/functional/legacy/065_float_and_logic_operators_spec.lua @@ -1,8 +1,8 @@ -- Test for floating point and logical operators. -local helpers = require('test.functional.helpers')(after_each) -local insert, source = helpers.insert, helpers.source -local clear, expect = helpers.clear, helpers.expect +local t = require('test.functional.testutil')(after_each) +local insert, source = t.insert, t.source +local clear, expect = t.clear, t.expect describe('floating point and logical operators', function() setup(clear) diff --git a/test/functional/legacy/066_visual_block_tab_spec.lua b/test/functional/legacy/066_visual_block_tab_spec.lua @@ -1,9 +1,9 @@ -- vim: set foldmethod=marker foldmarker=[[,]] : -- Test for visual block shift and tab characters. -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local feed_command, expect = helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local feed_command, expect = t.feed_command, t.expect describe('visual block shift and tab characters', function() setup(clear) diff --git a/test/functional/legacy/067_augroup_exists_spec.lua b/test/functional/legacy/067_augroup_exists_spec.lua @@ -1,9 +1,9 @@ -- Test that groups and patterns are tested correctly when calling exists() for -- autocommands. -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command, expect = helpers.command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command, expect = t.command, t.expect describe('augroup when calling exists()', function() setup(clear) diff --git a/test/functional/legacy/068_text_formatting_spec.lua b/test/functional/legacy/068_text_formatting_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local feed = helpers.feed -local clear = helpers.clear -local insert = helpers.insert -local feed_command = helpers.feed_command -local expect = helpers.expect +local feed = t.feed +local clear = t.clear +local insert = t.insert +local feed_command = t.feed_command +local expect = t.expect describe('text formatting', function() setup(clear) diff --git a/test/functional/legacy/069_multibyte_formatting_spec.lua b/test/functional/legacy/069_multibyte_formatting_spec.lua @@ -3,15 +3,9 @@ -- And test "ra" on multibyte characters. -- Also test byteidx() and byteidxcomp() -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local feed, insert, eq, eval, clear, feed_command, expect = - helpers.feed, - helpers.insert, - helpers.eq, - helpers.eval, - helpers.clear, - helpers.feed_command, - helpers.expect + t.feed, t.insert, t.eq, t.eval, t.clear, t.feed_command, t.expect describe('multibyte text', function() before_each(clear) diff --git a/test/functional/legacy/072_undo_file_spec.lua b/test/functional/legacy/072_undo_file_spec.lua @@ -2,9 +2,9 @@ -- Since this script is sourced we need to explicitly break changes up in -- undo-able pieces. Do that by setting 'undolevels'. -local helpers = require('test.functional.helpers')(after_each) -local feed, insert = helpers.feed, helpers.insert -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local feed, insert = t.feed, t.insert +local clear, feed_command, expect = t.clear, t.feed_command, t.expect describe('72', function() setup(clear) diff --git a/test/functional/legacy/074_global_var_in_viminfo_spec.lua b/test/functional/legacy/074_global_var_in_viminfo_spec.lua @@ -1,8 +1,8 @@ -- Tests for storing global variables in the .shada file -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local clear, command, eq, neq, eval, poke_eventloop = - helpers.clear, helpers.command, helpers.eq, helpers.neq, helpers.eval, helpers.poke_eventloop + t.clear, t.command, t.eq, t.neq, t.eval, t.poke_eventloop describe('storing global variables in ShaDa files', function() local tempname = 'Xtest-functional-legacy-074' diff --git a/test/functional/legacy/078_swapfile_recover_spec.lua b/test/functional/legacy/078_swapfile_recover_spec.lua @@ -3,8 +3,8 @@ -- restored. We need about 10000 lines of 100 characters to get two levels of -- pointer blocks. -local helpers = require('test.functional.helpers')(after_each) -local clear, expect, source = helpers.clear, helpers.expect, helpers.source +local t = require('test.functional.testutil')(after_each) +local clear, expect, source = t.clear, t.expect, t.source describe('78', function() setup(clear) diff --git a/test/functional/legacy/081_coptions_movement_spec.lua b/test/functional/legacy/081_coptions_movement_spec.lua @@ -1,8 +1,8 @@ -- Test for t movement command and 'cpo-;' setting -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local feed_command, expect = helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local feed_command, expect = t.feed_command, t.expect describe('coptions', function() setup(clear) diff --git a/test/functional/legacy/082_string_comparison_spec.lua b/test/functional/legacy/082_string_comparison_spec.lua @@ -1,9 +1,9 @@ -- Tests for case-insensitive UTF-8 comparisons (utf_strnicmp() in mbyte.c) -- Also test "g~ap". -local helpers = require('test.functional.helpers')(after_each) -local feed, source = helpers.feed, helpers.source -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local feed, source = t.feed, t.source +local clear, feed_command, expect = t.clear, t.feed_command, t.expect describe('case-insensitive string comparison in UTF-8', function() setup(clear) diff --git a/test/functional/legacy/083_tag_search_with_file_encoding_spec.lua b/test/functional/legacy/083_tag_search_with_file_encoding_spec.lua @@ -1,12 +1,12 @@ -- Tests for tag search with !_TAG_FILE_ENCODING. -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local insert, source, clear, expect, write_file = - helpers.insert, helpers.source, helpers.clear, helpers.expect, helpers.write_file + t.insert, t.source, t.clear, t.expect, t.write_file local function has_iconv() clear() -- ensures session - return 1 == helpers.eval('has("iconv")') + return 1 == t.eval('has("iconv")') end describe('tag search with !_TAG_FILE_ENCODING', function() @@ -31,7 +31,7 @@ describe('tag search with !_TAG_FILE_ENCODING', function() ) -- The last file is very long but repetitive and can be generated on the -- fly. - local text = helpers.dedent([[ + local text = t.dedent([[ !_TAG_FILE_SORTED 1 // !_TAG_FILE_ENCODING cp932 // ]]) diff --git a/test/functional/legacy/090_sha256_spec.lua b/test/functional/legacy/090_sha256_spec.lua @@ -1,8 +1,8 @@ -- Tests for sha256() function. -local helpers = require('test.functional.helpers')(after_each) -local insert, source = helpers.insert, helpers.source -local clear, expect = helpers.clear, helpers.expect +local t = require('test.functional.testutil')(after_each) +local insert, source = t.insert, t.source +local clear, expect = t.clear, t.expect describe('sha256()', function() setup(clear) diff --git a/test/functional/legacy/091_context_variables_spec.lua b/test/functional/legacy/091_context_variables_spec.lua @@ -1,8 +1,8 @@ -- Tests for getbufvar(), getwinvar(), gettabvar() and gettabwinvar(). -local helpers = require('test.functional.helpers')(after_each) -local insert, source = helpers.insert, helpers.source -local clear, expect = helpers.clear, helpers.expect +local t = require('test.functional.testutil')(after_each) +local insert, source = t.insert, t.source +local clear, expect = t.clear, t.expect describe('context variables', function() setup(clear) diff --git a/test/functional/legacy/092_mksession_cursor_cols_utf8_spec.lua b/test/functional/legacy/092_mksession_cursor_cols_utf8_spec.lua @@ -3,9 +3,9 @@ -- -- Same as legacy test 93 but using UTF-8 file encoding. -local helpers = require('test.functional.helpers')(after_each) -local feed, insert = helpers.feed, helpers.insert -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local feed, insert = t.feed, t.insert +local clear, feed_command, expect = t.clear, t.feed_command, t.expect describe('store cursor position in session file in UTF-8', function() setup(clear) diff --git a/test/functional/legacy/093_mksession_cursor_cols_latin1_spec.lua b/test/functional/legacy/093_mksession_cursor_cols_latin1_spec.lua @@ -3,9 +3,9 @@ -- -- Same as legacy test 92 but using Latin-1 file encoding. -local helpers = require('test.functional.helpers')(after_each) -local feed, insert = helpers.feed, helpers.insert -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local feed, insert = t.feed, t.insert +local clear, feed_command, expect = t.clear, t.feed_command, t.expect describe('store cursor position in session file in Latin-1', function() setup(clear) diff --git a/test/functional/legacy/094_visual_mode_operators_spec.lua b/test/functional/legacy/094_visual_mode_operators_spec.lua @@ -4,9 +4,9 @@ -- followed by an operator and those executed via Operator-pending mode. Also -- part of the test are mappings, counts, and repetition with the . command. -local helpers = require('test.functional.helpers')(after_each) -local feed, insert, source = helpers.feed, helpers.insert, helpers.source -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local feed, insert, source = t.feed, t.insert, t.source +local clear, feed_command, expect = t.clear, t.feed_command, t.expect -- Vim script user functions needed for some of the test cases. local function source_user_functions() diff --git a/test/functional/legacy/095_regexp_multibyte_spec.lua b/test/functional/legacy/095_regexp_multibyte_spec.lua @@ -3,9 +3,9 @@ -- A pattern that gives the expected result produces OK, so that we know it was -- actually tried. -local helpers = require('test.functional.helpers')(after_each) -local insert, source = helpers.insert, helpers.source -local clear, expect = helpers.clear, helpers.expect +local t = require('test.functional.testutil')(after_each) +local insert, source = t.insert, t.source +local clear, expect = t.clear, t.expect describe('regex with multi-byte', function() setup(clear) diff --git a/test/functional/legacy/096_location_list_spec.lua b/test/functional/legacy/096_location_list_spec.lua @@ -6,9 +6,9 @@ -- C. make sure that the location list window is not reused instead of the window -- it belongs to. -local helpers = require('test.functional.helpers')(after_each) -local source = helpers.source -local clear, command, expect = helpers.clear, helpers.command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local source = t.source +local clear, command, expect = t.clear, t.command, t.expect describe('location list', function() local test_file = 'Xtest-096_location_list.out' diff --git a/test/functional/legacy/097_glob_path_spec.lua b/test/functional/legacy/097_glob_path_spec.lua @@ -2,15 +2,15 @@ -- Test whether glob()/globpath() return correct results with certain escaped -- characters. -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command, expect = helpers.command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command, expect = t.command, t.expect describe('glob() and globpath()', function() setup(clear) setup(function() - if helpers.is_os('win') then + if t.is_os('win') then os.execute('md sautest\\autoload') os.execute('.>sautest\\autoload\\Test104.vim 2>nul') os.execute('.>sautest\\autoload\\footest.vim 2>nul') @@ -28,7 +28,7 @@ describe('glob() and globpath()', function() -- Consistent sorting of file names command('set nofileignorecase') - if helpers.is_os('win') then + if t.is_os('win') then command([[$put =glob('Xxx{')]]) command([[$put =glob('Xxx$')]]) @@ -72,7 +72,7 @@ describe('glob() and globpath()', function() end) teardown(function() - if helpers.is_os('win') then + if t.is_os('win') then os.execute('del /q/f Xxx{ Xxx$') os.execute('rd /q /s sautest') else diff --git a/test/functional/legacy/101_hlsearch_spec.lua b/test/functional/legacy/101_hlsearch_spec.lua @@ -1,8 +1,8 @@ -- Test for v:hlsearch -local helpers = require('test.functional.helpers')(after_each) -local clear, feed = helpers.clear, helpers.feed -local feed_command, expect = helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed = t.clear, t.feed +local feed_command, expect = t.feed_command, t.expect describe('v:hlsearch', function() setup(clear) diff --git a/test/functional/legacy/102_fnameescape_spec.lua b/test/functional/legacy/102_fnameescape_spec.lua @@ -1,8 +1,8 @@ -- Test if fnameescape is correct for special chars like! -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command, expect = helpers.command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command, expect = t.command, t.expect describe('fnameescape', function() setup(clear) diff --git a/test/functional/legacy/103_visual_mode_reset_spec.lua b/test/functional/legacy/103_visual_mode_reset_spec.lua @@ -1,8 +1,8 @@ -- Test for visual mode not being reset causing E315 error. -local helpers = require('test.functional.helpers')(after_each) -local feed, source = helpers.feed, helpers.source -local clear, expect = helpers.clear, helpers.expect +local t = require('test.functional.testutil')(after_each) +local feed, source = t.feed, t.source +local clear, expect = t.clear, t.expect describe('E315 error', function() setup(clear) diff --git a/test/functional/legacy/106_errorformat_spec.lua b/test/functional/legacy/106_errorformat_spec.lua @@ -1,8 +1,8 @@ -- Tests for errorformat. -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command, expect = helpers.command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command, expect = t.command, t.expect describe('errorformat', function() setup(clear) diff --git a/test/functional/legacy/107_adjust_window_and_contents_spec.lua b/test/functional/legacy/107_adjust_window_and_contents_spec.lua @@ -1,12 +1,12 @@ -- Tests for adjusting window and contents -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local poke_eventloop = helpers.poke_eventloop -local clear = helpers.clear -local insert = helpers.insert -local command = helpers.command +local poke_eventloop = t.poke_eventloop +local clear = t.clear +local insert = t.insert +local command = t.command describe('107', function() setup(clear) diff --git a/test/functional/legacy/108_backtrace_debug_commands_spec.lua b/test/functional/legacy/108_backtrace_debug_commands_spec.lua @@ -1,9 +1,9 @@ -- Tests for backtrace debug commands. -local helpers = require('test.functional.helpers')(after_each) -local command = helpers.command -local feed, clear = helpers.feed, helpers.clear -local feed_command, expect = helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local command = t.command +local feed, clear = t.feed, t.clear +local feed_command, expect = t.feed_command, t.expect describe('108', function() before_each(clear) diff --git a/test/functional/legacy/arglist_spec.lua b/test/functional/legacy/arglist_spec.lua @@ -1,11 +1,11 @@ -- Test argument list commands -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, command, eq = helpers.clear, helpers.command, helpers.eq -local expect_exit = helpers.expect_exit -local feed = helpers.feed -local pcall_err = helpers.pcall_err +local clear, command, eq = t.clear, t.command, t.eq +local expect_exit = t.expect_exit +local feed = t.feed +local pcall_err = t.pcall_err describe('argument list commands', function() before_each(clear) diff --git a/test/functional/legacy/assert_spec.lua b/test/functional/legacy/assert_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) -local nvim, call = helpers.api, helpers.call -local clear, eq = helpers.clear, helpers.eq -local source, command = helpers.source, helpers.command -local exc_exec = helpers.exc_exec -local eval = helpers.eval +local t = require('test.functional.testutil')(after_each) +local nvim, call = t.api, t.call +local clear, eq = t.clear, t.eq +local source, command = t.source, t.command +local exc_exec = t.exc_exec +local eval = t.eval local function expected_errors(errors) eq(errors, nvim.nvim_get_vvar('errors')) diff --git a/test/functional/legacy/autochdir_spec.lua b/test/functional/legacy/autochdir_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, eq, matches = helpers.clear, helpers.eq, helpers.matches -local eval, command, call, api = helpers.eval, helpers.command, helpers.call, helpers.api -local source, exec_capture = helpers.source, helpers.exec_capture -local mkdir = helpers.mkdir +local t = require('test.functional.testutil')(after_each) +local clear, eq, matches = t.clear, t.eq, t.matches +local eval, command, call, api = t.eval, t.command, t.call, t.api +local source, exec_capture = t.source, t.exec_capture +local mkdir = t.mkdir local function expected_empty() eq({}, api.nvim_get_vvar('errors')) @@ -18,7 +18,7 @@ describe('autochdir behavior', function() end) after_each(function() - helpers.rmdir(dir) + t.rmdir(dir) end) -- Tests vim/vim#777 without test_autochdir(). diff --git a/test/functional/legacy/autocmd_option_spec.lua b/test/functional/legacy/autocmd_option_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local nvim = helpers.api -local clear, eq, neq, eval = helpers.clear, helpers.eq, helpers.neq, helpers.eval -local api = helpers.api -local curbuf = helpers.api.nvim_get_current_buf -local curwin = helpers.api.nvim_get_current_win -local exec_capture = helpers.exec_capture -local source, command = helpers.source, helpers.command +local t = require('test.functional.testutil')(after_each) +local nvim = t.api +local clear, eq, neq, eval = t.clear, t.eq, t.neq, t.eval +local api = t.api +local curbuf = t.api.nvim_get_current_buf +local curwin = t.api.nvim_get_current_win +local exec_capture = t.exec_capture +local source, command = t.source, t.command local function declare_hook_function() source([[ diff --git a/test/functional/legacy/autocmd_spec.lua b/test/functional/legacy/autocmd_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local write_file = helpers.write_file -local command = helpers.command -local feed = helpers.feed -local api = helpers.api -local eq = helpers.eq +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local write_file = t.write_file +local command = t.command +local feed = t.feed +local api = t.api +local eq = t.eq before_each(clear) diff --git a/test/functional/legacy/autoformat_join_spec.lua b/test/functional/legacy/autoformat_join_spec.lua @@ -1,9 +1,9 @@ -- Tests for setting the '[,'] marks when joining lines. -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local command, expect = helpers.command, helpers.expect -local poke_eventloop = helpers.poke_eventloop +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local command, expect = t.command, t.expect +local poke_eventloop = t.poke_eventloop describe('autoformat join', function() setup(clear) diff --git a/test/functional/legacy/breakindent_spec.lua b/test/functional/legacy/breakindent_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local exec = helpers.exec -local feed = helpers.feed +local clear = t.clear +local command = t.command +local exec = t.exec +local feed = t.feed before_each(clear) diff --git a/test/functional/legacy/changelist_spec.lua b/test/functional/legacy/changelist_spec.lua @@ -1,9 +1,9 @@ -- Test changelist position after splitting window -- Set 'undolevels' to make changelist for sourced file -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local feed_command, expect = helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local feed_command, expect = t.feed_command, t.expect describe('changelist', function() setup(clear) diff --git a/test/functional/legacy/charsearch_spec.lua b/test/functional/legacy/charsearch_spec.lua @@ -1,8 +1,8 @@ -- Test for character searches -local helpers = require('test.functional.helpers')(after_each) -local feed, insert = helpers.feed, helpers.insert -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local feed, insert = t.feed, t.insert +local clear, feed_command, expect = t.clear, t.feed_command, t.expect describe('charsearch', function() setup(clear) diff --git a/test/functional/legacy/close_count_spec.lua b/test/functional/legacy/close_count_spec.lua @@ -1,13 +1,13 @@ -- Tests for :[count]close! and :[count]hide -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local poke_eventloop = helpers.poke_eventloop -local eval = helpers.eval -local feed = helpers.feed -local clear = helpers.clear -local command = helpers.command +local eq = t.eq +local poke_eventloop = t.poke_eventloop +local eval = t.eval +local feed = t.feed +local clear = t.clear +local command = t.command describe('close_count', function() setup(clear) diff --git a/test/functional/legacy/cmdline_spec.lua b/test/functional/legacy/cmdline_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local feed = helpers.feed -local feed_command = helpers.feed_command -local exec = helpers.exec -local api = helpers.api +local clear = t.clear +local command = t.command +local feed = t.feed +local feed_command = t.feed_command +local exec = t.exec +local api = t.api local pesc = vim.pesc describe('cmdline', function() diff --git a/test/functional/legacy/command_count_spec.lua b/test/functional/legacy/command_count_spec.lua @@ -1,8 +1,8 @@ -- Test for user command counts -local helpers = require('test.functional.helpers')(after_each) -local clear, source, expect = helpers.clear, helpers.source, helpers.expect -local feed_command = helpers.feed_command +local t = require('test.functional.testutil')(after_each) +local clear, source, expect = t.clear, t.source, t.expect +local feed_command = t.feed_command -- luacheck: ignore 613 (Trailing whitespace in a string) describe('command_count', function() diff --git a/test/functional/legacy/comparators_spec.lua b/test/functional/legacy/comparators_spec.lua @@ -1,8 +1,8 @@ -- " Test for expression comparators. -local helpers = require('test.functional.helpers')(after_each) -local clear, eq = helpers.clear, helpers.eq -local eval, command = helpers.eval, helpers.command +local t = require('test.functional.testutil')(after_each) +local clear, eq = t.clear, t.eq +local eval, command = t.eval, t.command describe('comparators', function() before_each(clear) diff --git a/test/functional/legacy/conceal_spec.lua b/test/functional/legacy/conceal_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local exec = helpers.exec -local feed = helpers.feed -local api = helpers.api +local clear = t.clear +local command = t.command +local exec = t.exec +local feed = t.feed +local api = t.api local expect_pos = function(row, col) - return helpers.eq({ row, col }, helpers.eval('[screenrow(), screencol()]')) + return t.eq({ row, col }, t.eval('[screenrow(), screencol()]')) end describe('Conceal', function() diff --git a/test/functional/legacy/cpoptions_spec.lua b/test/functional/legacy/cpoptions_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local feed = helpers.feed +local clear = t.clear +local command = t.command +local feed = t.feed before_each(clear) diff --git a/test/functional/legacy/crash_spec.lua b/test/functional/legacy/crash_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local assert_alive = helpers.assert_alive -local clear = helpers.clear -local command = helpers.command -local feed = helpers.feed +local t = require('test.functional.testutil')(after_each) +local assert_alive = t.assert_alive +local clear = t.clear +local command = t.command +local feed = t.feed before_each(clear) diff --git a/test/functional/legacy/debugger_spec.lua b/test/functional/legacy/debugger_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local feed = helpers.feed -local write_file = helpers.write_file +local clear = t.clear +local command = t.command +local feed = t.feed +local write_file = t.write_file before_each(clear) diff --git a/test/functional/legacy/delete_spec.lua b/test/functional/legacy/delete_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, source = helpers.clear, helpers.source -local eq, eval, command = helpers.eq, helpers.eval, helpers.command -local exc_exec = helpers.exc_exec +local t = require('test.functional.testutil')(after_each) +local clear, source = t.clear, t.source +local eq, eval, command = t.eq, t.eval, t.command +local exc_exec = t.exc_exec describe('Test for delete()', function() before_each(clear) @@ -48,7 +48,7 @@ describe('Test for delete()', function() it('symlink directory delete', function() command("call mkdir('Xdir1')") - if helpers.is_os('win') then + if t.is_os('win') then command('silent !mklink /j Xlink Xdir1') else command('silent !ln -s Xdir1 Xlink') diff --git a/test/functional/legacy/digraph_spec.lua b/test/functional/legacy/digraph_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local feed = helpers.feed +local clear = t.clear +local feed = t.feed before_each(clear) diff --git a/test/functional/legacy/display_spec.lua b/test/functional/legacy/display_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local exec = helpers.exec -local feed = helpers.feed -local command = helpers.command +local clear = t.clear +local exec = t.exec +local feed = t.feed +local command = t.command describe('display', function() before_each(clear) diff --git a/test/functional/legacy/edit_spec.lua b/test/functional/legacy/edit_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local expect = helpers.expect -local feed = helpers.feed +local clear = t.clear +local command = t.command +local expect = t.expect +local feed = t.feed local sleep = vim.uv.sleep before_each(clear) diff --git a/test/functional/legacy/erasebackword_spec.lua b/test/functional/legacy/erasebackword_spec.lua @@ -1,7 +1,7 @@ -- Test for CTRL-W in Insert mode -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, expect = helpers.clear, helpers.feed, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, expect = t.clear, t.feed, t.expect describe('CTRL-W in Insert mode', function() setup(clear) diff --git a/test/functional/legacy/eval_spec.lua b/test/functional/legacy/eval_spec.lua @@ -1,13 +1,13 @@ -- Test for various eval features. -local helpers = require('test.functional.helpers')(after_each) -local assert_alive = helpers.assert_alive -local feed, insert, source = helpers.feed, helpers.insert, helpers.source -local clear, command, expect = helpers.clear, helpers.command, helpers.expect -local eq, eval, write_file = helpers.eq, helpers.eval, helpers.write_file -local poke_eventloop = helpers.poke_eventloop -local exc_exec = helpers.exc_exec -local dedent = helpers.dedent +local t = require('test.functional.testutil')(after_each) +local assert_alive = t.assert_alive +local feed, insert, source = t.feed, t.insert, t.source +local clear, command, expect = t.clear, t.command, t.expect +local eq, eval, write_file = t.eq, t.eval, t.write_file +local poke_eventloop = t.poke_eventloop +local exc_exec = t.exc_exec +local dedent = t.dedent describe('eval', function() setup(function() diff --git a/test/functional/legacy/ex_mode_spec.lua b/test/functional/legacy/ex_mode_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval -local feed = helpers.feed -local api = helpers.api -local poke_eventloop = helpers.poke_eventloop +local clear = t.clear +local command = t.command +local eq = t.eq +local eval = t.eval +local feed = t.feed +local api = t.api +local poke_eventloop = t.poke_eventloop before_each(clear) diff --git a/test/functional/legacy/excmd_spec.lua b/test/functional/legacy/excmd_spec.lua @@ -1,18 +1,18 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local exec = helpers.exec -local exec_lua = helpers.exec_lua -local expect_exit = helpers.expect_exit -local feed = helpers.feed -local fn = helpers.fn -local api = helpers.api -local read_file = helpers.read_file -local source = helpers.source -local eq = helpers.eq -local write_file = helpers.write_file -local is_os = helpers.is_os +local clear = t.clear +local command = t.command +local exec = t.exec +local exec_lua = t.exec_lua +local expect_exit = t.expect_exit +local feed = t.feed +local fn = t.fn +local api = t.api +local read_file = t.read_file +local source = t.source +local eq = t.eq +local write_file = t.write_file +local is_os = t.is_os local function sizeoflong() if not exec_lua('return pcall(require, "ffi")') then diff --git a/test/functional/legacy/fixeol_spec.lua b/test/functional/legacy/fixeol_spec.lua @@ -1,8 +1,8 @@ -- Tests for 'fixeol' -local helpers = require('test.functional.helpers')(after_each) -local feed = helpers.feed -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local feed = t.feed +local clear, feed_command, expect = t.clear, t.feed_command, t.expect describe('fixeol', function() local function rmtestfiles() diff --git a/test/functional/legacy/fnamemodify_spec.lua b/test/functional/legacy/fnamemodify_spec.lua @@ -1,8 +1,8 @@ -- Test filename modifiers. -local helpers = require('test.functional.helpers')(after_each) -local clear, source = helpers.clear, helpers.source -local call, eq, nvim = helpers.call, helpers.eq, helpers.api +local t = require('test.functional.testutil')(after_each) +local clear, source = t.clear, t.source +local call, eq, nvim = t.call, t.eq, t.api local function expected_empty() eq({}, nvim.nvim_get_vvar('errors')) diff --git a/test/functional/legacy/fold_spec.lua b/test/functional/legacy/fold_spec.lua @@ -1,17 +1,16 @@ -- Tests for folding. local Screen = require('test.functional.ui.screen') -local helpers = require('test.functional.helpers')(after_each) -local feed, insert, feed_command, expect_any = - helpers.feed, helpers.insert, helpers.feed_command, helpers.expect_any -local command = helpers.command -local exec = helpers.exec +local t = require('test.functional.testutil')(after_each) +local feed, insert, feed_command, expect_any = t.feed, t.insert, t.feed_command, t.expect_any +local command = t.command +local exec = t.exec describe('folding', function() local screen before_each(function() - helpers.clear() + t.clear() screen = Screen.new(45, 8) screen:attach() @@ -61,7 +60,7 @@ describe('folding', function() feed('kYpj') feed_command('call append("$", foldlevel("."))') - helpers.poke_eventloop() + t.poke_eventloop() screen:expect([[ dd {{{ | ee {{{ }}} | @@ -87,7 +86,7 @@ describe('folding', function() feed_command('call append("$", foldlevel(2))') feed('zR') - helpers.poke_eventloop() + t.poke_eventloop() screen:expect([[ aa | bb | diff --git a/test/functional/legacy/function_sort_spec.lua b/test/functional/legacy/function_sort_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) - -local eq = helpers.eq -local neq = helpers.neq -local eval = helpers.eval -local clear = helpers.clear -local source = helpers.source -local exc_exec = helpers.exc_exec +local t = require('test.functional.testutil')(after_each) + +local eq = t.eq +local neq = t.neq +local eval = t.eval +local clear = t.clear +local source = t.source +local exc_exec = t.exc_exec describe('sort', function() before_each(clear) diff --git a/test/functional/legacy/getcwd_spec.lua b/test/functional/legacy/getcwd_spec.lua @@ -1,14 +1,14 @@ -- Tests for getcwd(), haslocaldir(), and :lcd -local helpers = require('test.functional.helpers')(after_each) -local eq, eval, source = helpers.eq, helpers.eval, helpers.source -local call, clear, command = helpers.call, helpers.clear, helpers.command +local t = require('test.functional.testutil')(after_each) +local eq, eval, source = t.eq, t.eval, t.source +local call, clear, command = t.call, t.clear, t.command describe('getcwd', function() before_each(clear) after_each(function() - helpers.rmdir('Xtopdir') + t.rmdir('Xtopdir') end) it('is working', function() diff --git a/test/functional/legacy/gf_spec.lua b/test/functional/legacy/gf_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local pcall_err = helpers.pcall_err +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local eq = t.eq +local pcall_err = t.pcall_err describe('gf', function() before_each(clear) diff --git a/test/functional/legacy/glob2regpat_spec.lua b/test/functional/legacy/glob2regpat_spec.lua @@ -1,6 +1,6 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq, eval = helpers.eq, helpers.eval +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eq, eval = t.eq, t.eval describe('glob2regpat()', function() before_each(clear) diff --git a/test/functional/legacy/global_spec.lua b/test/functional/legacy/global_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local exec = helpers.exec -local feed = helpers.feed -local poke_eventloop = helpers.poke_eventloop +local clear = t.clear +local exec = t.exec +local feed = t.feed +local poke_eventloop = t.poke_eventloop before_each(clear) diff --git a/test/functional/legacy/highlight_spec.lua b/test/functional/legacy/highlight_spec.lua @@ -1,12 +1,12 @@ local Screen = require('test.functional.ui.screen') -local helpers = require('test.functional.helpers')(after_each) -local clear, feed = helpers.clear, helpers.feed -local expect = helpers.expect -local eq = helpers.eq -local poke_eventloop = helpers.poke_eventloop -local exc_exec = helpers.exc_exec -local feed_command = helpers.feed_command -local exec = helpers.exec +local t = require('test.functional.testutil')(after_each) +local clear, feed = t.clear, t.feed +local expect = t.expect +local eq = t.eq +local poke_eventloop = t.poke_eventloop +local exc_exec = t.exc_exec +local feed_command = t.feed_command +local exec = t.exec before_each(clear) diff --git a/test/functional/legacy/increment_spec.lua b/test/functional/legacy/increment_spec.lua @@ -1,9 +1,9 @@ -- Tests for using Ctrl-A/Ctrl-X on visual selections -local helpers = require('test.functional.helpers')(after_each) -local source, command = helpers.source, helpers.command -local call, clear = helpers.call, helpers.clear -local eq, nvim = helpers.eq, helpers.api +local t = require('test.functional.testutil')(after_each) +local source, command = t.source, t.command +local call, clear = t.call, t.clear +local eq, nvim = t.eq, t.api describe('Ctrl-A/Ctrl-X on visual selections', function() before_each(function() diff --git a/test/functional/legacy/insertcount_spec.lua b/test/functional/legacy/insertcount_spec.lua @@ -1,8 +1,8 @@ -- Tests for repeating insert and replace. -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local feed_command, expect = helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local feed_command, expect = t.feed_command, t.expect describe('insertcount', function() setup(clear) diff --git a/test/functional/legacy/join_spec.lua b/test/functional/legacy/join_spec.lua @@ -1,8 +1,8 @@ -- Test for joining lines -local helpers = require('test.functional.helpers')(after_each) -local clear, eq = helpers.clear, helpers.eq -local eval, command = helpers.eval, helpers.command +local t = require('test.functional.testutil')(after_each) +local clear, eq = t.clear, t.eq +local eval, command = t.eval, t.command describe('joining lines', function() before_each(clear) diff --git a/test/functional/legacy/lispwords_spec.lua b/test/functional/legacy/lispwords_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local eval = helpers.eval -local command = helpers.command -local source = helpers.source +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eq = t.eq +local eval = t.eval +local command = t.command +local source = t.source describe('lispwords', function() before_each(clear) diff --git a/test/functional/legacy/listchars_spec.lua b/test/functional/legacy/listchars_spec.lua @@ -1,9 +1,9 @@ -- Tests for 'listchars' display with 'list' and :list. -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local feed, insert, exec = helpers.feed, helpers.insert, helpers.exec -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local feed, insert, exec = t.feed, t.insert, t.exec +local clear, feed_command, expect = t.clear, t.feed_command, t.expect -- luacheck: ignore 621 (Indentation) describe("'listchars'", function() diff --git a/test/functional/legacy/listlbr_spec.lua b/test/functional/legacy/listlbr_spec.lua @@ -1,9 +1,9 @@ -- Test for linebreak and list option (non-utf8) -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local feed, insert, source = helpers.feed, helpers.insert, helpers.source -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local feed, insert, source = t.feed, t.insert, t.source +local clear, feed_command, expect = t.clear, t.feed_command, t.expect describe('listlbr', function() before_each(clear) diff --git a/test/functional/legacy/listlbr_utf8_spec.lua b/test/functional/legacy/listlbr_utf8_spec.lua @@ -1,11 +1,11 @@ -- Test for linebreak and list option in utf-8 mode -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local source = helpers.source -local feed = helpers.feed -local exec = helpers.exec -local clear, expect = helpers.clear, helpers.expect +local source = t.source +local feed = t.feed +local exec = t.exec +local clear, expect = t.clear, t.expect describe('linebreak', function() before_each(clear) diff --git a/test/functional/legacy/mapping_spec.lua b/test/functional/legacy/mapping_spec.lua @@ -1,9 +1,9 @@ -- Test for mappings and abbreviations -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local expect, poke_eventloop = helpers.expect, helpers.poke_eventloop -local command, eq, eval, api = helpers.command, helpers.eq, helpers.eval, helpers.api +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local expect, poke_eventloop = t.expect, t.poke_eventloop +local command, eq, eval, api = t.command, t.eq, t.eval, t.api local sleep = vim.uv.sleep describe('mapping', function() diff --git a/test/functional/legacy/marks_spec.lua b/test/functional/legacy/marks_spec.lua @@ -1,6 +1,6 @@ -local helpers = require('test.functional.helpers')(after_each) -local feed, insert, source = helpers.feed, helpers.insert, helpers.source -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local feed, insert, source = t.feed, t.insert, t.source +local clear, feed_command, expect = t.clear, t.feed_command, t.expect describe('marks', function() before_each(function() diff --git a/test/functional/legacy/match_spec.lua b/test/functional/legacy/match_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local exec = helpers.exec -local feed = helpers.feed +local clear = t.clear +local exec = t.exec +local feed = t.feed before_each(clear) diff --git a/test/functional/legacy/matchparen_spec.lua b/test/functional/legacy/matchparen_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local exec = helpers.exec -local feed = helpers.feed +local clear = t.clear +local exec = t.exec +local feed = t.feed describe('matchparen', function() before_each(clear) diff --git a/test/functional/legacy/memory_usage_spec.lua b/test/functional/legacy/memory_usage_spec.lua @@ -1,17 +1,17 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eval = helpers.eval -local eq = helpers.eq -local feed_command = helpers.feed_command -local retry = helpers.retry -local ok = helpers.ok -local source = helpers.source -local poke_eventloop = helpers.poke_eventloop -local load_adjust = helpers.load_adjust -local write_file = helpers.write_file -local is_os = helpers.is_os -local is_ci = helpers.is_ci -local is_asan = helpers.is_asan +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eval = t.eval +local eq = t.eq +local feed_command = t.feed_command +local retry = t.retry +local ok = t.ok +local source = t.source +local poke_eventloop = t.poke_eventloop +local load_adjust = t.load_adjust +local write_file = t.write_file +local is_os = t.is_os +local is_ci = t.is_ci +local is_asan = t.is_asan clear() if is_asan() then diff --git a/test/functional/legacy/messages_spec.lua b/test/functional/legacy/messages_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local exec = helpers.exec -local feed = helpers.feed -local api = helpers.api -local nvim_dir = helpers.nvim_dir -local assert_alive = helpers.assert_alive +local clear = t.clear +local command = t.command +local exec = t.exec +local feed = t.feed +local api = t.api +local nvim_dir = t.nvim_dir +local assert_alive = t.assert_alive before_each(clear) diff --git a/test/functional/legacy/mksession_spec.lua b/test/functional/legacy/mksession_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local fn = helpers.fn -local eq = helpers.eq +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local fn = t.fn +local eq = t.eq describe('mksession', function() before_each(clear) diff --git a/test/functional/legacy/move_spec.lua b/test/functional/legacy/move_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local feed = helpers.feed -local fn = helpers.fn +local clear = t.clear +local feed = t.feed +local fn = t.fn before_each(clear) diff --git a/test/functional/legacy/nested_function_spec.lua b/test/functional/legacy/nested_function_spec.lua @@ -1,8 +1,8 @@ -- Tests for nested function. -local helpers = require('test.functional.helpers')(after_each) -local clear, insert = helpers.clear, helpers.insert -local command, expect, source = helpers.command, helpers.expect, helpers.source +local t = require('test.functional.testutil')(after_each) +local clear, insert = t.clear, t.insert +local command, expect, source = t.command, t.expect, t.source describe('test_nested_function', function() setup(clear) diff --git a/test/functional/legacy/normal_spec.lua b/test/functional/legacy/normal_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local exec = helpers.exec -local feed = helpers.feed -local api = helpers.api -local eq = helpers.eq -local fn = helpers.fn +local clear = t.clear +local exec = t.exec +local feed = t.feed +local api = t.api +local eq = t.eq +local fn = t.fn describe('normal', function() local screen diff --git a/test/functional/legacy/number_spec.lua b/test/functional/legacy/number_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local exec = helpers.exec -local feed = helpers.feed +local clear = t.clear +local command = t.command +local exec = t.exec +local feed = t.feed describe("'number' and 'relativenumber'", function() before_each(clear) diff --git a/test/functional/legacy/options_spec.lua b/test/functional/legacy/options_spec.lua @@ -1,9 +1,9 @@ -- See also: test/old/testdir/test_options.vim -local helpers = require('test.functional.helpers')(after_each) -local command, clear = helpers.command, helpers.clear -local source, expect = helpers.source, helpers.expect -local exc_exec = helpers.exc_exec -local matches = helpers.matches +local t = require('test.functional.testutil')(after_each) +local command, clear = t.command, t.clear +local source, expect = t.source, t.expect +local exc_exec = t.exc_exec +local matches = t.matches local Screen = require('test.functional.ui.screen') describe('options', function() diff --git a/test/functional/legacy/prompt_buffer_spec.lua b/test/functional/legacy/prompt_buffer_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local feed = helpers.feed -local source = helpers.source -local clear = helpers.clear -local command = helpers.command -local expect = helpers.expect -local poke_eventloop = helpers.poke_eventloop -local api = helpers.api -local eq = helpers.eq -local neq = helpers.neq +local feed = t.feed +local source = t.source +local clear = t.clear +local command = t.command +local expect = t.expect +local poke_eventloop = t.poke_eventloop +local api = t.api +local eq = t.eq +local neq = t.neq describe('prompt buffer', function() local screen diff --git a/test/functional/legacy/put_spec.lua b/test/functional/legacy/put_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local exec_lua = helpers.exec_lua -local api = helpers.api -local source = helpers.source -local eq = helpers.eq +local clear = t.clear +local exec_lua = t.exec_lua +local api = t.api +local source = t.source +local eq = t.eq local function sizeoflong() if not exec_lua('return pcall(require, "ffi")') then diff --git a/test/functional/legacy/qf_title_spec.lua b/test/functional/legacy/qf_title_spec.lua @@ -1,8 +1,8 @@ -- Tests for quickfix window's title -local helpers = require('test.functional.helpers')(after_each) -local insert, source = helpers.insert, helpers.source -local clear, expect = helpers.clear, helpers.expect +local t = require('test.functional.testutil')(after_each) +local insert, source = t.insert, t.source +local clear, expect = t.clear, t.expect describe('qf_title', function() setup(clear) diff --git a/test/functional/legacy/scroll_opt_spec.lua b/test/functional/legacy/scroll_opt_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local exec = helpers.exec -local feed = helpers.feed -local assert_alive = helpers.assert_alive +local clear = t.clear +local exec = t.exec +local feed = t.feed +local assert_alive = t.assert_alive before_each(clear) diff --git a/test/functional/legacy/search_mbyte_spec.lua b/test/functional/legacy/search_mbyte_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local poke_eventloop = helpers.poke_eventloop -local clear = helpers.clear -local insert = helpers.insert -local expect = helpers.expect -local command = helpers.command +local poke_eventloop = t.poke_eventloop +local clear = t.clear +local insert = t.insert +local expect = t.expect +local command = t.command describe('search_mbyte', function() before_each(clear) diff --git a/test/functional/legacy/search_spec.lua b/test/functional/legacy/search_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval -local feed = helpers.feed -local fn = helpers.fn -local poke_eventloop = helpers.poke_eventloop -local exec = helpers.exec +local clear = t.clear +local command = t.command +local eq = t.eq +local eval = t.eval +local feed = t.feed +local fn = t.fn +local poke_eventloop = t.poke_eventloop +local exec = t.exec describe('search cmdline', function() local screen diff --git a/test/functional/legacy/search_stat_spec.lua b/test/functional/legacy/search_stat_spec.lua @@ -1,6 +1,6 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, exec, command = helpers.clear, helpers.feed, helpers.exec, helpers.command +local clear, feed, exec, command = t.clear, t.feed, t.exec, t.command describe('search stat', function() local screen diff --git a/test/functional/legacy/signs_spec.lua b/test/functional/legacy/signs_spec.lua @@ -1,7 +1,7 @@ -- Tests for signs -local helpers = require('test.functional.helpers')(after_each) -local clear, command, expect = helpers.clear, helpers.command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, command, expect = t.clear, t.command, t.expect describe('signs', function() setup(clear) diff --git a/test/functional/legacy/source_spec.lua b/test/functional/legacy/source_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local feed = helpers.feed -local write_file = helpers.write_file +local clear = t.clear +local feed = t.feed +local write_file = t.write_file before_each(clear) diff --git a/test/functional/legacy/statusline_spec.lua b/test/functional/legacy/statusline_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local exec = helpers.exec -local feed = helpers.feed +local clear = t.clear +local exec = t.exec +local feed = t.feed before_each(clear) diff --git a/test/functional/legacy/substitute_spec.lua b/test/functional/legacy/substitute_spec.lua @@ -2,12 +2,12 @@ -- Test for submatch() on substitute(). -- Test for *:s%* on :substitute. -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local feed, insert = helpers.feed, helpers.insert -local exec = helpers.exec -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect -local eq, eval = helpers.eq, helpers.eval +local feed, insert = t.feed, t.insert +local exec = t.exec +local clear, feed_command, expect = t.clear, t.feed_command, t.expect +local eq, eval = t.eq, t.eval describe('substitute()', function() before_each(clear) diff --git a/test/functional/legacy/syn_attr_spec.lua b/test/functional/legacy/syn_attr_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local eq = t.eq +local eval = t.eval -- oldtest: Test_missing_attr() describe('synIDattr()', function() diff --git a/test/functional/legacy/tabline_spec.lua b/test/functional/legacy/tabline_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local exec = helpers.exec -local feed = helpers.feed +local clear = t.clear +local exec = t.exec +local feed = t.feed before_each(clear) diff --git a/test/functional/legacy/tagcase_spec.lua b/test/functional/legacy/tagcase_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local eval = helpers.eval -local exc_exec = helpers.exc_exec -local expect = helpers.expect -local insert = helpers.insert -local source = helpers.source -local write_file = helpers.write_file +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eq = t.eq +local eval = t.eval +local exc_exec = t.exc_exec +local expect = t.expect +local insert = t.insert +local source = t.source +local write_file = t.write_file describe("'tagcase' option", function() setup(function() diff --git a/test/functional/legacy/textobjects_spec.lua b/test/functional/legacy/textobjects_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) -local call = helpers.call -local clear = helpers.clear -local command = helpers.command -local expect = helpers.expect -local source = helpers.source +local t = require('test.functional.testutil')(after_each) +local call = t.call +local clear = t.clear +local command = t.command +local expect = t.expect +local source = t.source describe('Text object', function() before_each(function() diff --git a/test/functional/legacy/undolevels_spec.lua b/test/functional/legacy/undolevels_spec.lua @@ -1,6 +1,6 @@ -local helpers = require('test.functional.helpers')(after_each) -local source, clear = helpers.source, helpers.clear -local eq, nvim = helpers.eq, helpers.api +local t = require('test.functional.testutil')(after_each) +local source, clear = t.source, t.clear +local eq, nvim = t.eq, t.api describe('undolevel', function() setup(clear) diff --git a/test/functional/legacy/utf8_spec.lua b/test/functional/legacy/utf8_spec.lua @@ -1,11 +1,11 @@ -- Tests for Unicode manipulations -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local command, expect = helpers.command, helpers.expect -local eq, eval = helpers.eq, helpers.eval -local source = helpers.source -local poke_eventloop = helpers.poke_eventloop +local t = require('test.functional.testutil')(after_each) +local clear, feed, insert = t.clear, t.feed, t.insert +local command, expect = t.command, t.expect +local eq, eval = t.eq, t.eval +local source = t.source +local poke_eventloop = t.poke_eventloop describe('utf8', function() before_each(clear) diff --git a/test/functional/legacy/vimscript_spec.lua b/test/functional/legacy/vimscript_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local exec = helpers.exec -local feed = helpers.feed -local api = helpers.api +local clear = t.clear +local exec = t.exec +local feed = t.feed +local api = t.api before_each(clear) diff --git a/test/functional/legacy/visual_spec.lua b/test/functional/legacy/visual_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local feed = helpers.feed -local exec = helpers.exec +local clear = t.clear +local feed = t.feed +local exec = t.exec before_each(clear) diff --git a/test/functional/legacy/window_cmd_spec.lua b/test/functional/legacy/window_cmd_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local exec = helpers.exec -local exec_lua = helpers.exec_lua -local command = helpers.command -local feed = helpers.feed +local clear = t.clear +local exec = t.exec +local exec_lua = t.exec_lua +local command = t.command +local feed = t.feed -- oldtest: Test_window_cmd_ls0_split_scrolling() it('scrolling with laststatus=0 and :botright split', function() diff --git a/test/functional/legacy/wordcount_spec.lua b/test/functional/legacy/wordcount_spec.lua @@ -1,10 +1,10 @@ -- Test for wordcount() function -local helpers = require('test.functional.helpers')(after_each) -local feed, insert, source = helpers.feed, helpers.insert, helpers.source -local clear, command = helpers.clear, helpers.command -local eq, eval = helpers.eq, helpers.eval -local poke_eventloop = helpers.poke_eventloop +local t = require('test.functional.testutil')(after_each) +local feed, insert, source = t.feed, t.insert, t.source +local clear, command = t.clear, t.command +local eq, eval = t.eq, t.eval +local poke_eventloop = t.poke_eventloop describe('wordcount', function() before_each(clear) diff --git a/test/functional/legacy/writefile_spec.lua b/test/functional/legacy/writefile_spec.lua @@ -1,7 +1,7 @@ -- Tests for writefile() -local helpers = require('test.functional.helpers')(after_each) -local clear, command, expect = helpers.clear, helpers.command, helpers.expect +local t = require('test.functional.testutil')(after_each) +local clear, command, expect = t.clear, t.command, t.expect describe('writefile', function() setup(clear) diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua @@ -1,15 +1,15 @@ -- Test suite for testing interactions with API bindings -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local exc_exec = helpers.exc_exec -local remove_trace = helpers.remove_trace -local fn = helpers.fn -local clear = helpers.clear -local eval = helpers.eval +local exc_exec = t.exc_exec +local remove_trace = t.remove_trace +local fn = t.fn +local clear = t.clear +local eval = t.eval local NIL = vim.NIL -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local pcall_err = helpers.pcall_err +local eq = t.eq +local exec_lua = t.exec_lua +local pcall_err = t.pcall_err before_each(clear) diff --git a/test/functional/lua/base64_spec.lua b/test/functional/lua/base64_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local exec_lua = helpers.exec_lua -local eq = helpers.eq -local pcall_err = helpers.pcall_err -local matches = helpers.matches +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local exec_lua = t.exec_lua +local eq = t.eq +local pcall_err = t.pcall_err +local matches = t.matches describe('vim.base64', function() before_each(clear) diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua @@ -1,18 +1,18 @@ -- Test suite for testing interactions with API bindings -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local command = helpers.command -local api = helpers.api -local fn = helpers.fn -local clear = helpers.clear -local eq = helpers.eq -local fail = helpers.fail -local exec_lua = helpers.exec_lua -local feed = helpers.feed -local expect_events = helpers.expect_events -local write_file = helpers.write_file -local dedent = helpers.dedent +local command = t.command +local api = t.api +local fn = t.fn +local clear = t.clear +local eq = t.eq +local fail = t.fail +local exec_lua = t.exec_lua +local feed = t.feed +local expect_events = t.expect_events +local write_file = t.write_file +local dedent = t.dedent local origlines = { 'original line 1', @@ -292,11 +292,11 @@ describe('lua buffer event callbacks: on_lines', function() exec_lua(code) command('q!') - helpers.assert_alive() + t.assert_alive() exec_lua(code) command('bd!') - helpers.assert_alive() + t.assert_alive() end) it('#12718 lnume', function() @@ -965,7 +965,7 @@ describe('lua: nvim_buf_attach on_bytes', function() command('e! Xtest-undofile') command('set undodir=. | set undofile') - local ns = helpers.request('nvim_create_namespace', 'ns1') + local ns = t.request('nvim_create_namespace', 'ns1') api.nvim_buf_set_extmark(0, ns, 0, 0, {}) eq({ '12345', 'hello world' }, api.nvim_buf_get_lines(0, 0, -1, true)) diff --git a/test/functional/lua/command_line_completion_spec.lua b/test/functional/lua/command_line_completion_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local exec_lua = helpers.exec_lua +local clear = t.clear +local eq = t.eq +local exec_lua = t.exec_lua local get_completions = function(input, env) return exec_lua('return {vim._expand_pat(...)}', input, env) diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua @@ -1,24 +1,24 @@ -- Test suite for checking :lua* commands -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local eq = helpers.eq +local eq = t.eq local NIL = vim.NIL -local eval = helpers.eval -local feed = helpers.feed -local clear = helpers.clear -local matches = helpers.matches -local api = helpers.api -local exec_lua = helpers.exec_lua -local exec_capture = helpers.exec_capture -local fn = helpers.fn -local source = helpers.source -local dedent = helpers.dedent -local command = helpers.command -local exc_exec = helpers.exc_exec -local pcall_err = helpers.pcall_err -local write_file = helpers.write_file -local remove_trace = helpers.remove_trace +local eval = t.eval +local feed = t.feed +local clear = t.clear +local matches = t.matches +local api = t.api +local exec_lua = t.exec_lua +local exec_capture = t.exec_capture +local fn = t.fn +local source = t.source +local dedent = t.dedent +local command = t.command +local exc_exec = t.exc_exec +local pcall_err = t.pcall_err +local write_file = t.write_file +local remove_trace = t.remove_trace before_each(clear) diff --git a/test/functional/lua/comment_spec.lua b/test/functional/lua/comment_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) - -local api = helpers.api -local clear = helpers.clear -local eq = helpers.eq -local exec_capture = helpers.exec_capture -local exec_lua = helpers.exec_lua -local feed = helpers.feed +local t = require('test.functional.testutil')(after_each) + +local api = t.api +local clear = t.clear +local eq = t.eq +local exec_capture = t.exec_capture +local exec_lua = t.exec_lua +local feed = t.feed -- Reference text -- aa diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local NIL = vim.NIL -local command = helpers.command -local clear = helpers.clear -local exec_lua = helpers.exec_lua -local eq = helpers.eq -local matches = helpers.matches -local api = helpers.api -local pcall_err = helpers.pcall_err -local fn = helpers.fn +local command = t.command +local clear = t.clear +local exec_lua = t.exec_lua +local eq = t.eq +local matches = t.matches +local api = t.api +local pcall_err = t.pcall_err +local fn = t.fn describe('vim.diagnostic', function() before_each(function() @@ -1826,20 +1826,12 @@ describe('vim.diagnostic', function() it('respects legacy signs placed with :sign define or sign_define #26618', function() -- Legacy signs for diagnostics were deprecated in 0.10 and will be removed in 0.12 - eq(0, helpers.fn.has('nvim-0.12')) + eq(0, t.fn.has('nvim-0.12')) - helpers.command( - 'sign define DiagnosticSignError text= texthl= linehl=ErrorMsg numhl=ErrorMsg' - ) - helpers.command( - 'sign define DiagnosticSignWarn text= texthl= linehl=WarningMsg numhl=WarningMsg' - ) - helpers.command( - 'sign define DiagnosticSignInfo text= texthl= linehl=Underlined numhl=Underlined' - ) - helpers.command( - 'sign define DiagnosticSignHint text= texthl= linehl=Underlined numhl=Underlined' - ) + t.command('sign define DiagnosticSignError text= texthl= linehl=ErrorMsg numhl=ErrorMsg') + t.command('sign define DiagnosticSignWarn text= texthl= linehl=WarningMsg numhl=WarningMsg') + t.command('sign define DiagnosticSignInfo text= texthl= linehl=Underlined numhl=Underlined') + t.command('sign define DiagnosticSignHint text= texthl= linehl=Underlined numhl=Underlined') local result = exec_lua [[ vim.diagnostic.config({ diff --git a/test/functional/lua/ffi_spec.lua b/test/functional/lua/ffi_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local clear = helpers.clear +local t = require('test.functional.testutil')(after_each) +local eq = t.eq +local exec_lua = t.exec_lua +local clear = t.clear before_each(clear) diff --git a/test/functional/lua/filetype_spec.lua b/test/functional/lua/filetype_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) -local exec_lua = helpers.exec_lua -local eq = helpers.eq -local api = helpers.api -local clear = helpers.clear -local pathroot = helpers.pathroot -local command = helpers.command -local mkdir = helpers.mkdir -local rmdir = helpers.rmdir -local write_file = helpers.write_file +local t = require('test.functional.testutil')(after_each) +local exec_lua = t.exec_lua +local eq = t.eq +local api = t.api +local clear = t.clear +local pathroot = t.pathroot +local command = t.command +local mkdir = t.mkdir +local rmdir = t.rmdir +local write_file = t.write_file local uv = vim.uv local root = pathroot() diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua @@ -1,16 +1,16 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local exec_lua = helpers.exec_lua -local eq = helpers.eq -local mkdir_p = helpers.mkdir_p -local rmdir = helpers.rmdir -local nvim_dir = helpers.nvim_dir -local test_build_dir = helpers.paths.test_build_dir -local test_source_path = helpers.paths.test_source_path -local nvim_prog = helpers.nvim_prog -local is_os = helpers.is_os -local mkdir = helpers.mkdir +local t = require('test.functional.testutil')(after_each) + +local clear = t.clear +local exec_lua = t.exec_lua +local eq = t.eq +local mkdir_p = t.mkdir_p +local rmdir = t.rmdir +local nvim_dir = t.nvim_dir +local test_build_dir = t.paths.test_build_dir +local test_source_path = t.paths.test_source_path +local nvim_prog = t.nvim_prog +local is_os = t.is_os +local mkdir = t.mkdir local nvim_prog_basename = is_os('win') and 'nvim.exe' or 'nvim' diff --git a/test/functional/lua/glob_spec.lua b/test/functional/lua/glob_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq = helpers.eq -local exec_lua = helpers.exec_lua +local t = require('test.functional.testutil')(after_each) +local eq = t.eq +local exec_lua = t.exec_lua describe('glob', function() - before_each(helpers.clear) - after_each(helpers.clear) + before_each(t.clear) + after_each(t.clear) local match = function(...) return exec_lua( diff --git a/test/functional/lua/highlight_spec.lua b/test/functional/lua/highlight_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local exec_lua = helpers.exec_lua -local eq = helpers.eq -local neq = helpers.neq -local eval = helpers.eval -local command = helpers.command -local clear = helpers.clear -local api = helpers.api +local t = require('test.functional.testutil')(after_each) +local exec_lua = t.exec_lua +local eq = t.eq +local neq = t.neq +local eval = t.eval +local command = t.command +local clear = t.clear +local api = t.api describe('vim.highlight.on_yank', function() before_each(function() @@ -19,7 +19,7 @@ describe('vim.highlight.on_yank', function() vim.cmd('bwipeout!') ]]) vim.uv.sleep(10) - helpers.feed('<cr>') -- avoid hang if error message exists + t.feed('<cr>') -- avoid hang if error message exists eq('', eval('v:errmsg')) end) diff --git a/test/functional/lua/inspector_spec.lua b/test/functional/lua/inspector_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local exec_lua = helpers.exec_lua -local eq = helpers.eq -local eval = helpers.eval -local clear = helpers.clear +local t = require('test.functional.testutil')(after_each) +local exec_lua = t.exec_lua +local eq = t.eq +local eval = t.eval +local clear = t.clear describe('vim.inspect_pos', function() before_each(function() diff --git a/test/functional/lua/iter_spec.lua b/test/functional/lua/iter_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq = helpers.eq -local matches = helpers.matches -local pcall_err = helpers.pcall_err +local t = require('test.functional.testutil')(after_each) +local eq = t.eq +local matches = t.matches +local pcall_err = t.pcall_err describe('vim.iter', function() it('new() on iterable class instance', function() @@ -18,12 +18,12 @@ describe('vim.iter', function() return v % 2 ~= 0 end - local t = { 1, 2, 3, 4, 5 } - eq({ 1, 3, 5 }, vim.iter(t):filter(odd):totable()) + local q = { 1, 2, 3, 4, 5 } + eq({ 1, 3, 5 }, vim.iter(q):filter(odd):totable()) eq( { 2, 4 }, vim - .iter(t) + .iter(q) :filter(function(v) return not odd(v) end) @@ -32,7 +32,7 @@ describe('vim.iter', function() eq( {}, vim - .iter(t) + .iter(q) :filter(function(v) return v > 5 end) @@ -40,7 +40,7 @@ describe('vim.iter', function() ) do - local it = vim.iter(ipairs(t)) + local it = vim.iter(ipairs(q)) it:filter(function(i, v) return i > 1 and v < 5 end) @@ -60,11 +60,11 @@ describe('vim.iter', function() end) it('map()', function() - local t = { 1, 2, 3, 4, 5 } + local q = { 1, 2, 3, 4, 5 } eq( { 2, 4, 6, 8, 10 }, vim - .iter(t) + .iter(q) :map(function(v) return 2 * v end) @@ -96,10 +96,10 @@ describe('vim.iter', function() end) it('for loops', function() - local t = { 1, 2, 3, 4, 5 } + local q = { 1, 2, 3, 4, 5 } local acc = 0 for v in - vim.iter(t):map(function(v) + vim.iter(q):map(function(v) return v * 3 end) do @@ -146,13 +146,13 @@ describe('vim.iter', function() it('skip()', function() do - local t = { 4, 3, 2, 1 } - eq(t, vim.iter(t):skip(0):totable()) - eq({ 3, 2, 1 }, vim.iter(t):skip(1):totable()) - eq({ 2, 1 }, vim.iter(t):skip(2):totable()) - eq({ 1 }, vim.iter(t):skip(#t - 1):totable()) - eq({}, vim.iter(t):skip(#t):totable()) - eq({}, vim.iter(t):skip(#t + 1):totable()) + local q = { 4, 3, 2, 1 } + eq(q, vim.iter(q):skip(0):totable()) + eq({ 3, 2, 1 }, vim.iter(q):skip(1):totable()) + eq({ 2, 1 }, vim.iter(q):skip(2):totable()) + eq({ 1 }, vim.iter(q):skip(#q - 1):totable()) + eq({}, vim.iter(q):skip(#q):totable()) + eq({}, vim.iter(q):skip(#q + 1):totable()) end do @@ -170,13 +170,13 @@ describe('vim.iter', function() it('skipback()', function() do - local t = { 4, 3, 2, 1 } - eq(t, vim.iter(t):skipback(0):totable()) - eq({ 4, 3, 2 }, vim.iter(t):skipback(1):totable()) - eq({ 4, 3 }, vim.iter(t):skipback(2):totable()) - eq({ 4 }, vim.iter(t):skipback(#t - 1):totable()) - eq({}, vim.iter(t):skipback(#t):totable()) - eq({}, vim.iter(t):skipback(#t + 1):totable()) + local q = { 4, 3, 2, 1 } + eq(q, vim.iter(q):skipback(0):totable()) + eq({ 4, 3, 2 }, vim.iter(q):skipback(1):totable()) + eq({ 4, 3 }, vim.iter(q):skipback(2):totable()) + eq({ 4 }, vim.iter(q):skipback(#q - 1):totable()) + eq({}, vim.iter(q):skipback(#q):totable()) + eq({}, vim.iter(q):skipback(#q + 1):totable()) end local it = vim.iter(vim.gsplit('a|b|c|d', '|')) @@ -184,14 +184,14 @@ describe('vim.iter', function() end) it('slice()', function() - local t = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } - eq({ 3, 4, 5, 6, 7 }, vim.iter(t):slice(3, 7):totable()) - eq({}, vim.iter(t):slice(6, 5):totable()) - eq({}, vim.iter(t):slice(0, 0):totable()) - eq({ 1 }, vim.iter(t):slice(1, 1):totable()) - eq({ 1, 2 }, vim.iter(t):slice(1, 2):totable()) - eq({ 10 }, vim.iter(t):slice(10, 10):totable()) - eq({ 8, 9, 10 }, vim.iter(t):slice(8, 11):totable()) + local q = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } + eq({ 3, 4, 5, 6, 7 }, vim.iter(q):slice(3, 7):totable()) + eq({}, vim.iter(q):slice(6, 5):totable()) + eq({}, vim.iter(q):slice(0, 0):totable()) + eq({ 1 }, vim.iter(q):slice(1, 1):totable()) + eq({ 1, 2 }, vim.iter(q):slice(1, 2):totable()) + eq({ 10 }, vim.iter(q):slice(10, 10):totable()) + eq({ 8, 9, 10 }, vim.iter(q):slice(8, 11):totable()) local it = vim.iter(vim.gsplit('a|b|c|d', '|')) matches('slice%(%) requires a list%-like table', pcall_err(it.slice, it, 1, 3)) @@ -199,13 +199,13 @@ describe('vim.iter', function() it('nth()', function() do - local t = { 4, 3, 2, 1 } - eq(nil, vim.iter(t):nth(0)) - eq(4, vim.iter(t):nth(1)) - eq(3, vim.iter(t):nth(2)) - eq(2, vim.iter(t):nth(3)) - eq(1, vim.iter(t):nth(4)) - eq(nil, vim.iter(t):nth(5)) + local q = { 4, 3, 2, 1 } + eq(nil, vim.iter(q):nth(0)) + eq(4, vim.iter(q):nth(1)) + eq(3, vim.iter(q):nth(2)) + eq(2, vim.iter(q):nth(3)) + eq(1, vim.iter(q):nth(4)) + eq(nil, vim.iter(q):nth(5)) end do @@ -223,13 +223,13 @@ describe('vim.iter', function() it('nthback()', function() do - local t = { 4, 3, 2, 1 } - eq(nil, vim.iter(t):nthback(0)) - eq(1, vim.iter(t):nthback(1)) - eq(2, vim.iter(t):nthback(2)) - eq(3, vim.iter(t):nthback(3)) - eq(4, vim.iter(t):nthback(4)) - eq(nil, vim.iter(t):nthback(5)) + local q = { 4, 3, 2, 1 } + eq(nil, vim.iter(q):nthback(0)) + eq(1, vim.iter(q):nthback(1)) + eq(2, vim.iter(q):nthback(2)) + eq(3, vim.iter(q):nthback(3)) + eq(4, vim.iter(q):nthback(4)) + eq(nil, vim.iter(q):nthback(5)) end local it = vim.iter(vim.gsplit('a|b|c|d', '|')) @@ -238,24 +238,24 @@ describe('vim.iter', function() it('take()', function() do - local t = { 4, 3, 2, 1 } - eq({}, vim.iter(t):take(0):totable()) - eq({ 4 }, vim.iter(t):take(1):totable()) - eq({ 4, 3 }, vim.iter(t):take(2):totable()) - eq({ 4, 3, 2 }, vim.iter(t):take(3):totable()) - eq({ 4, 3, 2, 1 }, vim.iter(t):take(4):totable()) - eq({ 4, 3, 2, 1 }, vim.iter(t):take(5):totable()) + local q = { 4, 3, 2, 1 } + eq({}, vim.iter(q):take(0):totable()) + eq({ 4 }, vim.iter(q):take(1):totable()) + eq({ 4, 3 }, vim.iter(q):take(2):totable()) + eq({ 4, 3, 2 }, vim.iter(q):take(3):totable()) + eq({ 4, 3, 2, 1 }, vim.iter(q):take(4):totable()) + eq({ 4, 3, 2, 1 }, vim.iter(q):take(5):totable()) end do - local t = { 4, 3, 2, 1 } - eq({ 1, 2, 3 }, vim.iter(t):rev():take(3):totable()) - eq({ 2, 3, 4 }, vim.iter(t):take(3):rev():totable()) + local q = { 4, 3, 2, 1 } + eq({ 1, 2, 3 }, vim.iter(q):rev():take(3):totable()) + eq({ 2, 3, 4 }, vim.iter(q):take(3):rev():totable()) end do - local t = { 4, 3, 2, 1 } - local it = vim.iter(t) + local q = { 4, 3, 2, 1 } + local it = vim.iter(q) eq({ 4, 3 }, it:take(2):totable()) -- tail is already set from the previous take() eq({ 4, 3 }, it:take(3):totable()) @@ -275,13 +275,13 @@ describe('vim.iter', function() end do - local t = { 4, 8, 9, 10 } - eq(true, vim.iter(t):any(odd)) + local q = { 4, 8, 9, 10 } + eq(true, vim.iter(q):any(odd)) end do - local t = { 4, 8, 10 } - eq(false, vim.iter(t):any(odd)) + local q = { 4, 8, 10 } + eq(false, vim.iter(q):any(odd)) end do @@ -306,13 +306,13 @@ describe('vim.iter', function() end do - local t = { 3, 5, 7, 9 } - eq(true, vim.iter(t):all(odd)) + local q = { 3, 5, 7, 9 } + eq(true, vim.iter(q):all(odd)) end do - local t = { 3, 5, 7, 10 } - eq(false, vim.iter(t):all(odd)) + local q = { 3, 5, 7, 10 } + eq(false, vim.iter(q):all(odd)) end do @@ -360,18 +360,18 @@ describe('vim.iter', function() end) it('find()', function() - local t = { 3, 6, 9, 12 } - eq(12, vim.iter(t):find(12)) - eq(nil, vim.iter(t):find(15)) + local q = { 3, 6, 9, 12 } + eq(12, vim.iter(q):find(12)) + eq(nil, vim.iter(q):find(15)) eq( 12, - vim.iter(t):find(function(v) + vim.iter(q):find(function(v) return v % 4 == 0 end) ) do - local it = vim.iter(t) + local it = vim.iter(q) local pred = function(v) return v % 3 == 0 end @@ -395,16 +395,16 @@ describe('vim.iter', function() end) it('rfind()', function() - local t = { 1, 2, 3, 2, 1 } + local q = { 1, 2, 3, 2, 1 } do - local it = vim.iter(t) + local it = vim.iter(q) eq(1, it:rfind(1)) eq(1, it:rfind(1)) eq(nil, it:rfind(1)) end do - local it = vim.iter(t):enumerate() + local it = vim.iter(q):enumerate() local pred = function(i) return i % 2 ~= 0 end @@ -452,16 +452,16 @@ describe('vim.iter', function() end) it('fold()', function() - local t = { 1, 2, 3, 4, 5 } + local q = { 1, 2, 3, 4, 5 } eq( 115, - vim.iter(t):fold(100, function(acc, v) + vim.iter(q):fold(100, function(acc, v) return acc + v end) ) eq( { 5, 4, 3, 2, 1 }, - vim.iter(t):fold({}, function(acc, v) + vim.iter(q):fold({}, function(acc, v) table.insert(acc, 1, v) return acc end) @@ -469,14 +469,14 @@ describe('vim.iter', function() end) it('flatten()', function() - local t = { { 1, { 2 } }, { { { { 3 } } }, { 4 } }, { 5 } } + local q = { { 1, { 2 } }, { { { { 3 } } }, { 4 } }, { 5 } } - eq(t, vim.iter(t):flatten(-1):totable()) - eq(t, vim.iter(t):flatten(0):totable()) - eq({ 1, { 2 }, { { { 3 } } }, { 4 }, 5 }, vim.iter(t):flatten():totable()) - eq({ 1, 2, { { 3 } }, 4, 5 }, vim.iter(t):flatten(2):totable()) - eq({ 1, 2, { 3 }, 4, 5 }, vim.iter(t):flatten(3):totable()) - eq({ 1, 2, 3, 4, 5 }, vim.iter(t):flatten(4):totable()) + eq(q, vim.iter(q):flatten(-1):totable()) + eq(q, vim.iter(q):flatten(0):totable()) + eq({ 1, { 2 }, { { { 3 } } }, { 4 }, 5 }, vim.iter(q):flatten():totable()) + eq({ 1, 2, { { 3 } }, 4, 5 }, vim.iter(q):flatten(2):totable()) + eq({ 1, 2, { 3 }, 4, 5 }, vim.iter(q):flatten(3):totable()) + eq({ 1, 2, 3, 4, 5 }, vim.iter(q):flatten(4):totable()) local m = { a = 1, b = { 2, 3 }, d = { 4 } } local it = vim.iter(m) @@ -507,11 +507,11 @@ describe('vim.iter', function() end end) - local t = it:fold({}, function(t, k, v) - t[k] = v - return t + local q = it:fold({}, function(q, k, v) + q[k] = v + return q end) - eq({ A = 2, C = 6 }, t) + eq({ A = 2, C = 6 }, q) end) it('handles table values mid-pipeline', function() diff --git a/test/functional/lua/json_spec.lua b/test/functional/lua/json_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local exec_lua = helpers.exec_lua -local eq = helpers.eq -local pcall_err = helpers.pcall_err +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local exec_lua = t.exec_lua +local eq = t.eq +local pcall_err = t.pcall_err describe('vim.json.decode()', function() before_each(function() diff --git a/test/functional/lua/loader_spec.lua b/test/functional/lua/loader_spec.lua @@ -1,10 +1,10 @@ -- Test suite for testing interactions with API bindings -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local exec_lua = helpers.exec_lua -local command = helpers.command -local clear = helpers.clear -local eq = helpers.eq +local exec_lua = t.exec_lua +local command = t.command +local clear = t.clear +local eq = t.eq describe('vim.loader', function() before_each(clear) @@ -35,7 +35,7 @@ describe('vim.loader', function() vim.loader.enable() ]] - local tmp = helpers.tmpname() + local tmp = t.tmpname() command('edit ' .. tmp) eq( @@ -73,15 +73,15 @@ describe('vim.loader', function() vim.loader.enable() ]] - local t = helpers.tmpname() - assert(os.remove(t)) - assert(helpers.mkdir(t)) - assert(helpers.mkdir(t .. '/%')) - local tmp1 = t .. '/%/x' - local tmp2 = t .. '/%%x' + local tmp = t.tmpname() + assert(os.remove(tmp)) + assert(t.mkdir(tmp)) + assert(t.mkdir(tmp .. '/%')) + local tmp1 = tmp .. '/%/x' + local tmp2 = tmp .. '/%%x' - helpers.write_file(tmp1, 'return 1', true) - helpers.write_file(tmp2, 'return 2', true) + t.write_file(tmp1, 'return 1', true) + t.write_file(tmp2, 'return 2', true) vim.uv.fs_utime(tmp1, 0, 0) vim.uv.fs_utime(tmp2, 0, 0) eq(1, exec_lua('return loadfile(...)()', tmp1)) diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua @@ -1,16 +1,16 @@ -- Test suite for testing interactions with API bindings -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local fn = helpers.fn -local api = helpers.api -local clear = helpers.clear +local fn = t.fn +local api = t.api +local clear = t.clear local sleep = vim.uv.sleep -local feed = helpers.feed -local eq = helpers.eq -local eval = helpers.eval -local matches = helpers.matches -local exec_lua = helpers.exec_lua -local retry = helpers.retry +local feed = t.feed +local eq = t.eq +local eval = t.eval +local matches = t.matches +local exec_lua = t.exec_lua +local retry = t.retry before_each(clear) diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua @@ -1,19 +1,19 @@ -- Test suite for testing luaeval() function -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local pcall_err = helpers.pcall_err -local exc_exec = helpers.exc_exec -local remove_trace = helpers.remove_trace -local exec_lua = helpers.exec_lua -local command = helpers.command -local api = helpers.api -local fn = helpers.fn -local clear = helpers.clear -local eval = helpers.eval -local feed = helpers.feed +local pcall_err = t.pcall_err +local exc_exec = t.exc_exec +local remove_trace = t.remove_trace +local exec_lua = t.exec_lua +local command = t.command +local api = t.api +local fn = t.fn +local clear = t.clear +local eval = t.eval +local feed = t.feed local NIL = vim.NIL -local eq = helpers.eq +local eq = t.eq before_each(clear) @@ -38,8 +38,8 @@ describe('luaeval()', function() describe('second argument', function() it('is successfully received', function() - local t = {t=true, f=false, --[[n=NIL,]] d={l={'string', 42, 0.42}}} - eq(t, fn.luaeval("_A", t)) + local q = {t=true, f=false, --[[n=NIL,]] d={l={'string', 42, 0.42}}} + eq(q, fn.luaeval("_A", q)) -- Not tested: nil, funcrefs, returned object identity: behaviour will -- most likely change. end) diff --git a/test/functional/lua/mpack_spec.lua b/test/functional/lua/mpack_spec.lua @@ -1,9 +1,9 @@ -- Test suite for testing interactions with API bindings -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local exec_lua = helpers.exec_lua +local clear = t.clear +local eq = t.eq +local exec_lua = t.exec_lua describe('lua vim.mpack', function() before_each(clear) diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua @@ -1,19 +1,19 @@ -- Test for Vim overrides of lua built-ins -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local eq = helpers.eq +local eq = t.eq local NIL = vim.NIL -local feed = helpers.feed -local clear = helpers.clear -local fn = helpers.fn -local api = helpers.api -local command = helpers.command -local write_file = helpers.write_file -local exec_capture = helpers.exec_capture -local exec_lua = helpers.exec_lua -local pcall_err = helpers.pcall_err -local is_os = helpers.is_os +local feed = t.feed +local clear = t.clear +local fn = t.fn +local api = t.api +local command = t.command +local write_file = t.write_file +local exec_capture = t.exec_capture +local exec_lua = t.exec_lua +local pcall_err = t.pcall_err +local is_os = t.is_os local fname = 'Xtest-functional-lua-overrides-luafile' diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua @@ -1,17 +1,17 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local eval = helpers.eval -local exec = helpers.exec -local fn = helpers.fn -local mkdir_p = helpers.mkdir_p -local rmdir = helpers.rmdir -local write_file = helpers.write_file +local clear = t.clear +local eq = t.eq +local eval = t.eval +local exec = t.exec +local fn = t.fn +local mkdir_p = t.mkdir_p +local rmdir = t.rmdir +local write_file = t.write_file describe('runtime:', function() local plug_dir = 'Test_Plugin' - local sep = helpers.get_pathsep() + local sep = t.get_pathsep() local init = 'dummy_init.lua' setup(function() diff --git a/test/functional/lua/secure_spec.lua b/test/functional/lua/secure_spec.lua @@ -1,20 +1,20 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local eq = helpers.eq -local clear = helpers.clear -local command = helpers.command -local pathsep = helpers.get_pathsep() -local is_os = helpers.is_os -local api = helpers.api -local exec_lua = helpers.exec_lua -local feed_command = helpers.feed_command -local feed = helpers.feed -local fn = helpers.fn +local eq = t.eq +local clear = t.clear +local command = t.command +local pathsep = t.get_pathsep() +local is_os = t.is_os +local api = t.api +local exec_lua = t.exec_lua +local feed_command = t.feed_command +local feed = t.feed +local fn = t.fn local stdpath = fn.stdpath -local pcall_err = helpers.pcall_err -local matches = helpers.matches -local read_file = helpers.read_file +local pcall_err = t.pcall_err +local matches = t.matches +local read_file = t.read_file describe('vim.secure', function() describe('read()', function() @@ -22,8 +22,8 @@ describe('vim.secure', function() setup(function() clear { env = { XDG_STATE_HOME = xstate } } - helpers.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) - helpers.write_file( + t.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) + t.write_file( 'Xfile', [[ let g:foobar = 42 @@ -33,7 +33,7 @@ describe('vim.secure', function() teardown(function() os.remove('Xfile') - helpers.rmdir(xstate) + t.rmdir(xstate) end) it('works', function() @@ -181,15 +181,15 @@ describe('vim.secure', function() setup(function() clear { env = { XDG_STATE_HOME = xstate } } - helpers.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) + t.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) end) teardown(function() - helpers.rmdir(xstate) + t.rmdir(xstate) end) before_each(function() - helpers.write_file('test_file', 'test') + t.write_file('test_file', 'test') end) after_each(function() diff --git a/test/functional/lua/snippet_spec.lua b/test/functional/lua/snippet_spec.lua @@ -1,16 +1,16 @@ -local helpers = require('test.functional.helpers')(after_each) - -local buf_lines = helpers.buf_lines -local clear = helpers.clear -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local feed = helpers.feed -local api = helpers.api -local fn = helpers.fn -local matches = helpers.matches -local pcall_err = helpers.pcall_err -local poke_eventloop = helpers.poke_eventloop -local retry = helpers.retry +local t = require('test.functional.testutil')(after_each) + +local buf_lines = t.buf_lines +local clear = t.clear +local eq = t.eq +local exec_lua = t.exec_lua +local feed = t.feed +local api = t.api +local fn = t.fn +local matches = t.matches +local pcall_err = t.pcall_err +local poke_eventloop = t.poke_eventloop +local retry = t.retry describe('vim.snippet', function() before_each(function() diff --git a/test/functional/lua/spell_spec.lua b/test/functional/lua/spell_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local exec_lua = helpers.exec_lua -local eq = helpers.eq -local pcall_err = helpers.pcall_err +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local exec_lua = t.exec_lua +local eq = t.eq +local pcall_err = t.pcall_err describe('vim.spell', function() before_each(function() diff --git a/test/functional/lua/system_spec.lua b/test/functional/lua/system_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local exec_lua = helpers.exec_lua -local eq = helpers.eq +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local exec_lua = t.exec_lua +local eq = t.eq local function system_sync(cmd, opts) return exec_lua( diff --git a/test/functional/lua/text_spec.lua b/test/functional/lua/text_spec.lua @@ -1,6 +1,6 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq = helpers.eq +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eq = t.eq describe('vim.text', function() before_each(clear) diff --git a/test/functional/lua/thread_spec.lua b/test/functional/lua/thread_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local assert_alive = helpers.assert_alive -local clear = helpers.clear -local feed = helpers.feed -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local next_msg = helpers.next_msg +local assert_alive = t.assert_alive +local clear = t.clear +local feed = t.feed +local eq = t.eq +local exec_lua = t.exec_lua +local next_msg = t.next_msg local NIL = vim.NIL -local pcall_err = helpers.pcall_err +local pcall_err = t.pcall_err describe('thread', function() local screen diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local clear = helpers.clear -local feed = helpers.feed -local fn = helpers.fn -local assert_log = helpers.assert_log -local check_close = helpers.check_close +local eq = t.eq +local exec_lua = t.exec_lua +local clear = t.clear +local feed = t.feed +local fn = t.fn +local assert_log = t.assert_log +local check_close = t.check_close local testlog = 'Xtest_lua_ui_event_log' @@ -112,7 +112,7 @@ describe('vim.ui_attach', function() it('does not crash on exit', function() fn.system({ - helpers.nvim_prog, + t.nvim_prog, '-u', 'NONE', '-i', @@ -124,7 +124,7 @@ describe('vim.ui_attach', function() '--cmd', 'quitall!', }) - eq(0, helpers.eval('v:shell_error')) + eq(0, t.eval('v:shell_error')) end) it('can receive accurate message kinds even if they are history', function() diff --git a/test/functional/lua/ui_spec.lua b/test/functional/lua/ui_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq = helpers.eq -local matches = helpers.matches -local exec_lua = helpers.exec_lua -local clear = helpers.clear -local feed = helpers.feed -local eval = helpers.eval -local is_ci = helpers.is_ci -local is_os = helpers.is_os -local poke_eventloop = helpers.poke_eventloop +local t = require('test.functional.testutil')(after_each) +local eq = t.eq +local matches = t.matches +local exec_lua = t.exec_lua +local clear = t.clear +local feed = t.feed +local eval = t.eval +local is_ci = t.is_ci +local is_os = t.is_os +local poke_eventloop = t.poke_eventloop describe('vim.ui', function() before_each(function() diff --git a/test/functional/lua/uri_spec.lua b/test/functional/lua/uri_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local exec_lua = helpers.exec_lua -local eq = helpers.eq -local is_os = helpers.is_os -local skip = helpers.skip -local write_file = require('test.helpers').write_file +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local exec_lua = t.exec_lua +local eq = t.eq +local is_os = t.is_os +local skip = t.skip +local write_file = t.write_file describe('URI methods', function() before_each(function() @@ -206,7 +206,7 @@ describe('URI methods', function() it('Windows paths should not be treated as uris', function() skip(not is_os('win'), 'Not applicable on non-Windows') - local file = helpers.tmpname() + local file = t.tmpname() write_file(file, 'Test content') local test_case = string.format( [[ diff --git a/test/functional/lua/version_spec.lua b/test/functional/lua/version_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local ok = helpers.ok -local exec_lua = helpers.exec_lua -local matches = helpers.matches -local pcall_err = helpers.pcall_err -local fn = helpers.fn +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eq = t.eq +local ok = t.ok +local exec_lua = t.exec_lua +local matches = t.matches +local pcall_err = t.pcall_err +local fn = t.fn local function v(ver) return vim.version._version(ver) diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua @@ -1,32 +1,32 @@ -- Test suite for testing interactions with API bindings -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local nvim_prog = helpers.nvim_prog -local fn = helpers.fn -local api = helpers.api -local command = helpers.command -local dedent = helpers.dedent -local insert = helpers.insert -local clear = helpers.clear -local eq = helpers.eq -local ok = helpers.ok +local nvim_prog = t.nvim_prog +local fn = t.fn +local api = t.api +local command = t.command +local dedent = t.dedent +local insert = t.insert +local clear = t.clear +local eq = t.eq +local ok = t.ok local pesc = vim.pesc -local eval = helpers.eval -local feed = helpers.feed -local pcall_err = helpers.pcall_err -local exec_lua = helpers.exec_lua -local matches = helpers.matches -local exec = helpers.exec +local eval = t.eval +local feed = t.feed +local pcall_err = t.pcall_err +local exec_lua = t.exec_lua +local matches = t.matches +local exec = t.exec local NIL = vim.NIL -local retry = helpers.retry -local next_msg = helpers.next_msg -local remove_trace = helpers.remove_trace -local mkdir_p = helpers.mkdir_p -local rmdir = helpers.rmdir -local write_file = helpers.write_file -local poke_eventloop = helpers.poke_eventloop -local assert_alive = helpers.assert_alive +local retry = t.retry +local next_msg = t.next_msg +local remove_trace = t.remove_trace +local mkdir_p = t.mkdir_p +local rmdir = t.rmdir +local write_file = t.write_file +local poke_eventloop = t.poke_eventloop +local assert_alive = t.assert_alive describe('lua stdlib', function() before_each(clear) @@ -592,8 +592,8 @@ describe('lua stdlib', function() { 'x*yz*oo*l', '*', true, false, { 'x', 'yz', 'oo', 'l' } }, } - for _, t in ipairs(tests) do - eq(t[5], vim.split(t[1], t[2], { plain = t[3], trimempty = t[4] }), t[1]) + for _, q in ipairs(tests) do + eq(q[5], vim.split(q[1], q[2], { plain = q[3], trimempty = q[4] }), q[1]) end -- Test old signature @@ -603,8 +603,8 @@ describe('lua stdlib', function() { 'abc', '.-' }, } - for _, t in ipairs(loops) do - matches('Infinite loop detected', pcall_err(vim.split, t[1], t[2])) + for _, q in ipairs(loops) do + matches('Infinite loop detected', pcall_err(vim.split, q[1], q[2])) end -- Validates args. @@ -626,8 +626,8 @@ describe('lua stdlib', function() { 'r\n', 'r' }, } - for _, t in ipairs(trims) do - assert(t[2], trim(t[1])) + for _, q in ipairs(trims) do + assert(q[2], trim(q[1])) end -- Validates args. @@ -636,8 +636,8 @@ describe('lua stdlib', function() it('vim.inspect', function() -- just make sure it basically works, it has its own test suite - local inspect = function(t, opts) - return exec_lua('return vim.inspect(...)', t, opts) + local inspect = function(q, opts) + return exec_lua('return vim.inspect(...)', q, opts) end eq('2', inspect(2)) @@ -1569,7 +1569,7 @@ describe('lua stdlib', function() eq(NIL, exec_lua([[return vim.g.Unknown_script_func]])) -- Check if autoload works properly - local pathsep = helpers.get_pathsep() + local pathsep = t.get_pathsep() local xconfig = 'Xhome' .. pathsep .. 'Xconfig' local xdata = 'Xhome' .. pathsep .. 'Xdata' local autoload_folder = table.concat({ xconfig, 'nvim', 'autoload' }, pathsep) @@ -4071,7 +4071,7 @@ describe('vim.keymap', function() feed('asdf\n') eq(1, exec_lua [[return GlobalCount]]) - eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) + eq('\nNo mapping found', t.exec_capture('nmap asdf')) end) it('works with buffer-local mappings', function() @@ -4095,7 +4095,7 @@ describe('vim.keymap', function() feed('asdf\n') eq(1, exec_lua [[return GlobalCount]]) - eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) + eq('\nNo mapping found', t.exec_capture('nmap asdf')) end) it('does not mutate the opts parameter', function() diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local clear = helpers.clear -local is_ci = helpers.is_ci -local is_os = helpers.is_os -local skip = helpers.skip +local t = require('test.functional.testutil')(after_each) +local eq = t.eq +local exec_lua = t.exec_lua +local clear = t.clear +local is_ci = t.is_ci +local is_os = t.is_os +local skip = t.skip -- Create a file via a rename to avoid multiple -- events which can happen with some backends on some platforms local function touch(path) - local tmp = helpers.tmpname() + local tmp = t.tmpname() io.open(tmp, 'w'):close() assert(vim.uv.fs_rename(tmp, path)) end @@ -24,10 +24,7 @@ describe('vim._watch', function() if watchfunc == 'fswatch' then skip(is_os('win'), 'not supported on windows') skip(is_os('mac'), 'flaky test on mac') - skip( - not is_ci() and helpers.fn.executable('fswatch') == 0, - 'fswatch not installed and not on CI' - ) + skip(not is_ci() and t.fn.executable('fswatch') == 0, 'fswatch not installed and not on CI') end if watchfunc == 'watch' then @@ -40,7 +37,7 @@ describe('vim._watch', function() ) end - local root_dir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX') + local root_dir = vim.uv.fs_mkdtemp(vim.fs.dirname(t.tmpname()) .. '/nvim_XXXXXXXXXX') local expected_events = 0 diff --git a/test/functional/lua/xdiff_spec.lua b/test/functional/lua/xdiff_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local exec_lua = helpers.exec_lua -local eq = helpers.eq -local pcall_err = helpers.pcall_err +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local exec_lua = t.exec_lua +local eq = t.eq +local pcall_err = t.pcall_err describe('xdiff bindings', function() before_each(function() diff --git a/test/functional/options/autochdir_spec.lua b/test/functional/options/autochdir_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local fn = helpers.fn -local command = helpers.command -local mkdir = helpers.mkdir +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eq = t.eq +local fn = t.fn +local command = t.command +local mkdir = t.mkdir describe("'autochdir'", function() it('given on the shell gets processed properly', function() @@ -16,7 +16,7 @@ describe("'autochdir'", function() -- With 'autochdir' on, we should get the directory of tty-test.c. clear('--cmd', 'set autochdir', targetdir .. '/tty-test.c') - eq(helpers.is_os('win') and expected:gsub('/', '\\') or expected, fn.getcwd()) + eq(t.is_os('win') and expected:gsub('/', '\\') or expected, fn.getcwd()) end) it('is not overwritten by getwinvar() call #17609', function() @@ -38,7 +38,7 @@ describe("'autochdir'", function() eq(dir_a, fn.getcwd()) fn.getwinvar(2, 'foo') eq(dir_a, fn.getcwd()) - helpers.rmdir(dir_a) - helpers.rmdir(dir_b) + t.rmdir(dir_a) + t.rmdir(dir_b) end) end) diff --git a/test/functional/options/chars_spec.lua b/test/functional/options/chars_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, command = helpers.clear, helpers.command -local pcall_err = helpers.pcall_err -local eval = helpers.eval -local eq = helpers.eq -local insert = helpers.insert -local feed = helpers.feed -local api = helpers.api +local clear, command = t.clear, t.command +local pcall_err = t.pcall_err +local eval = t.eval +local eq = t.eq +local insert = t.insert +local feed = t.feed +local api = t.api describe("'fillchars'", function() local screen diff --git a/test/functional/options/cursorbind_spec.lua b/test/functional/options/cursorbind_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local exec = helpers.exec -local feed = helpers.feed +local clear = t.clear +local command = t.command +local exec = t.exec +local feed = t.feed before_each(clear) diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua @@ -1,27 +1,27 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local assert_alive = helpers.assert_alive -local assert_log = helpers.assert_log -local api = helpers.api -local command = helpers.command -local clear = helpers.clear -local exc_exec = helpers.exc_exec -local exec_lua = helpers.exec_lua -local eval = helpers.eval -local eq = helpers.eq -local ok = helpers.ok -local fn = helpers.fn -local insert = helpers.insert -local neq = helpers.neq -local mkdir = helpers.mkdir -local rmdir = helpers.rmdir -local alter_slashes = helpers.alter_slashes +local assert_alive = t.assert_alive +local assert_log = t.assert_log +local api = t.api +local command = t.command +local clear = t.clear +local exc_exec = t.exc_exec +local exec_lua = t.exec_lua +local eval = t.eval +local eq = t.eq +local ok = t.ok +local fn = t.fn +local insert = t.insert +local neq = t.neq +local mkdir = t.mkdir +local rmdir = t.rmdir +local alter_slashes = t.alter_slashes local tbl_contains = vim.tbl_contains -local expect_exit = helpers.expect_exit -local check_close = helpers.check_close -local is_os = helpers.is_os +local expect_exit = t.expect_exit +local check_close = t.check_close +local is_os = t.is_os local testlog = 'Xtest-defaults-log' @@ -1248,7 +1248,7 @@ end) describe('autocommands', function() it('closes terminal with default shell on success', function() clear() - api.nvim_set_option_value('shell', helpers.testprg('shell-test'), {}) + api.nvim_set_option_value('shell', t.testprg('shell-test'), {}) command('set shellcmdflag=EXIT shellredir= shellpipe= shellquote= shellxquote=') -- Should not block other events @@ -1258,7 +1258,7 @@ describe('autocommands', function() command('terminal') eq(1, eval('get(g:, "n", 0)')) - helpers.retry(nil, 1000, function() + t.retry(nil, 1000, function() neq('terminal', api.nvim_get_option_value('buftype', { buf = 0 })) eq(2, eval('get(g:, "n", 0)')) end) diff --git a/test/functional/options/keymap_spec.lua b/test/functional/options/keymap_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, eq = helpers.clear, helpers.feed, helpers.eq -local expect, command, eval = helpers.expect, helpers.command, helpers.eval -local insert, call = helpers.insert, helpers.call -local exec_capture, dedent = helpers.exec_capture, helpers.dedent +local t = require('test.functional.testutil')(after_each) +local clear, feed, eq = t.clear, t.feed, t.eq +local expect, command, eval = t.expect, t.command, t.eval +local insert, call = t.insert, t.call +local exec_capture, dedent = t.exec_capture, t.dedent -- First test it's implemented using the :lmap and :lnoremap commands, then -- check those mappings behave as expected. diff --git a/test/functional/options/modified_spec.lua b/test/functional/options/modified_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local api = helpers.api +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eq = t.eq +local api = t.api describe("'modified'", function() before_each(function() diff --git a/test/functional/options/mousescroll_spec.lua b/test/functional/options/mousescroll_spec.lua @@ -1,21 +1,21 @@ -local helpers = require('test.functional.helpers')(after_each) -local command = helpers.command -local clear = helpers.clear -local eval = helpers.eval -local eq = helpers.eq -local exc_exec = helpers.exc_exec -local feed = helpers.feed +local t = require('test.functional.testutil')(after_each) +local command = t.command +local clear = t.clear +local eval = t.eval +local eq = t.eq +local exc_exec = t.exc_exec +local feed = t.feed local scroll = function(direction) - return helpers.request('nvim_input_mouse', 'wheel', direction, '', 0, 2, 2) + return t.request('nvim_input_mouse', 'wheel', direction, '', 0, 2, 2) end local screenrow = function() - return helpers.call('screenrow') + return t.call('screenrow') end local screencol = function() - return helpers.call('screencol') + return t.call('screencol') end describe("'mousescroll'", function() diff --git a/test/functional/options/num_options_spec.lua b/test/functional/options/num_options_spec.lua @@ -1,8 +1,7 @@ -- Tests for :setlocal and :setglobal -local helpers = require('test.functional.helpers')(after_each) -local clear, feed_command, eval, eq, api = - helpers.clear, helpers.feed_command, helpers.eval, helpers.eq, helpers.api +local t = require('test.functional.testutil')(after_each) +local clear, feed_command, eval, eq, api = t.clear, t.feed_command, t.eval, t.eq, t.api local function should_fail(opt, value, errmsg) feed_command('setglobal ' .. opt .. '=' .. value) diff --git a/test/functional/options/shortmess_spec.lua b/test/functional/options/shortmess_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval -local feed = helpers.feed +local clear = t.clear +local command = t.command +local eq = t.eq +local eval = t.eval +local feed = t.feed describe("'shortmess'", function() local screen diff --git a/test/functional/options/tabstop_spec.lua b/test/functional/options/tabstop_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local assert_alive = helpers.assert_alive -local clear = helpers.clear -local feed = helpers.feed +local assert_alive = t.assert_alive +local clear = t.clear +local feed = t.feed describe("'tabstop' option", function() before_each(function() diff --git a/test/functional/options/winfixbuf_spec.lua b/test/functional/options/winfixbuf_spec.lua @@ -1,6 +1,6 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local exec_lua = helpers.exec_lua +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local exec_lua = t.exec_lua describe("Nvim API calls with 'winfixbuf'", function() before_each(function() diff --git a/test/functional/plugin/ccomplete_spec.lua b/test/functional/plugin/ccomplete_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval -local feed = helpers.feed -local write_file = helpers.write_file +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local eq = t.eq +local eval = t.eval +local feed = t.feed +local write_file = t.write_file describe('ccomplete#Complete', function() setup(function() diff --git a/test/functional/plugin/cfilter_spec.lua b/test/functional/plugin/cfilter_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local fn = helpers.fn +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local eq = t.eq +local fn = t.fn describe('cfilter.lua', function() before_each(function() diff --git a/test/functional/plugin/editorconfig_spec.lua b/test/functional/plugin/editorconfig_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local pathsep = helpers.get_pathsep() -local fn = helpers.fn -local api = helpers.api -local exec_lua = helpers.exec_lua +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local eq = t.eq +local pathsep = t.get_pathsep() +local fn = t.fn +local api = t.api +local exec_lua = t.exec_lua local testdir = 'Xtest-editorconfig' @@ -20,8 +20,8 @@ local function test_case(name, expected) end setup(function() - helpers.mkdir_p(testdir) - helpers.write_file( + t.mkdir_p(testdir) + t.write_file( testdir .. pathsep .. '.editorconfig', [[ root = true @@ -96,7 +96,7 @@ setup(function() end) teardown(function() - helpers.rmdir(testdir) + t.rmdir(testdir) end) describe('editorconfig', function() @@ -178,18 +178,18 @@ But not this one -- luacheck: pop local trimmed = untrimmed:gsub('%s+\n', '\n') - helpers.write_file(filename, untrimmed) + t.write_file(filename, untrimmed) command('edit ' .. filename) command('write') command('bdelete') - eq(trimmed, helpers.read_file(filename)) + eq(trimmed, t.read_file(filename)) filename = testdir .. pathsep .. 'no_trim.txt' - helpers.write_file(filename, untrimmed) + t.write_file(filename, untrimmed) command('edit ' .. filename) command('write') command('bdelete') - eq(untrimmed, helpers.read_file(filename)) + eq(untrimmed, t.read_file(filename)) end) it('sets textwidth', function() diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local curbuf_contents = helpers.curbuf_contents -local command = helpers.command -local eq, neq, matches = helpers.eq, helpers.neq, helpers.matches -local getcompletion = helpers.fn.getcompletion -local insert = helpers.insert -local source = helpers.source -local fn = helpers.fn -local api = helpers.api +local clear = t.clear +local curbuf_contents = t.curbuf_contents +local command = t.command +local eq, neq, matches = t.eq, t.neq, t.matches +local getcompletion = t.fn.getcompletion +local insert = t.insert +local source = t.source +local fn = t.fn +local api = t.api describe(':checkhealth', function() it('detects invalid $VIMRUNTIME', function() @@ -53,7 +53,7 @@ describe('health.vim', function() describe(':checkhealth', function() it('functions report_*() render correctly', function() command('checkhealth full_render') - helpers.expect([[ + t.expect([[ ============================================================================== test_plug.full_render: require("test_plug.full_render.health").check() @@ -76,7 +76,7 @@ describe('health.vim', function() it('concatenates multiple reports', function() command('checkhealth success1 success2 test_plug') - helpers.expect([[ + t.expect([[ ============================================================================== test_plug: require("test_plug.health").check() @@ -106,7 +106,7 @@ describe('health.vim', function() it('lua plugins submodules', function() command('checkhealth test_plug.submodule') - helpers.expect([[ + t.expect([[ ============================================================================== test_plug.submodule: require("test_plug.submodule.health").check() @@ -121,7 +121,7 @@ describe('health.vim', function() it('... including empty reports', function() command('checkhealth test_plug.submodule_empty') - helpers.expect([[ + t.expect([[ ============================================================================== test_plug.submodule_empty: require("test_plug.submodule_empty.health").check() @@ -180,7 +180,7 @@ describe('health.vim', function() it('gracefully handles invalid healthcheck', function() command('checkhealth non_existent_healthcheck') -- luacheck: ignore 613 - helpers.expect([[ + t.expect([[ ============================================================================== non_existent_healthcheck: @@ -192,7 +192,7 @@ describe('health.vim', function() it('does not use vim.health as a healtcheck', function() -- vim.health is not a healthcheck command('checkhealth vim') - helpers.expect([[ + t.expect([[ ERROR: No healthchecks found.]]) end) end) diff --git a/test/functional/plugin/lsp/codelens_spec.lua b/test/functional/plugin/lsp/codelens_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local exec_lua = helpers.exec_lua -local eq = helpers.eq +local exec_lua = t.exec_lua +local eq = t.eq describe('vim.lsp.codelens', function() before_each(function() - helpers.clear() + t.clear() exec_lua('require("vim.lsp")') end) - after_each(helpers.clear) + after_each(t.clear) it('on_codelens_stores_and_displays_lenses', function() local fake_uri = 'file:///fake/uri' diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua @@ -1,7 +1,7 @@ ---@diagnostic disable: no-unknown -local helpers = require('test.functional.helpers')(after_each) -local eq = helpers.eq -local exec_lua = helpers.exec_lua +local t = require('test.functional.testutil')(after_each) +local eq = t.eq +local exec_lua = t.exec_lua --- Convert completion results. --- @@ -41,7 +41,7 @@ local function complete(line, candidates, lnum) end describe('vim.lsp._completion', function() - before_each(helpers.clear) + before_each(t.clear) -- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion it('prefers textEdit over label as word', function() diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) -local lsp_helpers = require('test.functional.plugin.lsp.helpers') +local t = require('test.functional.testutil')(after_each) +local t_lsp = require('test.functional.plugin.lsp.testutil') -local clear = helpers.clear -local exec_lua = helpers.exec_lua -local eq = helpers.eq -local neq = require('test.helpers').neq +local clear = t.clear +local exec_lua = t.exec_lua +local eq = t.eq +local neq = t.neq -local create_server_definition = lsp_helpers.create_server_definition +local create_server_definition = t_lsp.create_server_definition describe('vim.lsp.diagnostic', function() local fake_uri diff --git a/test/functional/plugin/lsp/handler_spec.lua b/test/functional/plugin/lsp/handler_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local pcall_err = helpers.pcall_err -local matches = helpers.matches +local eq = t.eq +local exec_lua = t.exec_lua +local pcall_err = t.pcall_err +local matches = t.matches describe('lsp-handlers', function() describe('vim.lsp._with_extend', function() diff --git a/test/functional/plugin/lsp/helpers.lua b/test/functional/plugin/lsp/helpers.lua @@ -1,219 +0,0 @@ -local helpers = require('test.functional.helpers')(nil) - -local clear = helpers.clear -local exec_lua = helpers.exec_lua -local run = helpers.run -local stop = helpers.stop -local api = helpers.api -local NIL = vim.NIL - -local M = {} - -function M.clear_notrace() - -- problem: here be dragons - -- solution: don't look too closely for dragons - clear { - env = { - NVIM_LUA_NOTRACK = '1', - NVIM_APPNAME = 'nvim_lsp_test', - VIMRUNTIME = os.getenv 'VIMRUNTIME', - }, - } -end - -M.create_server_definition = [[ - function _create_server(opts) - opts = opts or {} - local server = {} - server.messages = {} - - function server.cmd(dispatchers) - local closing = false - local handlers = opts.handlers or {} - local srv = {} - - function srv.request(method, params, callback) - table.insert(server.messages, { - method = method, - params = params, - }) - local handler = handlers[method] - if handler then - local response, err = handler(method, params) - callback(err, response) - elseif method == 'initialize' then - callback(nil, { - capabilities = opts.capabilities or {} - }) - elseif method == 'shutdown' then - callback(nil, nil) - end - local request_id = #server.messages - return true, request_id - end - - function srv.notify(method, params) - table.insert(server.messages, { - method = method, - params = params - }) - if method == 'exit' then - dispatchers.on_exit(0, 15) - end - end - - function srv.is_closing() - return closing - end - - function srv.terminate() - closing = true - end - - return srv - end - - return server - end -]] - --- Fake LSP server. -M.fake_lsp_code = 'test/functional/fixtures/fake-lsp-server.lua' -M.fake_lsp_logfile = 'Xtest-fake-lsp.log' - -local function fake_lsp_server_setup(test_name, timeout_ms, options, settings) - exec_lua( - [=[ - lsp = require('vim.lsp') - local test_name, fake_lsp_code, fake_lsp_logfile, timeout, options, settings = ... - TEST_RPC_CLIENT_ID = lsp.start_client { - cmd_env = { - NVIM_LOG_FILE = fake_lsp_logfile; - NVIM_LUA_NOTRACK = "1"; - NVIM_APPNAME = "nvim_lsp_test"; - }; - cmd = { - vim.v.progpath, '-l', fake_lsp_code, test_name, tostring(timeout), - }; - handlers = setmetatable({}, { - __index = function(t, method) - return function(...) - return vim.rpcrequest(1, 'handler', ...) - end - end; - }); - workspace_folders = {{ - uri = 'file://' .. vim.uv.cwd(), - name = 'test_folder', - }}; - before_init = function(params, config) - vim.schedule(function() - vim.rpcrequest(1, "setup") - end) - end, - on_init = function(client, result) - TEST_RPC_CLIENT = client - vim.rpcrequest(1, "init", result) - end; - flags = { - allow_incremental_sync = options.allow_incremental_sync or false; - debounce_text_changes = options.debounce_text_changes or 0; - }; - settings = settings; - on_exit = function(...) - vim.rpcnotify(1, "exit", ...) - end; - } - ]=], - test_name, - M.fake_lsp_code, - M.fake_lsp_logfile, - timeout_ms or 1e3, - options or {}, - settings or {} - ) -end - ---- @class test.lsp.Config ---- @field test_name string ---- @field timeout_ms? integer ---- @field options? table ---- @field settings? table ---- ---- @field on_setup? fun() ---- @field on_init? fun(client: vim.lsp.Client, ...) ---- @field on_handler? fun(...) ---- @field on_exit? fun(code: integer, signal: integer) - ---- @param config test.lsp.Config -function M.test_rpc_server(config) - if config.test_name then - M.clear_notrace() - fake_lsp_server_setup( - config.test_name, - config.timeout_ms or 1e3, - config.options, - config.settings - ) - end - local client = setmetatable({}, { - __index = function(_, name) - -- Workaround for not being able to yield() inside __index for Lua 5.1 :( - -- Otherwise I would just return the value here. - return function(...) - return exec_lua( - [=[ - local name = ... - if type(TEST_RPC_CLIENT[name]) == 'function' then - return TEST_RPC_CLIENT[name](select(2, ...)) - else - return TEST_RPC_CLIENT[name] - end - ]=], - name, - ... - ) - end - end, - }) - --- @type integer, integer - local code, signal - local function on_request(method, args) - if method == 'setup' then - if config.on_setup then - config.on_setup() - end - return NIL - end - if method == 'init' then - if config.on_init then - config.on_init(client, unpack(args)) - end - return NIL - end - if method == 'handler' then - if config.on_handler then - config.on_handler(unpack(args)) - end - end - return NIL - end - local function on_notify(method, args) - if method == 'exit' then - code, signal = unpack(args) - return stop() - end - end - -- TODO specify timeout? - -- run(on_request, on_notify, nil, 1000) - run(on_request, on_notify, nil) - if config.on_exit then - config.on_exit(code, signal) - end - stop() - if config.test_name then - api.nvim_exec_autocmds('VimLeavePre', { modeline = false }) - end -end - -return M diff --git a/test/functional/plugin/lsp/incremental_sync_spec.lua b/test/functional/plugin/lsp/incremental_sync_spec.lua @@ -1,11 +1,11 @@ -- Test suite for testing interactions with the incremental sync algorithms powering the LSP client -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local api = helpers.api -local clear = helpers.clear -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local feed = helpers.feed +local api = t.api +local clear = t.clear +local eq = t.eq +local exec_lua = t.exec_lua +local feed = t.feed before_each(function() clear() diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) -local lsp_helpers = require('test.functional.plugin.lsp.helpers') +local t = require('test.functional.testutil')(after_each) +local t_lsp = require('test.functional.plugin.lsp.testutil') local Screen = require('test.functional.ui.screen') -local eq = helpers.eq -local dedent = helpers.dedent -local exec_lua = helpers.exec_lua -local insert = helpers.insert -local api = helpers.api +local eq = t.eq +local dedent = t.dedent +local exec_lua = t.exec_lua +local insert = t.insert +local api = t.api -local clear_notrace = lsp_helpers.clear_notrace -local create_server_definition = lsp_helpers.create_server_definition +local clear_notrace = t_lsp.clear_notrace +local create_server_definition = t_lsp.create_server_definition local text = dedent([[ auto add(int a, int b) { return a + b; } diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -1,19 +1,19 @@ -local helpers = require('test.functional.helpers')(after_each) -local lsp_helpers = require('test.functional.plugin.lsp.helpers') +local t = require('test.functional.testutil')(after_each) +local t_lsp = require('test.functional.plugin.lsp.testutil') local Screen = require('test.functional.ui.screen') -local command = helpers.command -local dedent = helpers.dedent -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local feed = helpers.feed -local feed_command = helpers.feed_command -local insert = helpers.insert -local matches = helpers.matches -local api = helpers.api - -local clear_notrace = lsp_helpers.clear_notrace -local create_server_definition = lsp_helpers.create_server_definition +local command = t.command +local dedent = t.dedent +local eq = t.eq +local exec_lua = t.exec_lua +local feed = t.feed +local feed_command = t.feed_command +local insert = t.insert +local matches = t.matches +local api = t.api + +local clear_notrace = t_lsp.clear_notrace +local create_server_definition = t_lsp.create_server_definition before_each(function() clear_notrace() diff --git a/test/functional/plugin/lsp/snippet_spec.lua b/test/functional/plugin/lsp/snippet_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local snippet = require('vim.lsp._snippet_grammar') local type = snippet.NodeType -local eq = helpers.eq -local exec_lua = helpers.exec_lua +local eq = t.eq +local exec_lua = t.exec_lua describe('vim.lsp._snippet_grammar', function() - before_each(helpers.clear) - after_each(helpers.clear) + before_each(t.clear) + after_each(t.clear) local parse = function(...) local res = exec_lua('return require("vim.lsp._snippet_grammar").parse(...)', ...) diff --git a/test/functional/plugin/lsp/testutil.lua b/test/functional/plugin/lsp/testutil.lua @@ -0,0 +1,219 @@ +local t = require('test.functional.testutil')(nil) + +local clear = t.clear +local exec_lua = t.exec_lua +local run = t.run +local stop = t.stop +local api = t.api +local NIL = vim.NIL + +local M = {} + +function M.clear_notrace() + -- problem: here be dragons + -- solution: don't look too closely for dragons + clear { + env = { + NVIM_LUA_NOTRACK = '1', + NVIM_APPNAME = 'nvim_lsp_test', + VIMRUNTIME = os.getenv 'VIMRUNTIME', + }, + } +end + +M.create_server_definition = [[ + function _create_server(opts) + opts = opts or {} + local server = {} + server.messages = {} + + function server.cmd(dispatchers) + local closing = false + local handlers = opts.handlers or {} + local srv = {} + + function srv.request(method, params, callback) + table.insert(server.messages, { + method = method, + params = params, + }) + local handler = handlers[method] + if handler then + local response, err = handler(method, params) + callback(err, response) + elseif method == 'initialize' then + callback(nil, { + capabilities = opts.capabilities or {} + }) + elseif method == 'shutdown' then + callback(nil, nil) + end + local request_id = #server.messages + return true, request_id + end + + function srv.notify(method, params) + table.insert(server.messages, { + method = method, + params = params + }) + if method == 'exit' then + dispatchers.on_exit(0, 15) + end + end + + function srv.is_closing() + return closing + end + + function srv.terminate() + closing = true + end + + return srv + end + + return server + end +]] + +-- Fake LSP server. +M.fake_lsp_code = 'test/functional/fixtures/fake-lsp-server.lua' +M.fake_lsp_logfile = 'Xtest-fake-lsp.log' + +local function fake_lsp_server_setup(test_name, timeout_ms, options, settings) + exec_lua( + [=[ + lsp = require('vim.lsp') + local test_name, fake_lsp_code, fake_lsp_logfile, timeout, options, settings = ... + TEST_RPC_CLIENT_ID = lsp.start_client { + cmd_env = { + NVIM_LOG_FILE = fake_lsp_logfile; + NVIM_LUA_NOTRACK = "1"; + NVIM_APPNAME = "nvim_lsp_test"; + }; + cmd = { + vim.v.progpath, '-l', fake_lsp_code, test_name, tostring(timeout), + }; + handlers = setmetatable({}, { + __index = function(t, method) + return function(...) + return vim.rpcrequest(1, 'handler', ...) + end + end; + }); + workspace_folders = {{ + uri = 'file://' .. vim.uv.cwd(), + name = 'test_folder', + }}; + before_init = function(params, config) + vim.schedule(function() + vim.rpcrequest(1, "setup") + end) + end, + on_init = function(client, result) + TEST_RPC_CLIENT = client + vim.rpcrequest(1, "init", result) + end; + flags = { + allow_incremental_sync = options.allow_incremental_sync or false; + debounce_text_changes = options.debounce_text_changes or 0; + }; + settings = settings; + on_exit = function(...) + vim.rpcnotify(1, "exit", ...) + end; + } + ]=], + test_name, + M.fake_lsp_code, + M.fake_lsp_logfile, + timeout_ms or 1e3, + options or {}, + settings or {} + ) +end + +--- @class test.lsp.Config +--- @field test_name string +--- @field timeout_ms? integer +--- @field options? table +--- @field settings? table +--- +--- @field on_setup? fun() +--- @field on_init? fun(client: vim.lsp.Client, ...) +--- @field on_handler? fun(...) +--- @field on_exit? fun(code: integer, signal: integer) + +--- @param config test.lsp.Config +function M.test_rpc_server(config) + if config.test_name then + M.clear_notrace() + fake_lsp_server_setup( + config.test_name, + config.timeout_ms or 1e3, + config.options, + config.settings + ) + end + local client = setmetatable({}, { + __index = function(_, name) + -- Workaround for not being able to yield() inside __index for Lua 5.1 :( + -- Otherwise I would just return the value here. + return function(...) + return exec_lua( + [=[ + local name = ... + if type(TEST_RPC_CLIENT[name]) == 'function' then + return TEST_RPC_CLIENT[name](select(2, ...)) + else + return TEST_RPC_CLIENT[name] + end + ]=], + name, + ... + ) + end + end, + }) + --- @type integer, integer + local code, signal + local function on_request(method, args) + if method == 'setup' then + if config.on_setup then + config.on_setup() + end + return NIL + end + if method == 'init' then + if config.on_init then + config.on_init(client, unpack(args)) + end + return NIL + end + if method == 'handler' then + if config.on_handler then + config.on_handler(unpack(args)) + end + end + return NIL + end + local function on_notify(method, args) + if method == 'exit' then + code, signal = unpack(args) + return stop() + end + end + -- TODO specify timeout? + -- run(on_request, on_notify, nil, 1000) + run(on_request, on_notify, nil) + if config.on_exit then + config.on_exit(code, signal) + end + stop() + if config.test_name then + api.nvim_exec_autocmds('VimLeavePre', { modeline = false }) + end +end + +return M diff --git a/test/functional/plugin/lsp/utils_spec.lua b/test/functional/plugin/lsp/utils_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local feed = helpers.feed +local feed = t.feed -local eq = helpers.eq -local exec_lua = helpers.exec_lua +local eq = t.eq +local exec_lua = t.exec_lua describe('vim.lsp.util', function() - before_each(helpers.clear) + before_each(t.clear) describe('stylize_markdown', function() local stylize_markdown = function(content, opts) @@ -142,7 +142,7 @@ describe('vim.lsp.util', function() local screen before_each(function() - helpers.clear() + t.clear() screen = Screen.new(80, 80) screen:attach() feed('79i<CR><Esc>') -- fill screen with empty lines diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua @@ -1,36 +1,36 @@ -local helpers = require('test.functional.helpers')(after_each) -local lsp_helpers = require('test.functional.plugin.lsp.helpers') - -local assert_log = helpers.assert_log -local buf_lines = helpers.buf_lines -local clear = helpers.clear -local command = helpers.command -local dedent = helpers.dedent -local exec_lua = helpers.exec_lua -local eq = helpers.eq -local eval = helpers.eval -local matches = helpers.matches -local pcall_err = helpers.pcall_err +local t = require('test.functional.testutil')(after_each) +local t_lsp = require('test.functional.plugin.lsp.testutil') + +local assert_log = t.assert_log +local buf_lines = t.buf_lines +local clear = t.clear +local command = t.command +local dedent = t.dedent +local exec_lua = t.exec_lua +local eq = t.eq +local eval = t.eval +local matches = t.matches +local pcall_err = t.pcall_err local pesc = vim.pesc -local insert = helpers.insert -local fn = helpers.fn -local retry = helpers.retry -local stop = helpers.stop +local insert = t.insert +local fn = t.fn +local retry = t.retry +local stop = t.stop local NIL = vim.NIL -local read_file = helpers.read_file -local write_file = helpers.write_file -local is_ci = helpers.is_ci -local api = helpers.api -local is_os = helpers.is_os -local skip = helpers.skip -local mkdir = helpers.mkdir -local tmpname = helpers.tmpname - -local clear_notrace = lsp_helpers.clear_notrace -local create_server_definition = lsp_helpers.create_server_definition -local fake_lsp_code = lsp_helpers.fake_lsp_code -local fake_lsp_logfile = lsp_helpers.fake_lsp_logfile -local test_rpc_server = lsp_helpers.test_rpc_server +local read_file = t.read_file +local write_file = t.write_file +local is_ci = t.is_ci +local api = t.api +local is_os = t.is_os +local skip = t.skip +local mkdir = t.mkdir +local tmpname = t.tmpname + +local clear_notrace = t_lsp.clear_notrace +local create_server_definition = t_lsp.create_server_definition +local fake_lsp_code = t_lsp.fake_lsp_code +local fake_lsp_logfile = t_lsp.fake_lsp_logfile +local test_rpc_server = t_lsp.test_rpc_server local function get_buf_option(name, bufnr) bufnr = bufnr or 'BUFFER' @@ -249,7 +249,7 @@ describe('LSP', function() if is_ci() then pending('hangs the build on CI #14028, re-enable with freeze timeout #14204') return - elseif helpers.skip_fragile(pending) then + elseif t.skip_fragile(pending) then return end local expected_handlers = { @@ -1481,7 +1481,7 @@ describe('LSP', function() end, on_handler = function(err, result, ctx) if ctx.method == 'start' then - helpers.command('normal! 1Go') + t.command('normal! 1Go') client.notify('finish') end eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') @@ -2368,7 +2368,7 @@ describe('LSP', function() end) describe('lsp.util.rename', function() - local pathsep = helpers.get_pathsep() + local pathsep = t.get_pathsep() it('Can rename an existing file', function() local old = tmpname() @@ -2404,7 +2404,7 @@ describe('LSP', function() os.remove(old_dir) os.remove(new_dir) - helpers.mkdir_p(old_dir) + t.mkdir_p(old_dir) local file = 'file.txt' write_file(old_dir .. pathsep .. file, 'Test content') @@ -2440,7 +2440,7 @@ describe('LSP', function() local new = tmpname() os.remove(old) os.remove(new) - helpers.mkdir_p(old) + t.mkdir_p(old) local result = exec_lua( [[ diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua @@ -1,17 +1,17 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local command, feed = helpers.command, helpers.feed -local clear = helpers.clear -local exec_lua = helpers.exec_lua -local fn = helpers.fn -local nvim_prog = helpers.nvim_prog -local matches = helpers.matches -local write_file = helpers.write_file -local tmpname = helpers.tmpname -local eq = helpers.eq +local command, feed = t.command, t.feed +local clear = t.clear +local exec_lua = t.exec_lua +local fn = t.fn +local nvim_prog = t.nvim_prog +local matches = t.matches +local write_file = t.write_file +local tmpname = t.tmpname +local eq = t.eq local pesc = vim.pesc -local skip = helpers.skip -local is_ci = helpers.is_ci +local skip = t.skip +local is_ci = t.is_ci -- Collects all names passed to find_path() after attempting ":Man foo". local function get_search_history(name) diff --git a/test/functional/plugin/matchparen_spec.lua b/test/functional/plugin/matchparen_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local api = helpers.api -local feed = helpers.feed -local eq = helpers.eq +local clear = t.clear +local command = t.command +local api = t.api +local feed = t.feed +local eq = t.eq describe('matchparen', function() local screen --- @type test.functional.ui.screen diff --git a/test/functional/plugin/msgpack_spec.lua b/test/functional/plugin/msgpack_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local api = helpers.api -local eq = helpers.eq -local nvim_eval = helpers.eval -local nvim_command = helpers.command -local exc_exec = helpers.exc_exec -local ok = helpers.ok +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local api = t.api +local eq = t.eq +local nvim_eval = t.eval +local nvim_command = t.command +local exc_exec = t.exc_exec +local ok = t.ok local NIL = vim.NIL describe('autoload/msgpack.vim', function() diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear +local clear = t.clear local eq, api, nvim_eval, nvim_command, exc_exec, fn, nvim_feed = - helpers.eq, helpers.api, helpers.eval, helpers.command, helpers.exc_exec, helpers.fn, helpers.feed -local neq = helpers.neq -local read_file = helpers.read_file + t.eq, t.api, t.eval, t.command, t.exc_exec, t.fn, t.feed +local neq = t.neq +local read_file = t.read_file -local shada_helpers = require('test.functional.shada.helpers') -local get_shada_rw = shada_helpers.get_shada_rw +local t_shada = require('test.functional.shada.testutil') +local get_shada_rw = t_shada.get_shada_rw local function reset(shada_file) clear { args = { '-u', 'NORC', '-i', shada_file or 'NONE' } } @@ -2612,7 +2612,7 @@ end) describe('plugin/shada.vim', function() local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0) - local eol = helpers.is_os('win') and '\r\n' or '\n' + local eol = t.is_os('win') and '\r\n' or '\n' before_each(function() -- Note: reset() is called explicitly in each test. os.remove(fname) diff --git a/test/functional/plugin/tohtml_spec.lua b/test/functional/plugin/tohtml_spec.lua @@ -1,13 +1,13 @@ local Screen = require('test.functional.ui.screen') -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local exec = helpers.exec -local exec_lua = helpers.exec_lua -local eq = helpers.eq -local fn = helpers.fn -local api = helpers.api -local insert = helpers.insert +local clear = t.clear +local exec = t.exec +local exec_lua = t.exec_lua +local eq = t.eq +local fn = t.fn +local api = t.api +local insert = t.insert local function html_syntax_match() local styles = diff --git a/test/functional/plugin/tutor_spec.lua b/test/functional/plugin/tutor_spec.lua @@ -1,9 +1,9 @@ local Screen = require('test.functional.ui.screen') -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local feed = helpers.feed -local is_os = helpers.is_os +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local feed = t.feed +local is_os = t.is_os describe(':Tutor', function() local screen --- @type test.functional.ui.screen diff --git a/test/functional/plugin/vim_syntax_spec.lua b/test/functional/plugin/vim_syntax_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local exec = helpers.exec -local api = helpers.api +local clear = t.clear +local exec = t.exec +local api = t.api describe('Vimscript syntax highlighting', function() local screen --- @type test.functional.ui.screen before_each(function() clear() - helpers.add_builddir_to_rtp() + t.add_builddir_to_rtp() exec([[ setfiletype vim syntax on diff --git a/test/functional/preload.lua b/test/functional/preload.lua @@ -1,10 +1,10 @@ -- Modules loaded here will NOT be cleared and reloaded by Busted. -- Busted started doing this to help provide more isolation. See issue #62 -- for more information about this. -local helpers = require('test.functional.helpers')(nil) +local t = require('test.functional.testutil')(nil) require('test.functional.ui.screen') local busted = require('busted') -local is_os = helpers.is_os +local is_os = t.is_os if is_os('win') then local ffi = require('ffi') diff --git a/test/functional/provider/clipboard_spec.lua b/test/functional/provider/clipboard_spec.lua @@ -1,12 +1,11 @@ -- Test clipboard provider support -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local feed_command, expect, eq, eval, source = - helpers.feed_command, helpers.expect, helpers.eq, helpers.eval, helpers.source -local command = helpers.command -local api = helpers.api +local clear, feed, insert = t.clear, t.feed, t.insert +local feed_command, expect, eq, eval, source = t.feed_command, t.expect, t.eq, t.eval, t.source +local command = t.command +local api = t.api local function basic_register_test(noblock) insert('some words') diff --git a/test/functional/provider/define_spec.lua b/test/functional/provider/define_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local eval, command = helpers.eval, helpers.command -local eq, run, stop = helpers.eq, helpers.run, helpers.stop -local clear = helpers.clear -local api = helpers.api +local t = require('test.functional.testutil')(after_each) +local eval, command = t.eval, t.command +local eq, run, stop = t.eq, t.run, t.stop +local clear = t.clear +local api = t.api local function get_prefix(sync) if sync then @@ -28,7 +28,7 @@ local function runx(sync, handler, on_setup) local function setup_cb(...) on_setup(...) -- need to stop on setup callback because there's two session:request - -- calls in `request/helpers.lua`. The second call will always return + -- calls in `request/t.lua`. The second call will always return -- after pending notification/request callbacks are processed stop() end @@ -324,7 +324,7 @@ local function function_specs_for(fn, sync, first_arg_factory, init) end) it('with range', function() - helpers.insert([[ + t.insert([[ foo bar baz diff --git a/test/functional/provider/nodejs_spec.lua b/test/functional/provider/nodejs_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq, clear = helpers.eq, helpers.clear -local missing_provider = helpers.missing_provider -local command = helpers.command -local write_file = helpers.write_file -local eval = helpers.eval -local retry = helpers.retry +local t = require('test.functional.testutil')(after_each) +local eq, clear = t.eq, t.clear +local missing_provider = t.missing_provider +local command = t.command +local write_file = t.write_file +local eval = t.eval +local retry = t.retry do clear() diff --git a/test/functional/provider/perl_spec.lua b/test/functional/provider/perl_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq, clear = helpers.eq, helpers.clear -local missing_provider = helpers.missing_provider -local command = helpers.command -local write_file = helpers.write_file -local eval = helpers.eval -local retry = helpers.retry -local api = helpers.api -local insert = helpers.insert -local expect = helpers.expect -local feed = helpers.feed +local t = require('test.functional.testutil')(after_each) +local eq, clear = t.eq, t.clear +local missing_provider = t.missing_provider +local command = t.command +local write_file = t.write_file +local eval = t.eval +local retry = t.retry +local api = t.api +local insert = t.insert +local expect = t.expect +local feed = t.feed do clear() diff --git a/test/functional/provider/provider_spec.lua b/test/functional/provider/provider_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, eval = helpers.clear, helpers.eval -local command = helpers.command -local eq = helpers.eq -local pcall_err = helpers.pcall_err +local t = require('test.functional.testutil')(after_each) +local clear, eval = t.clear, t.eval +local command = t.command +local eq = t.eq +local pcall_err = t.pcall_err describe('providers', function() before_each(function() diff --git a/test/functional/provider/python3_spec.lua b/test/functional/provider/python3_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) -local assert_alive = helpers.assert_alive -local eval, command, feed = helpers.eval, helpers.command, helpers.feed -local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert -local expect, write_file = helpers.expect, helpers.write_file -local feed_command = helpers.feed_command -local source = helpers.source -local missing_provider = helpers.missing_provider -local matches = helpers.matches -local pcall_err = helpers.pcall_err -local fn = helpers.fn -local dedent = helpers.dedent +local t = require('test.functional.testutil')(after_each) +local assert_alive = t.assert_alive +local eval, command, feed = t.eval, t.command, t.feed +local eq, clear, insert = t.eq, t.clear, t.insert +local expect, write_file = t.expect, t.write_file +local feed_command = t.feed_command +local source = t.source +local missing_provider = t.missing_provider +local matches = t.matches +local pcall_err = t.pcall_err +local fn = t.fn +local dedent = t.dedent do clear() @@ -153,7 +153,7 @@ describe('python3 provider', function() end) it('RPC call to expand("<afile>") during BufDelete #5245 #5617', function() - helpers.add_builddir_to_rtp() + t.add_builddir_to_rtp() source([=[ python3 << EOF import vim diff --git a/test/functional/provider/ruby_spec.lua b/test/functional/provider/ruby_spec.lua @@ -1,20 +1,20 @@ -local helpers = require('test.functional.helpers')(after_each) - -local assert_alive = helpers.assert_alive -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local exc_exec = helpers.exc_exec -local expect = helpers.expect -local feed = helpers.feed -local feed_command = helpers.feed_command -local fn = helpers.fn -local insert = helpers.insert -local api = helpers.api -local missing_provider = helpers.missing_provider -local matches = helpers.matches -local write_file = helpers.write_file -local pcall_err = helpers.pcall_err +local t = require('test.functional.testutil')(after_each) + +local assert_alive = t.assert_alive +local clear = t.clear +local command = t.command +local eq = t.eq +local exc_exec = t.exc_exec +local expect = t.expect +local feed = t.feed +local feed_command = t.feed_command +local fn = t.fn +local insert = t.insert +local api = t.api +local missing_provider = t.missing_provider +local matches = t.matches +local write_file = t.write_file +local pcall_err = t.pcall_err do clear() @@ -103,7 +103,7 @@ end) describe('ruby provider', function() it('RPC call to expand("<afile>") during BufDelete #5245 #5617', function() - helpers.add_builddir_to_rtp() + t.add_builddir_to_rtp() command([=[autocmd BufDelete * ruby VIM::evaluate('expand("<afile>")')]=]) feed_command('help help') assert_alive() diff --git a/test/functional/script/luacats_grammar_spec.lua b/test/functional/script/luacats_grammar_spec.lua @@ -1,5 +1,5 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq = helpers.eq +local t = require('test.functional.testutil')(after_each) +local eq = t.eq local grammar = require('scripts/luacats_grammar') diff --git a/test/functional/script/luacats_parser_spec.lua b/test/functional/script/luacats_parser_spec.lua @@ -1,5 +1,5 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq = helpers.eq +local t = require('test.functional.testutil')(after_each) +local eq = t.eq local parser = require('scripts/luacats_parser') diff --git a/test/functional/script/text_utils_spec.lua b/test/functional/script/text_utils_spec.lua @@ -1,6 +1,6 @@ -local helpers = require('test.functional.helpers')(after_each) -local exec_lua = helpers.exec_lua -local eq = helpers.eq +local t = require('test.functional.testutil')(after_each) +local exec_lua = t.exec_lua +local eq = t.eq local function md_to_vimdoc(text, start_indent, indent, text_width) return exec_lua( @@ -28,7 +28,7 @@ end describe('md_to_vimdoc', function() before_each(function() - helpers.clear() + t.clear() end) test('can render para after fenced code', { diff --git a/test/functional/shada/buffers_spec.lua b/test/functional/shada/buffers_spec.lua @@ -1,10 +1,10 @@ -- shada buffer list saving/reading support -local helpers = require('test.functional.helpers')(after_each) -local nvim_command, fn, eq, api = helpers.command, helpers.fn, helpers.eq, helpers.api -local expect_exit = helpers.expect_exit +local t = require('test.functional.testutil')(after_each) +local nvim_command, fn, eq, api = t.command, t.fn, t.eq, t.api +local expect_exit = t.expect_exit -local shada_helpers = require('test.functional.shada.helpers') -local reset, clear = shada_helpers.reset, shada_helpers.clear +local t_shada = require('test.functional.shada.testutil') +local reset, clear = t_shada.reset, t_shada.clear describe('shada support code', function() local testfilename = 'Xtestfile-functional-shada-buffers' diff --git a/test/functional/shada/compatibility_spec.lua b/test/functional/shada/compatibility_spec.lua @@ -1,18 +1,17 @@ -- ShaDa compatibility support -local helpers = require('test.functional.helpers')(after_each) -local nvim_command, fn, eq = helpers.command, helpers.fn, helpers.eq -local exc_exec = helpers.exc_exec +local t = require('test.functional.testutil')(after_each) +local nvim_command, fn, eq = t.command, t.fn, t.eq +local exc_exec = t.exc_exec -local shada_helpers = require('test.functional.shada.helpers') -local reset, clear, get_shada_rw = - shada_helpers.reset, shada_helpers.clear, shada_helpers.get_shada_rw -local read_shada_file = shada_helpers.read_shada_file +local t_shada = require('test.functional.shada.testutil') +local reset, clear, get_shada_rw = t_shada.reset, t_shada.clear, t_shada.get_shada_rw +local read_shada_file = t_shada.read_shada_file local wshada, sdrcmd, shada_fname = get_shada_rw('Xtest-functional-shada-compatibility.shada') local mock_file_path = '/a/b/' local mock_file_path2 = '/d/e/' -if helpers.is_os('win') then +if t.is_os('win') then mock_file_path = 'C:/a/' mock_file_path2 = 'C:/d/' end diff --git a/test/functional/shada/errors_spec.lua b/test/functional/shada/errors_spec.lua @@ -1,10 +1,9 @@ -- ShaDa errors handling support -local helpers = require('test.functional.helpers')(after_each) -local nvim_command, eq, exc_exec = helpers.command, helpers.eq, helpers.exc_exec +local t = require('test.functional.testutil')(after_each) +local nvim_command, eq, exc_exec = t.command, t.eq, t.exc_exec -local shada_helpers = require('test.functional.shada.helpers') -local reset, clear, get_shada_rw = - shada_helpers.reset, shada_helpers.clear, shada_helpers.get_shada_rw +local t_shada = require('test.functional.shada.testutil') +local reset, clear, get_shada_rw = t_shada.reset, t_shada.clear, t_shada.get_shada_rw local wshada, sdrcmd, shada_fname, clean = get_shada_rw('Xtest-functional-shada-errors.shada') diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua @@ -1,87 +0,0 @@ -local helpers = require('test.functional.helpers')(nil) -local api = helpers.api -local write_file = helpers.write_file -local concat_tables = helpers.concat_tables - -local tmpname = helpers.tmpname() - --- o={ --- args=…, --- args_rm=…, --- shadafile=…, --- } -local function reset(o) - assert(o == nil or type(o) == 'table' or type(o) == 'string') - o = o and o or {} - local args_rm = o.args_rm or {} - table.insert(args_rm, '-i') - local args = { - '-i', - o.shadafile or tmpname, - } - if type(o) == 'string' then - args = concat_tables(args, { '--cmd', o }) - elseif o.args then - args = concat_tables(args, o.args) - end - helpers.clear { - args_rm = args_rm, - args = args, - } - api.nvim_set_var('tmpname', tmpname) -end - -local clear = function() - helpers.expect_exit(helpers.command, 'qall!') - os.remove(tmpname) -end - -local get_shada_rw = function(fname) - local wshada = function(text) - write_file(fname, text, true) - end - local sdrcmd = function(bang) - return 'rshada' .. (bang and '!' or '') .. ' ' .. fname - end - local clean = function() - os.remove(fname) - local i = ('a'):byte() - while i <= ('z'):byte() do - if not os.remove(fname .. ('.tmp.%c'):format(i)) then - break - end - i = i + 1 - end - end - return wshada, sdrcmd, fname, clean -end - -local mpack_keys = { 'type', 'timestamp', 'length', 'value' } - -local read_shada_file = function(fname) - local fd = io.open(fname, 'r') - local mstring = fd:read('*a') - fd:close() - local unpack = vim.mpack.Unpacker() - local ret = {} - local cur, val - local i = 0 - local off = 1 - while off <= #mstring do - val, off = unpack(mstring, off) - if i % 4 == 0 then - cur = {} - ret[#ret + 1] = cur - end - cur[mpack_keys[(i % 4) + 1]] = val - i = i + 1 - end - return ret -end - -return { - reset = reset, - clear = clear, - get_shada_rw = get_shada_rw, - read_shada_file = read_shada_file, -} diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua @@ -1,12 +1,11 @@ -- ShaDa history saving/reading support -local helpers = require('test.functional.helpers')(after_each) -local nvim_command, fn, api, nvim_feed, eq = - helpers.command, helpers.fn, helpers.api, helpers.feed, helpers.eq -local assert_alive = helpers.assert_alive -local expect_exit = helpers.expect_exit - -local shada_helpers = require('test.functional.shada.helpers') -local reset, clear = shada_helpers.reset, shada_helpers.clear +local t = require('test.functional.testutil')(after_each) +local nvim_command, fn, api, nvim_feed, eq = t.command, t.fn, t.api, t.feed, t.eq +local assert_alive = t.assert_alive +local expect_exit = t.expect_exit + +local t_shada = require('test.functional.shada.testutil') +local reset, clear = t_shada.reset, t_shada.clear describe('ShaDa support code', function() before_each(reset) diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua @@ -1,12 +1,12 @@ -- ShaDa marks saving/reading support -local helpers = require('test.functional.helpers')(after_each) -local api, nvim_command, fn, eq = helpers.api, helpers.command, helpers.fn, helpers.eq -local feed = helpers.feed -local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture -local expect_exit = helpers.expect_exit +local t = require('test.functional.testutil')(after_each) +local api, nvim_command, fn, eq = t.api, t.command, t.fn, t.eq +local feed = t.feed +local exc_exec, exec_capture = t.exc_exec, t.exec_capture +local expect_exit = t.expect_exit -local shada_helpers = require('test.functional.shada.helpers') -local reset, clear = shada_helpers.reset, shada_helpers.clear +local t_shada = require('test.functional.shada.testutil') +local reset, clear = t_shada.reset, t_shada.clear local nvim_current_line = function() return api.nvim_win_get_cursor(0)[1] @@ -216,7 +216,7 @@ describe('ShaDa support code', function() -- -c temporary sets lnum to zero to make `+/pat` work, so calling setpcmark() -- during -c used to add item with zero lnum to jump list. it('does not create incorrect file for non-existent buffers when writing from -c', function() - local argv = helpers.new_argv { + local argv = t.new_argv { args_rm = { '-i', '--embed', -- no --embed @@ -235,7 +235,7 @@ describe('ShaDa support code', function() end) it('does not create incorrect file for non-existent buffers opened from -c', function() - local argv = helpers.new_argv { + local argv = t.new_argv { args_rm = { '-i', '--embed', -- no --embed diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua @@ -1,18 +1,17 @@ -- ShaDa merging data support -local helpers = require('test.functional.helpers')(after_each) -local nvim_command, fn, eq = helpers.command, helpers.fn, helpers.eq -local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture -local api = helpers.api +local t = require('test.functional.testutil')(after_each) +local nvim_command, fn, eq = t.command, t.fn, t.eq +local exc_exec, exec_capture = t.exc_exec, t.exec_capture +local api = t.api -local shada_helpers = require('test.functional.shada.helpers') -local reset, clear, get_shada_rw = - shada_helpers.reset, shada_helpers.clear, shada_helpers.get_shada_rw -local read_shada_file = shada_helpers.read_shada_file +local t_shada = require('test.functional.shada.testutil') +local reset, clear, get_shada_rw = t_shada.reset, t_shada.clear, t_shada.get_shada_rw +local read_shada_file = t_shada.read_shada_file local wshada, sdrcmd, shada_fname = get_shada_rw('Xtest-functional-shada-merging.shada') local mock_file_path = '/a/b/' -if helpers.is_os('win') then +if t.is_os('win') then mock_file_path = 'C:/a/' end @@ -698,9 +697,9 @@ describe('ShaDa marks support code', function() for _, v in ipairs(read_shada_file(shada_fname)) do if v.type == 7 then local name = ('%c'):format(v.value.n) - local t = found[name] or {} - t[v.value.f] = (t[v.value.f] or 0) + 1 - found[name] = t + local _t = found[name] or {} + _t[v.value.f] = (_t[v.value.f] or 0) + 1 + found[name] = _t end end eq({ ['0'] = { [mock_file_path .. '-'] = 1 }, A = { [mock_file_path .. '?'] = 1 } }, found) @@ -1018,14 +1017,14 @@ describe('ShaDa jumps support code', function() eq(0, exc_exec(sdrcmd())) shada = '' for i = 1, 101 do - local t = i * 2 + local _t = i * 2 shada = shada .. ('\008\204%c\019\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\204%c'):format( - t, - t + _t, + _t ) - jumps[(t > #jumps + 1) and (#jumps + 1) or t] = - { file = '' .. mock_file_path .. 'c', line = t } + jumps[(_t > #jumps + 1) and (#jumps + 1) or _t] = + { file = '' .. mock_file_path .. 'c', line = _t } end wshada(shada) eq(0, exc_exec('wshada ' .. shada_fname)) @@ -1149,13 +1148,13 @@ describe('ShaDa changes support code', function() eq(0, exc_exec(sdrcmd())) shada = '' for i = 1, 101 do - local t = i * 2 + local _t = i * 2 shada = shada .. ('\011\204%c\019\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\204%c'):format( - t, - t + _t, + _t ) - changes[(t > #changes + 1) and (#changes + 1) or t] = { line = t } + changes[(_t > #changes + 1) and (#changes + 1) or _t] = { line = _t } end wshada(shada) eq(0, exc_exec('wshada ' .. shada_fname)) @@ -1178,11 +1177,11 @@ describe('ShaDa changes support code', function() nvim_command('keepjumps call setline(1, range(202))') local shada = '' for i = 1, 101 do - local t = i * 2 + local _t = i * 2 shada = shada .. ('\011\204%c\019\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\204%c'):format( - t, - t + _t, + _t ) end wshada(shada) @@ -1197,8 +1196,8 @@ describe('ShaDa changes support code', function() changes[i] = { line = i } end for i = 1, 101 do - local t = i * 2 - changes[(t > #changes + 1) and (#changes + 1) or t] = { line = t } + local _t = i * 2 + changes[(_t > #changes + 1) and (#changes + 1) or _t] = { line = _t } end wshada(shada) eq(0, exc_exec('wshada ' .. shada_fname)) diff --git a/test/functional/shada/registers_spec.lua b/test/functional/shada/registers_spec.lua @@ -1,10 +1,10 @@ -- ShaDa registers saving/reading support -local helpers = require('test.functional.helpers')(after_each) -local nvim_command, fn, eq = helpers.command, helpers.fn, helpers.eq +local t = require('test.functional.testutil')(after_each) +local nvim_command, fn, eq = t.command, t.fn, t.eq -local shada_helpers = require('test.functional.shada.helpers') -local reset, clear = shada_helpers.reset, shada_helpers.clear -local expect_exit = helpers.expect_exit +local t_shada = require('test.functional.shada.testutil') +local reset, clear = t_shada.reset, t_shada.clear +local expect_exit = t.expect_exit local setreg = function(name, contents, typ) if type(contents) == 'string' then diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua @@ -1,18 +1,17 @@ -- Other ShaDa tests -local helpers = require('test.functional.helpers')(after_each) -local api, nvim_command, fn, eq = helpers.api, helpers.command, helpers.fn, helpers.eq +local t = require('test.functional.testutil')(after_each) +local api, nvim_command, fn, eq = t.api, t.command, t.fn, t.eq local write_file, spawn, set_session, nvim_prog, exc_exec = - helpers.write_file, helpers.spawn, helpers.set_session, helpers.nvim_prog, helpers.exc_exec -local is_os = helpers.is_os -local skip = helpers.skip + t.write_file, t.spawn, t.set_session, t.nvim_prog, t.exc_exec +local is_os = t.is_os +local skip = t.skip local uv = vim.uv -local paths = helpers.paths +local paths = t.paths -local shada_helpers = require('test.functional.shada.helpers') -local reset, clear, get_shada_rw = - shada_helpers.reset, shada_helpers.clear, shada_helpers.get_shada_rw -local read_shada_file = shada_helpers.read_shada_file +local t_shada = require('test.functional.shada.testutil') +local reset, clear, get_shada_rw = t_shada.reset, t_shada.clear, t_shada.get_shada_rw +local read_shada_file = t_shada.read_shada_file local wshada, _, shada_fname, clean = get_shada_rw('Xtest-functional-shada-shada.shada') diff --git a/test/functional/shada/testutil.lua b/test/functional/shada/testutil.lua @@ -0,0 +1,87 @@ +local t = require('test.functional.testutil')(nil) +local api = t.api +local write_file = t.write_file +local concat_tables = t.concat_tables + +local tmpname = t.tmpname() + +-- o={ +-- args=…, +-- args_rm=…, +-- shadafile=…, +-- } +local function reset(o) + assert(o == nil or type(o) == 'table' or type(o) == 'string') + o = o and o or {} + local args_rm = o.args_rm or {} + table.insert(args_rm, '-i') + local args = { + '-i', + o.shadafile or tmpname, + } + if type(o) == 'string' then + args = concat_tables(args, { '--cmd', o }) + elseif o.args then + args = concat_tables(args, o.args) + end + t.clear { + args_rm = args_rm, + args = args, + } + api.nvim_set_var('tmpname', tmpname) +end + +local clear = function() + t.expect_exit(t.command, 'qall!') + os.remove(tmpname) +end + +local get_shada_rw = function(fname) + local wshada = function(text) + write_file(fname, text, true) + end + local sdrcmd = function(bang) + return 'rshada' .. (bang and '!' or '') .. ' ' .. fname + end + local clean = function() + os.remove(fname) + local i = ('a'):byte() + while i <= ('z'):byte() do + if not os.remove(fname .. ('.tmp.%c'):format(i)) then + break + end + i = i + 1 + end + end + return wshada, sdrcmd, fname, clean +end + +local mpack_keys = { 'type', 'timestamp', 'length', 'value' } + +local read_shada_file = function(fname) + local fd = io.open(fname, 'r') + local mstring = fd:read('*a') + fd:close() + local unpack = vim.mpack.Unpacker() + local ret = {} + local cur, val + local i = 0 + local off = 1 + while off <= #mstring do + val, off = unpack(mstring, off) + if i % 4 == 0 then + cur = {} + ret[#ret + 1] = cur + end + cur[mpack_keys[(i % 4) + 1]] = val + i = i + 1 + end + return ret +end + +return { + reset = reset, + clear = clear, + get_shada_rw = get_shada_rw, + read_shada_file = read_shada_file, +} diff --git a/test/functional/shada/variables_spec.lua b/test/functional/shada/variables_spec.lua @@ -1,11 +1,10 @@ -- ShaDa variables saving/reading support -local helpers = require('test.functional.helpers')(after_each) -local api, fn, nvim_command, eq, eval = - helpers.api, helpers.fn, helpers.command, helpers.eq, helpers.eval -local expect_exit = helpers.expect_exit +local t = require('test.functional.testutil')(after_each) +local api, fn, nvim_command, eq, eval = t.api, t.fn, t.command, t.eq, t.eval +local expect_exit = t.expect_exit -local shada_helpers = require('test.functional.shada.helpers') -local reset, clear = shada_helpers.reset, shada_helpers.clear +local t_shada = require('test.functional.shada.testutil') +local reset, clear = t_shada.reset, t_shada.clear describe('ShaDa support code', function() before_each(reset) diff --git a/test/functional/terminal/altscreen_spec.lua b/test/functional/terminal/altscreen_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) -local thelpers = require('test.functional.terminal.helpers') -local clear, eq, api = helpers.clear, helpers.eq, helpers.api -local feed = helpers.feed -local feed_data = thelpers.feed_data -local enter_altscreen = thelpers.enter_altscreen -local exit_altscreen = thelpers.exit_altscreen +local t = require('test.functional.testutil')(after_each) +local tt = require('test.functional.terminal.testutil') +local clear, eq, api = t.clear, t.eq, t.api +local feed = t.feed +local feed_data = tt.feed_data +local enter_altscreen = tt.enter_altscreen +local exit_altscreen = tt.exit_altscreen -if helpers.skip(helpers.is_os('win')) then +if t.skip(t.is_os('win')) then return end @@ -15,7 +15,7 @@ describe(':terminal altscreen', function() before_each(function() clear() - screen = thelpers.screen_setup() + screen = tt.screen_setup() feed_data({ 'line1', 'line2', diff --git a/test/functional/terminal/api_spec.lua b/test/functional/terminal/api_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local child_session = require('test.functional.terminal.helpers') -local ok = helpers.ok +local t = require('test.functional.testutil')(after_each) +local tt = require('test.functional.terminal.testutil') +local ok = t.ok -if helpers.skip(helpers.is_os('win')) then +if t.skip(t.is_os('win')) then return end @@ -11,9 +11,9 @@ describe('api', function() local socket_name = './Xtest_functional_api.sock' before_each(function() - helpers.clear() + t.clear() os.remove(socket_name) - screen = child_session.setup_child_nvim({ + screen = tt.setup_child_nvim({ '-u', 'NONE', '-i', @@ -21,7 +21,7 @@ describe('api', function() '--cmd', 'colorscheme vim', '--cmd', - helpers.nvim_set .. ' notermguicolors', + t.nvim_set .. ' notermguicolors', }) end) after_each(function() @@ -39,7 +39,7 @@ describe('api', function() } -- Start the socket from the child nvim. - child_session.feed_data(":echo serverstart('" .. socket_name .. "')\n") + tt.feed_data(":echo serverstart('" .. socket_name .. "')\n") -- Wait for socket creation. screen:expect([[ @@ -49,10 +49,10 @@ describe('api', function() {3:-- TERMINAL --} | ]]) - local socket_session1 = helpers.connect(socket_name) - local socket_session2 = helpers.connect(socket_name) + local socket_session1 = t.connect(socket_name) + local socket_session2 = t.connect(socket_name) - child_session.feed_data('i[tui] insert-mode') + tt.feed_data('i[tui] insert-mode') -- Wait for stdin to be processed. screen:expect([[ [tui] insert-mode{1: } | diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua @@ -1,25 +1,25 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local thelpers = require('test.functional.terminal.helpers') -local assert_alive = helpers.assert_alive -local feed, clear = helpers.feed, helpers.clear -local poke_eventloop = helpers.poke_eventloop -local nvim_prog = helpers.nvim_prog -local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source -local pcall_err = helpers.pcall_err -local eq, neq = helpers.eq, helpers.neq -local api = helpers.api -local retry = helpers.retry -local testprg = helpers.testprg -local write_file = helpers.write_file -local command = helpers.command -local exc_exec = helpers.exc_exec -local matches = helpers.matches -local exec_lua = helpers.exec_lua +local tt = require('test.functional.terminal.testutil') +local assert_alive = t.assert_alive +local feed, clear = t.feed, t.clear +local poke_eventloop = t.poke_eventloop +local nvim_prog = t.nvim_prog +local eval, feed_command, source = t.eval, t.feed_command, t.source +local pcall_err = t.pcall_err +local eq, neq = t.eq, t.neq +local api = t.api +local retry = t.retry +local testprg = t.testprg +local write_file = t.write_file +local command = t.command +local exc_exec = t.exc_exec +local matches = t.matches +local exec_lua = t.exec_lua local sleep = vim.uv.sleep -local fn = helpers.fn -local is_os = helpers.is_os -local skip = helpers.skip +local fn = t.fn +local is_os = t.is_os +local skip = t.skip describe(':terminal buffer', function() local screen @@ -27,7 +27,7 @@ describe(':terminal buffer', function() before_each(function() clear() command('set modifiable swapfile undolevels=20') - screen = thelpers.screen_setup() + screen = tt.screen_setup() end) it('terminal-mode forces various options', function() @@ -266,7 +266,7 @@ describe(':terminal buffer', function() it('does not segfault when pasting empty register #13955', function() feed('<c-\\><c-n>') feed_command('put a') -- register a is empty - helpers.assert_alive() + t.assert_alive() end) it([[can use temporary normal mode <c-\><c-o>]], function() @@ -473,7 +473,7 @@ end) describe('terminal input', function() it('sends various special keys with modifiers', function() clear() - local screen = thelpers.setup_child_nvim({ + local screen = tt.setup_child_nvim({ '-u', 'NONE', '-i', @@ -560,7 +560,7 @@ if is_os('win') then feed_command('set modifiable swapfile undolevels=20') poke_eventloop() local cmd = { 'cmd.exe', '/K', 'PROMPT=$g$s' } - screen = thelpers.screen_setup(nil, cmd) + screen = tt.screen_setup(nil, cmd) end) it('"put" operator sends data normally', function() diff --git a/test/functional/terminal/channel_spec.lua b/test/functional/terminal/channel_spec.lua @@ -1,17 +1,17 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local eq = helpers.eq -local eval = helpers.eval -local command = helpers.command -local pcall_err = helpers.pcall_err -local feed = helpers.feed -local poke_eventloop = helpers.poke_eventloop -local is_os = helpers.is_os -local api = helpers.api -local async_meths = helpers.async_meths -local testprg = helpers.testprg -local assert_alive = helpers.assert_alive +local clear = t.clear +local eq = t.eq +local eval = t.eval +local command = t.command +local pcall_err = t.pcall_err +local feed = t.feed +local poke_eventloop = t.poke_eventloop +local is_os = t.is_os +local api = t.api +local async_meths = t.async_meths +local testprg = t.testprg +local assert_alive = t.assert_alive describe('terminal channel is closed and later released if', function() local screen diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua @@ -1,26 +1,26 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local thelpers = require('test.functional.terminal.helpers') -local feed, clear = helpers.feed, helpers.clear -local testprg, command = helpers.testprg, helpers.command -local eq, eval = helpers.eq, helpers.eval -local matches = helpers.matches -local poke_eventloop = helpers.poke_eventloop -local hide_cursor = thelpers.hide_cursor -local show_cursor = thelpers.show_cursor -local is_os = helpers.is_os -local skip = helpers.skip +local tt = require('test.functional.terminal.testutil') +local feed, clear = t.feed, t.clear +local testprg, command = t.testprg, t.command +local eq, eval = t.eq, t.eval +local matches = t.matches +local poke_eventloop = t.poke_eventloop +local hide_cursor = tt.hide_cursor +local show_cursor = tt.show_cursor +local is_os = t.is_os +local skip = t.skip describe(':terminal cursor', function() local screen before_each(function() clear() - screen = thelpers.screen_setup() + screen = tt.screen_setup() end) it('moves the screen cursor when focused', function() - thelpers.feed_data('testing cursor') + tt.feed_data('testing cursor') screen:expect([[ tty ready | testing cursor{1: } | @@ -66,7 +66,7 @@ describe(':terminal cursor', function() :set number | ]]) feed('i') - helpers.poke_eventloop() + t.poke_eventloop() screen:expect([[ {7: 1 }tty ready | {7: 2 }rows: 6, cols: 46 | @@ -152,7 +152,7 @@ describe('buffer cursor position is correct in terminal without number column', local screen local function setup_ex_register(str) - screen = thelpers.setup_child_nvim({ + screen = tt.setup_child_nvim({ '-u', 'NONE', '-i', @@ -469,7 +469,7 @@ describe('buffer cursor position is correct in terminal with number column', fun local screen local function setup_ex_register(str) - screen = thelpers.setup_child_nvim({ + screen = tt.setup_child_nvim({ '-u', 'NONE', '-i', diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local screen = require('test.functional.ui.screen') -local testprg = helpers.testprg -local command = helpers.command -local fn = helpers.fn -local api = helpers.api -local clear = helpers.clear -local eq = helpers.eq -local matches = helpers.matches +local testprg = t.testprg +local command = t.command +local fn = t.fn +local api = t.api +local clear = t.clear +local eq = t.eq +local matches = t.matches local pesc = vim.pesc describe(':edit term://*', function() diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua @@ -1,18 +1,18 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local assert_alive = helpers.assert_alive -local clear, poke_eventloop = helpers.clear, helpers.poke_eventloop -local testprg, source, eq = helpers.testprg, helpers.source, helpers.eq -local feed = helpers.feed -local feed_command, eval = helpers.feed_command, helpers.eval -local fn = helpers.fn -local api = helpers.api -local retry = helpers.retry -local ok = helpers.ok -local command = helpers.command -local skip = helpers.skip -local is_os = helpers.is_os -local is_ci = helpers.is_ci +local assert_alive = t.assert_alive +local clear, poke_eventloop = t.clear, t.poke_eventloop +local testprg, source, eq = t.testprg, t.source, t.eq +local feed = t.feed +local feed_command, eval = t.feed_command, t.eval +local fn = t.fn +local api = t.api +local retry = t.retry +local ok = t.ok +local command = t.command +local skip = t.skip +local is_os = t.is_os +local is_ci = t.is_ci describe(':terminal', function() local screen diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua @@ -1,191 +0,0 @@ --- To test tui/input.c, this module spawns `nvim` inside :terminal and sends --- bytes via jobsend(). Note: the functional/helpers.lua test-session methods --- operate on the _host_ session, _not_ the child session. -local helpers = require('test.functional.helpers')(nil) -local Screen = require('test.functional.ui.screen') -local testprg = helpers.testprg -local exec_lua = helpers.exec_lua -local api = helpers.api -local nvim_prog = helpers.nvim_prog - -local function feed_data(data) - if type(data) == 'table' then - data = table.concat(data, '\n') - end - exec_lua('vim.api.nvim_chan_send(vim.b.terminal_job_id, ...)', data) -end - -local function feed_termcode(data) - feed_data('\027' .. data) -end - -local function make_lua_executor(session) - return function(code, ...) - local status, rv = session:request('nvim_exec_lua', code, { ... }) - if not status then - session:stop() - error(rv[2]) - end - return rv - end -end - --- some helpers for controlling the terminal. the codes were taken from --- infocmp xterm-256color which is less what libvterm understands --- civis/cnorm -local function hide_cursor() - feed_termcode('[?25l') -end -local function show_cursor() - feed_termcode('[?25h') -end --- smcup/rmcup -local function enter_altscreen() - feed_termcode('[?1049h') -end -local function exit_altscreen() - feed_termcode('[?1049l') -end --- character attributes -local function set_fg(num) - feed_termcode('[38;5;' .. num .. 'm') -end -local function set_bg(num) - feed_termcode('[48;5;' .. num .. 'm') -end -local function set_bold() - feed_termcode('[1m') -end -local function set_italic() - feed_termcode('[3m') -end -local function set_underline() - feed_termcode('[4m') -end -local function set_underdouble() - feed_termcode('[4:2m') -end -local function set_undercurl() - feed_termcode('[4:3m') -end -local function set_strikethrough() - feed_termcode('[9m') -end -local function clear_attrs() - feed_termcode('[0;10m') -end --- mouse -local function enable_mouse() - feed_termcode('[?1002h') -end -local function disable_mouse() - feed_termcode('[?1002l') -end - -local default_command = { testprg('tty-test') } - -local function screen_setup(extra_rows, command, cols, env, screen_opts) - extra_rows = extra_rows and extra_rows or 0 - command = command and command or default_command - cols = cols and cols or 50 - - api.nvim_command('highlight TermCursor cterm=reverse') - api.nvim_command('highlight TermCursorNC ctermbg=11') - - local screen = Screen.new(cols, 7 + extra_rows) - screen:set_default_attr_ids({ - [1] = { reverse = true }, -- focused cursor - [2] = { background = 11 }, -- unfocused cursor - [3] = { bold = true }, - [4] = { foreground = 12 }, -- NonText in :terminal session - [5] = { bold = true, reverse = true }, - [6] = { foreground = 81 }, -- SpecialKey in :terminal session - [7] = { foreground = 130 }, -- LineNr in host session - [8] = { foreground = 15, background = 1 }, -- ErrorMsg in :terminal session - [9] = { foreground = 4 }, - [10] = { foreground = 121 }, -- MoreMsg in :terminal session - [11] = { foreground = 11 }, -- LineNr in :terminal session - [12] = { underline = true }, - [13] = { underline = true, reverse = true }, - [14] = { underline = true, reverse = true, bold = true }, - [15] = { underline = true, foreground = 12 }, - [16] = { background = 248, foreground = 0 }, -- Visual in :terminal session - }) - - screen:attach(screen_opts or { rgb = false }) - - api.nvim_command('enew') - api.nvim_call_function('termopen', { command, env and { env = env } or nil }) - api.nvim_input('<CR>') - local vim_errmsg = api.nvim_eval('v:errmsg') - if vim_errmsg and '' ~= vim_errmsg then - error(vim_errmsg) - end - - api.nvim_command('setlocal scrollback=10') - api.nvim_command('startinsert') - api.nvim_input('<Ignore>') -- Add input to separate two RPC requests - - -- tty-test puts the terminal into raw mode and echoes input. Tests work by - -- feeding termcodes to control the display and asserting by screen:expect. - if command == default_command and screen_opts == nil then - -- Wait for "tty ready" to be printed before each test or the terminal may - -- still be in canonical mode (will echo characters for example). - local empty_line = (' '):rep(cols) - local expected = { - 'tty ready' .. (' '):rep(cols - 9), - '{1: }' .. (' '):rep(cols - 1), - empty_line, - empty_line, - empty_line, - empty_line, - } - for _ = 1, extra_rows do - table.insert(expected, empty_line) - end - - table.insert(expected, '{3:-- TERMINAL --}' .. ((' '):rep(cols - 14))) - screen:expect(table.concat(expected, '|\n') .. '|') - else - -- This eval also acts as a poke_eventloop(). - if 0 == api.nvim_eval("exists('b:terminal_job_id')") then - error('terminal job failed to start') - end - end - return screen -end - -local function setup_child_nvim(args, opts) - opts = opts or {} - local argv = { nvim_prog, unpack(args) } - - local env = opts.env or {} - if not env.VIMRUNTIME then - env.VIMRUNTIME = os.getenv('VIMRUNTIME') - end - - return screen_setup(0, argv, opts.cols, env) -end - -return { - feed_data = feed_data, - feed_termcode = feed_termcode, - make_lua_executor = make_lua_executor, - hide_cursor = hide_cursor, - show_cursor = show_cursor, - enter_altscreen = enter_altscreen, - exit_altscreen = exit_altscreen, - set_fg = set_fg, - set_bg = set_bg, - set_bold = set_bold, - set_italic = set_italic, - set_underline = set_underline, - set_underdouble = set_underdouble, - set_undercurl = set_undercurl, - set_strikethrough = set_strikethrough, - clear_attrs = clear_attrs, - enable_mouse = enable_mouse, - disable_mouse = disable_mouse, - screen_setup = screen_setup, - setup_child_nvim = setup_child_nvim, -} diff --git a/test/functional/terminal/highlight_spec.lua b/test/functional/terminal/highlight_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local thelpers = require('test.functional.terminal.helpers') -local feed, clear = helpers.feed, helpers.clear -local api = helpers.api -local testprg, command = helpers.testprg, helpers.command -local nvim_prog_abs = helpers.nvim_prog_abs -local fn = helpers.fn -local nvim_set = helpers.nvim_set -local is_os = helpers.is_os -local skip = helpers.skip +local tt = require('test.functional.terminal.testutil') +local feed, clear = t.feed, t.clear +local api = t.api +local testprg, command = t.testprg, t.command +local nvim_prog_abs = t.nvim_prog_abs +local fn = t.fn +local nvim_set = t.nvim_set +local is_os = t.is_os +local skip = t.skip describe(':terminal highlight', function() local screen @@ -51,9 +51,9 @@ describe(':terminal highlight', function() describe(title, function() before_each(function() set_attrs_fn() - thelpers.feed_data('text') - thelpers.clear_attrs() - thelpers.feed_data('text') + tt.feed_data('text') + tt.clear_attrs() + tt.feed_data('text') end) local function pass_attrs() @@ -76,7 +76,7 @@ describe(':terminal highlight', function() table.insert(lines, 'line' .. tostring(i)) end table.insert(lines, '') - thelpers.feed_data(lines) + tt.feed_data(lines) screen:expect([[ line4 | line5 | @@ -101,28 +101,28 @@ describe(':terminal highlight', function() end descr('foreground', 1, function() - thelpers.set_fg(45) + tt.set_fg(45) end) descr('background', 2, function() - thelpers.set_bg(46) + tt.set_bg(46) end) descr('foreground and background', 3, function() - thelpers.set_fg(45) - thelpers.set_bg(46) + tt.set_fg(45) + tt.set_bg(46) end) descr('bold, italics, underline and strikethrough', 4, function() - thelpers.set_bold() - thelpers.set_italic() - thelpers.set_underline() - thelpers.set_strikethrough() + tt.set_bold() + tt.set_italic() + tt.set_underline() + tt.set_strikethrough() end) descr('bold and underdouble', 12, function() - thelpers.set_bold() - thelpers.set_underdouble() + tt.set_bold() + tt.set_underdouble() end) descr('italics and undercurl', 13, function() - thelpers.set_italic() - thelpers.set_undercurl() + tt.set_italic() + tt.set_undercurl() end) end) @@ -206,7 +206,7 @@ it('CursorLine and CursorColumn work in :terminal buffer in Normal mode', functi ^tty ready | |*6 ]]) - thelpers.feed_data((' foobar'):rep(30)) + tt.feed_data((' foobar'):rep(30)) screen:expect([[ ^tty ready | foobar foobar foobar foobar foobar foobar foobar | @@ -319,12 +319,12 @@ describe(':terminal highlight forwarding', function() it('will handle cterm and rgb attributes', function() skip(is_os('win')) - thelpers.set_fg(3) - thelpers.feed_data('text') - thelpers.feed_termcode('[38:2:255:128:0m') - thelpers.feed_data('color') - thelpers.clear_attrs() - thelpers.feed_data('text') + tt.set_fg(3) + tt.feed_data('text') + tt.feed_termcode('[38:2:255:128:0m') + tt.feed_data('color') + tt.clear_attrs() + tt.feed_data('text') screen:expect { grid = [[ tty ready | @@ -366,10 +366,10 @@ describe(':terminal highlight with custom palette', function() it('will use the custom color', function() skip(is_os('win')) - thelpers.set_fg(3) - thelpers.feed_data('text') - thelpers.clear_attrs() - thelpers.feed_data('text') + tt.set_fg(3) + tt.feed_data('text') + tt.clear_attrs() + tt.feed_data('text') screen:expect([[ tty ready | {1:text}text{7: } | diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) -local thelpers = require('test.functional.terminal.helpers') -local clear, eq, eval = helpers.clear, helpers.eq, helpers.eval -local feed, api, command = helpers.feed, helpers.api, helpers.command -local feed_data = thelpers.feed_data -local is_os = helpers.is_os -local skip = helpers.skip +local t = require('test.functional.testutil')(after_each) +local tt = require('test.functional.terminal.testutil') +local clear, eq, eval = t.clear, t.eq, t.eval +local feed, api, command = t.feed, t.api, t.command +local feed_data = tt.feed_data +local is_os = t.is_os +local skip = t.skip describe(':terminal mouse', function() local screen @@ -15,7 +15,7 @@ describe(':terminal mouse', function() command('highlight StatusLine cterm=NONE') command('highlight StatusLineNC cterm=NONE') command('highlight VertSplit cterm=NONE') - screen = thelpers.screen_setup() + screen = tt.screen_setup() local lines = {} for i = 1, 30 do table.insert(lines, 'line' .. tostring(i)) @@ -95,8 +95,8 @@ describe(':terminal mouse', function() describe('with mouse events enabled by the program', function() before_each(function() - thelpers.enable_mouse() - thelpers.feed_data('mouse enabled\n') + tt.enable_mouse() + tt.feed_data('mouse enabled\n') screen:expect([[ line27 | line28 | @@ -423,8 +423,8 @@ describe(':terminal mouse', function() ]]) -- enabling mouse won't affect interaction with other windows - thelpers.enable_mouse() - thelpers.feed_data('mouse enabled\n') + tt.enable_mouse() + tt.feed_data('mouse enabled\n') screen:expect([[ {7: 27 }line │line30 | {7: 28 }line │rows: 5, cols: 25 | diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua @@ -1,26 +1,26 @@ local Screen = require('test.functional.ui.screen') -local helpers = require('test.functional.helpers')(after_each) -local thelpers = require('test.functional.terminal.helpers') -local clear, eq = helpers.clear, helpers.eq -local feed, testprg = helpers.feed, helpers.testprg -local eval = helpers.eval -local command = helpers.command -local poke_eventloop = helpers.poke_eventloop -local retry = helpers.retry -local api = helpers.api -local feed_data = thelpers.feed_data -local pcall_err = helpers.pcall_err -local exec_lua = helpers.exec_lua -local assert_alive = helpers.assert_alive -local skip = helpers.skip -local is_os = helpers.is_os +local t = require('test.functional.testutil')(after_each) +local tt = require('test.functional.terminal.testutil') +local clear, eq = t.clear, t.eq +local feed, testprg = t.feed, t.testprg +local eval = t.eval +local command = t.command +local poke_eventloop = t.poke_eventloop +local retry = t.retry +local api = t.api +local feed_data = tt.feed_data +local pcall_err = t.pcall_err +local exec_lua = t.exec_lua +local assert_alive = t.assert_alive +local skip = t.skip +local is_os = t.is_os describe(':terminal scrollback', function() local screen before_each(function() clear() - screen = thelpers.screen_setup(nil, nil, 30) + screen = tt.screen_setup(nil, nil, 30) end) describe('when the limit is exceeded', function() @@ -397,9 +397,9 @@ describe("'scrollback' option", function() it('set to 0 behaves as 1', function() local screen if is_os('win') then - screen = thelpers.screen_setup(nil, { 'cmd.exe' }, 30) + screen = tt.screen_setup(nil, { 'cmd.exe' }, 30) else - screen = thelpers.screen_setup(nil, { 'sh' }, 30) + screen = tt.screen_setup(nil, { 'sh' }, 30) end api.nvim_set_option_value('scrollback', 0, {}) @@ -414,10 +414,10 @@ describe("'scrollback' option", function() local screen if is_os('win') then command([[let $PROMPT='$$']]) - screen = thelpers.screen_setup(nil, { 'cmd.exe' }, 30) + screen = tt.screen_setup(nil, { 'cmd.exe' }, 30) else command('let $PS1 = "$"') - screen = thelpers.screen_setup(nil, { 'sh' }, 30) + screen = tt.screen_setup(nil, { 'sh' }, 30) end api.nvim_set_option_value('scrollback', 200, {}) @@ -479,7 +479,7 @@ describe("'scrollback' option", function() it('deletes extra lines immediately', function() -- Scrollback is 10 on screen_setup - local screen = thelpers.screen_setup(nil, nil, 30) + local screen = tt.screen_setup(nil, nil, 30) local lines = {} for i = 1, 30 do table.insert(lines, 'line' .. tostring(i)) diff --git a/test/functional/terminal/testutil.lua b/test/functional/terminal/testutil.lua @@ -0,0 +1,191 @@ +-- To test tui/input.c, this module spawns `nvim` inside :terminal and sends +-- bytes via jobsend(). Note: the functional/t.lua test-session methods +-- operate on the _host_ session, _not_ the child session. +local t = require('test.functional.testutil')(nil) +local Screen = require('test.functional.ui.screen') +local testprg = t.testprg +local exec_lua = t.exec_lua +local api = t.api +local nvim_prog = t.nvim_prog + +local function feed_data(data) + if type(data) == 'table' then + data = table.concat(data, '\n') + end + exec_lua('vim.api.nvim_chan_send(vim.b.terminal_job_id, ...)', data) +end + +local function feed_termcode(data) + feed_data('\027' .. data) +end + +local function make_lua_executor(session) + return function(code, ...) + local status, rv = session:request('nvim_exec_lua', code, { ... }) + if not status then + session:stop() + error(rv[2]) + end + return rv + end +end + +-- some t for controlling the terminal. the codes were taken from +-- infocmp xterm-256color which is less what libvterm understands +-- civis/cnorm +local function hide_cursor() + feed_termcode('[?25l') +end +local function show_cursor() + feed_termcode('[?25h') +end +-- smcup/rmcup +local function enter_altscreen() + feed_termcode('[?1049h') +end +local function exit_altscreen() + feed_termcode('[?1049l') +end +-- character attributes +local function set_fg(num) + feed_termcode('[38;5;' .. num .. 'm') +end +local function set_bg(num) + feed_termcode('[48;5;' .. num .. 'm') +end +local function set_bold() + feed_termcode('[1m') +end +local function set_italic() + feed_termcode('[3m') +end +local function set_underline() + feed_termcode('[4m') +end +local function set_underdouble() + feed_termcode('[4:2m') +end +local function set_undercurl() + feed_termcode('[4:3m') +end +local function set_strikethrough() + feed_termcode('[9m') +end +local function clear_attrs() + feed_termcode('[0;10m') +end +-- mouse +local function enable_mouse() + feed_termcode('[?1002h') +end +local function disable_mouse() + feed_termcode('[?1002l') +end + +local default_command = { testprg('tty-test') } + +local function screen_setup(extra_rows, command, cols, env, screen_opts) + extra_rows = extra_rows and extra_rows or 0 + command = command and command or default_command + cols = cols and cols or 50 + + api.nvim_command('highlight TermCursor cterm=reverse') + api.nvim_command('highlight TermCursorNC ctermbg=11') + + local screen = Screen.new(cols, 7 + extra_rows) + screen:set_default_attr_ids({ + [1] = { reverse = true }, -- focused cursor + [2] = { background = 11 }, -- unfocused cursor + [3] = { bold = true }, + [4] = { foreground = 12 }, -- NonText in :terminal session + [5] = { bold = true, reverse = true }, + [6] = { foreground = 81 }, -- SpecialKey in :terminal session + [7] = { foreground = 130 }, -- LineNr in host session + [8] = { foreground = 15, background = 1 }, -- ErrorMsg in :terminal session + [9] = { foreground = 4 }, + [10] = { foreground = 121 }, -- MoreMsg in :terminal session + [11] = { foreground = 11 }, -- LineNr in :terminal session + [12] = { underline = true }, + [13] = { underline = true, reverse = true }, + [14] = { underline = true, reverse = true, bold = true }, + [15] = { underline = true, foreground = 12 }, + [16] = { background = 248, foreground = 0 }, -- Visual in :terminal session + }) + + screen:attach(screen_opts or { rgb = false }) + + api.nvim_command('enew') + api.nvim_call_function('termopen', { command, env and { env = env } or nil }) + api.nvim_input('<CR>') + local vim_errmsg = api.nvim_eval('v:errmsg') + if vim_errmsg and '' ~= vim_errmsg then + error(vim_errmsg) + end + + api.nvim_command('setlocal scrollback=10') + api.nvim_command('startinsert') + api.nvim_input('<Ignore>') -- Add input to separate two RPC requests + + -- tty-test puts the terminal into raw mode and echoes input. Tests work by + -- feeding termcodes to control the display and asserting by screen:expect. + if command == default_command and screen_opts == nil then + -- Wait for "tty ready" to be printed before each test or the terminal may + -- still be in canonical mode (will echo characters for example). + local empty_line = (' '):rep(cols) + local expected = { + 'tty ready' .. (' '):rep(cols - 9), + '{1: }' .. (' '):rep(cols - 1), + empty_line, + empty_line, + empty_line, + empty_line, + } + for _ = 1, extra_rows do + table.insert(expected, empty_line) + end + + table.insert(expected, '{3:-- TERMINAL --}' .. ((' '):rep(cols - 14))) + screen:expect(table.concat(expected, '|\n') .. '|') + else + -- This eval also acts as a poke_eventloop(). + if 0 == api.nvim_eval("exists('b:terminal_job_id')") then + error('terminal job failed to start') + end + end + return screen +end + +local function setup_child_nvim(args, opts) + opts = opts or {} + local argv = { nvim_prog, unpack(args) } + + local env = opts.env or {} + if not env.VIMRUNTIME then + env.VIMRUNTIME = os.getenv('VIMRUNTIME') + end + + return screen_setup(0, argv, opts.cols, env) +end + +return { + feed_data = feed_data, + feed_termcode = feed_termcode, + make_lua_executor = make_lua_executor, + hide_cursor = hide_cursor, + show_cursor = show_cursor, + enter_altscreen = enter_altscreen, + exit_altscreen = exit_altscreen, + set_fg = set_fg, + set_bg = set_bg, + set_bold = set_bold, + set_italic = set_italic, + set_underline = set_underline, + set_underdouble = set_underdouble, + set_undercurl = set_undercurl, + set_strikethrough = set_strikethrough, + clear_attrs = clear_attrs, + enable_mouse = enable_mouse, + disable_mouse = disable_mouse, + screen_setup = screen_setup, + setup_child_nvim = setup_child_nvim, +} diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua @@ -4,36 +4,36 @@ -- "bracketed paste" terminal feature: -- http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Bracketed-Paste-Mode -local helpers = require('test.functional.helpers')(after_each) -local thelpers = require('test.functional.terminal.helpers') +local t = require('test.functional.testutil')(after_each) +local tt = require('test.functional.terminal.testutil') local Screen = require('test.functional.ui.screen') -local eq = helpers.eq -local feed_data = thelpers.feed_data -local clear = helpers.clear -local command = helpers.command -local dedent = helpers.dedent -local exec = helpers.exec -local exec_lua = helpers.exec_lua -local testprg = helpers.testprg -local retry = helpers.retry -local nvim_prog = helpers.nvim_prog -local nvim_set = helpers.nvim_set -local ok = helpers.ok -local read_file = helpers.read_file -local fn = helpers.fn -local api = helpers.api -local is_ci = helpers.is_ci -local is_os = helpers.is_os -local new_pipename = helpers.new_pipename -local spawn_argv = helpers.spawn_argv -local set_session = helpers.set_session -local write_file = helpers.write_file -local eval = helpers.eval -local assert_log = helpers.assert_log +local eq = t.eq +local feed_data = tt.feed_data +local clear = t.clear +local command = t.command +local dedent = t.dedent +local exec = t.exec +local exec_lua = t.exec_lua +local testprg = t.testprg +local retry = t.retry +local nvim_prog = t.nvim_prog +local nvim_set = t.nvim_set +local ok = t.ok +local read_file = t.read_file +local fn = t.fn +local api = t.api +local is_ci = t.is_ci +local is_os = t.is_os +local new_pipename = t.new_pipename +local spawn_argv = t.spawn_argv +local set_session = t.set_session +local write_file = t.write_file +local eval = t.eval +local assert_log = t.assert_log local testlog = 'Xtest-tui-log' -if helpers.skip(is_os('win')) then +if t.skip(is_os('win')) then return end @@ -45,7 +45,7 @@ describe('TUI', function() before_each(function() clear() local child_server = new_pipename() - screen = thelpers.setup_child_nvim({ + screen = tt.setup_child_nvim({ '--listen', child_server, '-u', @@ -64,8 +64,8 @@ describe('TUI', function() | {3:-- TERMINAL --} | ]]) - child_session = helpers.connect(child_server) - child_exec_lua = thelpers.make_lua_executor(child_session) + child_session = t.connect(child_server) + child_exec_lua = tt.make_lua_executor(child_session) end) -- Wait for mode in the child Nvim (avoid "typeahead race" #10826). @@ -1347,15 +1347,15 @@ describe('TUI', function() it('paste: big burst of input', function() feed_data(':set ruler\n') - local t = {} + local q = {} for i = 1, 3000 do - t[i] = 'item ' .. tostring(i) + q[i] = 'item ' .. tostring(i) end feed_data('i') wait_for_mode('i') -- "bracketed paste" - feed_data('\027[200~' .. table.concat(t, '\n') .. '\027[201~') - expect_child_buf_lines(t) + feed_data('\027[200~' .. table.concat(q, '\n') .. '\027[201~') + expect_child_buf_lines(q) feed_data(' end') screen:expect([[ item 2997 | @@ -1695,7 +1695,7 @@ describe('TUI', function() end) it('draws correctly when cursor_address overflows #21643', function() - helpers.skip(is_os('mac'), 'FIXME: crashes/errors on macOS') + t.skip(is_os('mac'), 'FIXME: crashes/errors on macOS') screen:try_resize(77, 855) retry(nil, nil, function() eq({ true, 852 }, { child_session:request('nvim_win_get_height', 0) }) @@ -1973,7 +1973,7 @@ describe('TUI', function() finally(function() os.remove(script_file) end) - local screen = thelpers.setup_child_nvim({ '--clean', '-l', script_file }) + local screen = tt.setup_child_nvim({ '--clean', '-l', script_file }) screen:expect { grid = [[ {1: } | @@ -2001,7 +2001,7 @@ describe('TUI', function() finally(function() os.remove('testF') end) - local screen = thelpers.screen_setup( + local screen = tt.screen_setup( 0, ('"%s" -u NONE -i NONE --cmd "set noswapfile noshowcmd noruler" --cmd "normal iabc" > /dev/null 2>&1 && cat testF && rm testF'):format( nvim_prog @@ -2022,7 +2022,7 @@ describe('TUI', function() end) it('<C-h> #10134', function() - local screen = thelpers.setup_child_nvim({ + local screen = tt.setup_child_nvim({ '-u', 'NONE', '-i', @@ -2055,7 +2055,7 @@ describe('TUI', function() end) it('draws line with many trailing spaces correctly #24955', function() - local screen = thelpers.setup_child_nvim({ + local screen = tt.setup_child_nvim({ '-u', 'NONE', '-i', @@ -2094,7 +2094,7 @@ describe('TUI', function() it('no heap-buffer-overflow when changing &columns', function() -- Set a different bg colour and change $TERM to something dumber so the `print_spaces()` -- codepath in `clear_region()` is hit. - local screen = thelpers.setup_child_nvim({ + local screen = tt.setup_child_nvim({ '-u', 'NONE', '-i', @@ -2137,7 +2137,7 @@ end) describe('TUI UIEnter/UILeave', function() it('fires exactly once, after VimEnter', function() clear() - local screen = thelpers.setup_child_nvim({ + local screen = tt.setup_child_nvim({ '-u', 'NONE', '-i', @@ -2184,7 +2184,7 @@ describe('TUI FocusGained/FocusLost', function() before_each(function() clear() local child_server = new_pipename() - screen = thelpers.setup_child_nvim({ + screen = tt.setup_child_nvim({ '--listen', child_server, '-u', @@ -2204,7 +2204,7 @@ describe('TUI FocusGained/FocusLost', function() | {3:-- TERMINAL --} | ]]) - child_session = helpers.connect(child_server) + child_session = t.connect(child_server) child_session:request( 'nvim_exec2', [[ @@ -2396,14 +2396,14 @@ describe('TUI FocusGained/FocusLost', function() end) end) --- These tests require `thelpers` because --headless/--embed +-- These tests require `tt` because --headless/--embed -- does not initialize the TUI. describe("TUI 't_Co' (terminal colors)", function() local screen local function assert_term_colors(term, colorterm, maxcolors) clear({ env = { TERM = term }, args = {} }) - screen = thelpers.setup_child_nvim({ + screen = tt.setup_child_nvim({ '-u', 'NONE', '-i', @@ -2679,14 +2679,14 @@ describe("TUI 't_Co' (terminal colors)", function() end) end) --- These tests require `thelpers` because --headless/--embed +-- These tests require `tt` because --headless/--embed -- does not initialize the TUI. describe("TUI 'term' option", function() local screen local function assert_term(term_envvar, term_expected) clear() - screen = thelpers.setup_child_nvim({ + screen = tt.setup_child_nvim({ '-u', 'NONE', '-i', @@ -2734,7 +2734,7 @@ describe("TUI 'term' option", function() end) end) --- These tests require `thelpers` because --headless/--embed +-- These tests require `tt` because --headless/--embed -- does not initialize the TUI. describe('TUI', function() local screen @@ -2746,7 +2746,7 @@ describe('TUI', function() -- Runs (child) `nvim` in a TTY (:terminal), to start the builtin TUI. local function nvim_tui(extra_args) clear() - screen = thelpers.setup_child_nvim({ + screen = tt.setup_child_nvim({ '-u', 'NONE', '-i', @@ -2827,7 +2827,7 @@ describe('TUI', function() ]]) local child_server = new_pipename() - screen = thelpers.setup_child_nvim({ + screen = tt.setup_child_nvim({ '--listen', child_server, '-u', @@ -2847,7 +2847,7 @@ describe('TUI', function() screen:expect({ any = '%[No Name%]' }) - local child_session = helpers.connect(child_server) + local child_session = t.connect(child_server) retry(nil, 1000, function() eq({ Tc = true, @@ -2877,7 +2877,7 @@ describe('TUI', function() ]]) local child_server = new_pipename() - screen = thelpers.setup_child_nvim({ + screen = tt.setup_child_nvim({ '--listen', child_server, -- Use --clean instead of -u NONE to load the osc52 plugin @@ -2893,7 +2893,7 @@ describe('TUI', function() screen:expect({ any = '%[No Name%]' }) - local child_session = helpers.connect(child_server) + local child_session = t.connect(child_server) retry(nil, 1000, function() eq('Ms', eval("get(g:, 'xtgettcap', '')")) eq({ true, 'OSC 52' }, { child_session:request('nvim_eval', 'g:clipboard.name') }) @@ -2908,7 +2908,7 @@ describe('TUI bg color', function() command('highlight clear Normal') command('set background=dark') -- set outer Nvim background local child_server = new_pipename() - local screen = thelpers.setup_child_nvim({ + local screen = tt.setup_child_nvim({ '--listen', child_server, '-u', @@ -2921,7 +2921,7 @@ describe('TUI bg color', function() 'set noswapfile', }) screen:expect({ any = '%[No Name%]' }) - local child_session = helpers.connect(child_server) + local child_session = t.connect(child_server) retry(nil, nil, function() eq({ true, 'dark' }, { child_session:request('nvim_eval', '&background') }) end) @@ -2931,7 +2931,7 @@ describe('TUI bg color', function() command('highlight clear Normal') command('set background=light') -- set outer Nvim background local child_server = new_pipename() - local screen = thelpers.setup_child_nvim({ + local screen = tt.setup_child_nvim({ '--listen', child_server, '-u', @@ -2944,7 +2944,7 @@ describe('TUI bg color', function() 'set noswapfile', }) screen:expect({ any = '%[No Name%]' }) - local child_session = helpers.connect(child_server) + local child_session = t.connect(child_server) retry(nil, nil, function() eq({ true, 'light' }, { child_session:request('nvim_eval', '&background') }) end) @@ -2962,7 +2962,7 @@ describe('TUI bg color', function() end, }) ]]) - thelpers.setup_child_nvim({ + tt.setup_child_nvim({ '-u', 'NONE', '-i', @@ -2978,7 +2978,7 @@ describe('TUI bg color', function() end) it('triggers OptionSet from automatic background processing', function() - local screen = thelpers.setup_child_nvim({ + local screen = tt.setup_child_nvim({ '-u', 'NONE', '-i', @@ -3000,7 +3000,7 @@ describe('TUI bg color', function() end) end) --- These tests require `thelpers` because --headless/--embed +-- These tests require `tt` because --headless/--embed -- does not initialize the TUI. describe('TUI as a client', function() after_each(function() @@ -3013,7 +3013,7 @@ describe('TUI as a client', function() set_session(server_super) local server_pipe = new_pipename() - local screen_server = thelpers.setup_child_nvim({ + local screen_server = tt.setup_child_nvim({ '--listen', server_pipe, '-u', @@ -3048,7 +3048,7 @@ describe('TUI as a client', function() } set_session(client_super) - local screen_client = thelpers.setup_child_nvim({ + local screen_client = tt.setup_child_nvim({ '--server', server_pipe, '--remote-ui', @@ -3092,7 +3092,7 @@ describe('TUI as a client', function() server:request('nvim_command', 'set notermguicolors') set_session(client_super) - local screen_client = thelpers.setup_child_nvim({ + local screen_client = tt.setup_child_nvim({ '--server', server_pipe, '--remote-ui', @@ -3134,7 +3134,7 @@ describe('TUI as a client', function() it('throws error when no server exists', function() clear() - local screen = thelpers.setup_child_nvim({ + local screen = tt.setup_child_nvim({ '--server', '127.0.0.1:2436546', '--remote-ui', @@ -3155,7 +3155,7 @@ describe('TUI as a client', function() set_session(server_super) local server_pipe = new_pipename() - local screen_server = thelpers.setup_child_nvim({ + local screen_server = tt.setup_child_nvim({ '--listen', server_pipe, '-u', @@ -3199,7 +3199,7 @@ describe('TUI as a client', function() } set_session(client_super) - local screen_client = thelpers.setup_child_nvim({ + local screen_client = tt.setup_child_nvim({ '--server', server_pipe, '--remote-ui', diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua @@ -1,21 +1,21 @@ -local helpers = require('test.functional.helpers')(after_each) -local thelpers = require('test.functional.terminal.helpers') -local feed_data = thelpers.feed_data -local feed, clear = helpers.feed, helpers.clear -local poke_eventloop = helpers.poke_eventloop -local command = helpers.command -local retry = helpers.retry -local eq = helpers.eq -local eval = helpers.eval -local skip = helpers.skip -local is_os = helpers.is_os +local t = require('test.functional.testutil')(after_each) +local tt = require('test.functional.terminal.testutil') +local feed_data = tt.feed_data +local feed, clear = t.feed, t.clear +local poke_eventloop = t.poke_eventloop +local command = t.command +local retry = t.retry +local eq = t.eq +local eval = t.eval +local skip = t.skip +local is_os = t.is_os describe(':terminal window', function() local screen before_each(function() clear() - screen = thelpers.screen_setup() + screen = tt.screen_setup() end) it('sets topline correctly #8556', function() @@ -176,7 +176,7 @@ describe(':terminal with multigrid', function() before_each(function() clear() - screen = thelpers.screen_setup(0, nil, 50, nil, { ext_multigrid = true }) + screen = tt.screen_setup(0, nil, 50, nil, { ext_multigrid = true }) end) it('resizes to requested size', function() diff --git a/test/functional/terminal/window_split_tab_spec.lua b/test/functional/terminal/window_split_tab_spec.lua @@ -1,16 +1,16 @@ -local helpers = require('test.functional.helpers')(after_each) -local thelpers = require('test.functional.terminal.helpers') -local assert_alive = helpers.assert_alive -local clear = helpers.clear -local feed = helpers.feed -local feed_command = helpers.feed_command -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval -local api = helpers.api +local t = require('test.functional.testutil')(after_each) +local tt = require('test.functional.terminal.testutil') +local assert_alive = t.assert_alive +local clear = t.clear +local feed = t.feed +local feed_command = t.feed_command +local command = t.command +local eq = t.eq +local eval = t.eval +local api = t.api local sleep = vim.uv.sleep -local retry = helpers.retry -local is_os = helpers.is_os +local retry = t.retry +local is_os = t.is_os describe(':terminal', function() local screen @@ -23,7 +23,7 @@ describe(':terminal', function() command('highlight StatusLine cterm=NONE') command('highlight StatusLineNC cterm=NONE') command('highlight VertSplit cterm=NONE') - screen = thelpers.screen_setup(3) + screen = tt.screen_setup(3) end) after_each(function() diff --git a/test/functional/testutil.lua b/test/functional/testutil.lua @@ -0,0 +1,1042 @@ +local uv = vim.uv +local t_global = require('test.testutil') + +local Session = require('test.client.session') +local uv_stream = require('test.client.uv_stream') +local SocketStream = uv_stream.SocketStream +local ChildProcessStream = uv_stream.ChildProcessStream + +local check_cores = t_global.check_cores +local check_logs = t_global.check_logs +local dedent = t_global.dedent +local eq = t_global.eq +local is_os = t_global.is_os +local ok = t_global.ok +local sleep = uv.sleep +local fail = t_global.fail + +--- @class test.functional.testutil: test.testutil +local module = vim.deepcopy(t_global) + +local runtime_set = 'set runtimepath^=./build/lib/nvim/' +module.nvim_prog = (os.getenv('NVIM_PRG') or t_global.paths.test_build_dir .. '/bin/nvim') +-- Default settings for the test session. +module.nvim_set = ( + 'set shortmess+=IS background=light termguicolors noswapfile noautoindent startofline' + .. ' laststatus=1 undodir=. directory=. viewdir=. backupdir=.' + .. ' belloff= wildoptions-=pum joinspaces noshowcmd noruler nomore redrawdebug=invalid' +) +module.nvim_argv = { + module.nvim_prog, + '-u', + 'NONE', + '-i', + 'NONE', + -- XXX: find treesitter parsers. + '--cmd', + runtime_set, + '--cmd', + module.nvim_set, + -- Remove default user commands and mappings. + '--cmd', + 'comclear | mapclear | mapclear!', + -- Make screentest work after changing to the new default color scheme + -- Source 'vim' color scheme without side effects + -- TODO: rewrite tests + '--cmd', + 'lua dofile("runtime/colors/vim.lua")', + '--cmd', + 'unlet g:colors_name', + '--embed', +} + +-- Directory containing nvim. +module.nvim_dir = module.nvim_prog:gsub('[/\\][^/\\]+$', '') +if module.nvim_dir == module.nvim_prog then + module.nvim_dir = '.' +end + +local prepend_argv --- @type string[]? + +if os.getenv('VALGRIND') then + local log_file = os.getenv('VALGRIND_LOG') or 'valgrind-%p.log' + prepend_argv = { + 'valgrind', + '-q', + '--tool=memcheck', + '--leak-check=yes', + '--track-origins=yes', + '--show-possibly-lost=no', + '--suppressions=src/.valgrind.supp', + '--log-file=' .. log_file, + } + if os.getenv('GDB') then + table.insert(prepend_argv, '--vgdb=yes') + table.insert(prepend_argv, '--vgdb-error=0') + end +elseif os.getenv('GDB') then + local gdbserver_port = os.getenv('GDBSERVER_PORT') or '7777' + prepend_argv = { 'gdbserver', 'localhost:' .. gdbserver_port } +end + +if prepend_argv then + local new_nvim_argv = {} --- @type string[] + local len = #prepend_argv + for i = 1, len do + new_nvim_argv[i] = prepend_argv[i] + end + for i = 1, #module.nvim_argv do + new_nvim_argv[i + len] = module.nvim_argv[i] + end + module.nvim_argv = new_nvim_argv + module.prepend_argv = prepend_argv +end + +local session --- @type test.Session? +local loop_running --- @type boolean? +local last_error --- @type string? +local method_error --- @type string? + +if not is_os('win') then + local sigpipe_handler = assert(uv.new_signal()) + uv.signal_start(sigpipe_handler, 'sigpipe', function() + print('warning: got SIGPIPE signal. Likely related to a crash in nvim') + end) +end + +function module.get_session() + return session +end + +function module.set_session(s) + session = s +end + +--- @param method string +--- @param ... any +--- @return any +function module.request(method, ...) + assert(session) + local status, rv = session:request(method, ...) + if not status then + if loop_running then + --- @type string + last_error = rv[2] + session:stop() + else + error(rv[2]) + end + end + return rv +end + +--- @param method string +--- @param ... any +--- @return any +function module.request_lua(method, ...) + return module.exec_lua([[return vim.api[...](select(2, ...))]], method, ...) +end + +--- @param timeout? integer +--- @return string? +function module.next_msg(timeout) + assert(session) + return session:next_message(timeout or 10000) +end + +function module.expect_twostreams(msgs1, msgs2) + local pos1, pos2 = 1, 1 + while pos1 <= #msgs1 or pos2 <= #msgs2 do + local msg = module.next_msg() + if pos1 <= #msgs1 and pcall(eq, msgs1[pos1], msg) then + pos1 = pos1 + 1 + elseif pos2 <= #msgs2 then + eq(msgs2[pos2], msg) + pos2 = pos2 + 1 + else + -- already failed, but show the right error message + eq(msgs1[pos1], msg) + end + end +end + +-- Expects a sequence of next_msg() results. If multiple sequences are +-- passed they are tried until one succeeds, in order of shortest to longest. +-- +-- Can be called with positional args (list of sequences only): +-- expect_msg_seq(seq1, seq2, ...) +-- or keyword args: +-- expect_msg_seq{ignore={...}, seqs={seq1, seq2, ...}} +-- +-- ignore: List of ignored event names. +-- seqs: List of one or more potential event sequences. +function module.expect_msg_seq(...) + if select('#', ...) < 1 then + error('need at least 1 argument') + end + local arg1 = select(1, ...) + if (arg1['seqs'] and select('#', ...) > 1) or type(arg1) ~= 'table' then + error('invalid args') + end + local ignore = arg1['ignore'] and arg1['ignore'] or {} + --- @type string[] + local seqs = arg1['seqs'] and arg1['seqs'] or { ... } + if type(ignore) ~= 'table' then + error("'ignore' arg must be a list of strings") + end + table.sort(seqs, function(a, b) -- Sort ascending, by (shallow) length. + return #a < #b + end) + + local actual_seq = {} + local nr_ignored = 0 + local final_error = '' + local function cat_err(err1, err2) + if err1 == nil then + return err2 + end + return string.format('%s\n%s\n%s', err1, string.rep('=', 78), err2) + end + local msg_timeout = module.load_adjust(10000) -- Big timeout for ASAN/valgrind. + for anum = 1, #seqs do + local expected_seq = seqs[anum] + -- Collect enough messages to compare the next expected sequence. + while #actual_seq < #expected_seq do + local msg = module.next_msg(msg_timeout) + local msg_type = msg and msg[2] or nil + if msg == nil then + error( + cat_err( + final_error, + string.format( + 'got %d messages (ignored %d), expected %d', + #actual_seq, + nr_ignored, + #expected_seq + ) + ) + ) + elseif vim.tbl_contains(ignore, msg_type) then + nr_ignored = nr_ignored + 1 + else + table.insert(actual_seq, msg) + end + end + local status, result = pcall(eq, expected_seq, actual_seq) + if status then + return result + end + local message = result + if type(result) == 'table' then + -- 'eq' returns several things + --- @type string + message = result.message + end + final_error = cat_err(final_error, message) + end + error(final_error) +end + +local function call_and_stop_on_error(lsession, ...) + local status, result = Session.safe_pcall(...) -- luacheck: ignore + if not status then + lsession:stop() + last_error = result + return '' + end + return result +end + +function module.set_method_error(err) + method_error = err +end + +--- @param lsession test.Session +--- @param request_cb function? +--- @param notification_cb function? +--- @param setup_cb function? +--- @param timeout integer +--- @return {[1]: integer, [2]: string} +function module.run_session(lsession, request_cb, notification_cb, setup_cb, timeout) + local on_request --- @type function? + local on_notification --- @type function? + local on_setup --- @type function? + + if request_cb then + function on_request(method, args) + method_error = nil + local result = call_and_stop_on_error(lsession, request_cb, method, args) + if method_error ~= nil then + return method_error, true + end + return result + end + end + + if notification_cb then + function on_notification(method, args) + call_and_stop_on_error(lsession, notification_cb, method, args) + end + end + + if setup_cb then + function on_setup() + call_and_stop_on_error(lsession, setup_cb) + end + end + + loop_running = true + lsession:run(on_request, on_notification, on_setup, timeout) + loop_running = false + if last_error then + local err = last_error + last_error = nil + error(err) + end + + return lsession.eof_err +end + +function module.run(request_cb, notification_cb, setup_cb, timeout) + assert(session) + return module.run_session(session, request_cb, notification_cb, setup_cb, timeout) +end + +function module.stop() + assert(session):stop() +end + +function module.nvim_prog_abs() + -- system(['build/bin/nvim']) does not work for whatever reason. It must + -- be executable searched in $PATH or something starting with / or ./. + if module.nvim_prog:match('[/\\]') then + return module.request('nvim_call_function', 'fnamemodify', { module.nvim_prog, ':p' }) + else + return module.nvim_prog + end +end + +-- Use for commands which expect nvim to quit. +-- The first argument can also be a timeout. +function module.expect_exit(fn_or_timeout, ...) + local eof_err_msg = 'EOF was received from Nvim. Likely the Nvim process crashed.' + if type(fn_or_timeout) == 'function' then + eq(eof_err_msg, module.pcall_err(fn_or_timeout, ...)) + else + eq( + eof_err_msg, + module.pcall_err(function(timeout, fn, ...) + fn(...) + assert(session) + while session:next_message(timeout) do + end + if session.eof_err then + error(session.eof_err[2]) + end + end, fn_or_timeout, ...) + ) + end +end + +--- Executes a Vimscript function via Lua. +--- Fails on Vimscript error, but does not update v:errmsg. +--- @param name string +--- @param ... any +--- @return any +function module.call_lua(name, ...) + return module.exec_lua([[return vim.call(...)]], name, ...) +end + +--- Sends user input to Nvim. +--- Does not fail on Vimscript error, but v:errmsg will be updated. +--- @param input string +local function nvim_feed(input) + while #input > 0 do + local written = module.request('nvim_input', input) + if written == nil then + module.assert_alive() + error('crash? (nvim_input returned nil)') + end + input = input:sub(written + 1) + end +end + +--- @param ... string +function module.feed(...) + for _, v in ipairs({ ... }) do + nvim_feed(dedent(v)) + end +end + +---@param ... string[]? +---@return string[] +function module.merge_args(...) + local i = 1 + local argv = {} --- @type string[] + for anum = 1, select('#', ...) do + --- @type string[]? + local args = select(anum, ...) + if args then + for _, arg in ipairs(args) do + argv[i] = arg + i = i + 1 + end + end + end + return argv +end + +--- Removes Nvim startup args from `args` matching items in `args_rm`. +--- +--- - Special case: "-u", "-i", "--cmd" are treated specially: their "values" are also removed. +--- - Special case: "runtimepath" will remove only { '--cmd', 'set runtimepath^=…', } +--- +--- Example: +--- args={'--headless', '-u', 'NONE'} +--- args_rm={'--cmd', '-u'} +--- Result: +--- {'--headless'} +--- +--- All matching cases are removed. +--- +--- Example: +--- args={'--cmd', 'foo', '-N', '--cmd', 'bar'} +--- args_rm={'--cmd', '-u'} +--- Result: +--- {'-N'} +--- @param args string[] +--- @param args_rm string[] +--- @return string[] +local function remove_args(args, args_rm) + local new_args = {} --- @type string[] + local skip_following = { '-u', '-i', '-c', '--cmd', '-s', '--listen' } + if not args_rm or #args_rm == 0 then + return { unpack(args) } + end + for _, v in ipairs(args_rm) do + assert(type(v) == 'string') + end + local last = '' + for _, arg in ipairs(args) do + if vim.tbl_contains(skip_following, last) then + last = '' + elseif vim.tbl_contains(args_rm, arg) then + last = arg + elseif arg == runtime_set and vim.tbl_contains(args_rm, 'runtimepath') then + table.remove(new_args) -- Remove the preceding "--cmd". + last = '' + else + table.insert(new_args, arg) + end + end + return new_args +end + +function module.check_close() + if not session then + return + end + local start_time = uv.now() + session:close() + uv.update_time() -- Update cached value of luv.now() (libuv: uv_now()). + local end_time = uv.now() + local delta = end_time - start_time + if delta > 500 then + print( + 'nvim took ' + .. delta + .. ' milliseconds to exit after last test\n' + .. 'This indicates a likely problem with the test even if it passed!\n' + ) + io.stdout:flush() + end + session = nil +end + +--- @param argv string[] +--- @param merge boolean? +--- @param env string[]? +--- @param keep boolean +--- @param io_extra uv.uv_pipe_t? used for stdin_fd, see :help ui-option +--- @return test.Session +function module.spawn(argv, merge, env, keep, io_extra) + if not keep then + module.check_close() + end + + local child_stream = + ChildProcessStream.spawn(merge and module.merge_args(prepend_argv, argv) or argv, env, io_extra) + return Session.new(child_stream) +end + +-- Creates a new Session connected by domain socket (named pipe) or TCP. +function module.connect(file_or_address) + local addr, port = string.match(file_or_address, '(.*):(%d+)') + local stream = (addr and port) and SocketStream.connect(addr, port) + or SocketStream.open(file_or_address) + return Session.new(stream) +end + +-- Starts (and returns) a new global Nvim session. +-- +-- Parameters are interpreted as startup args, OR a map with these keys: +-- args: List: Args appended to the default `nvim_argv` set. +-- args_rm: List: Args removed from the default set. All cases are +-- removed, e.g. args_rm={'--cmd'} removes all cases of "--cmd" +-- (and its value) from the default set. +-- env: Map: Defines the environment of the new session. +-- +-- Example: +-- clear('-e') +-- clear{args={'-e'}, args_rm={'-i'}, env={TERM=term}} +function module.clear(...) + module.set_session(module.spawn_argv(false, ...)) + return module.get_session() +end + +--- same params as clear, but does returns the session instead +--- of replacing the default session +--- @return test.Session +function module.spawn_argv(keep, ...) + local argv, env, io_extra = module.new_argv(...) + return module.spawn(argv, nil, env, keep, io_extra) +end + +--- @class test.new_argv.Opts +--- @field args? string[] +--- @field args_rm? string[] +--- @field env? table<string,string> +--- @field io_extra? uv.uv_pipe_t + +--- Builds an argument list for use in clear(). +--- +--- @see clear() for parameters. +--- @param ... string +--- @return string[] +--- @return string[]? +--- @return uv.uv_pipe_t? +function module.new_argv(...) + local args = { unpack(module.nvim_argv) } + table.insert(args, '--headless') + if _G._nvim_test_id then + -- Set the server name to the test-id for logging. #8519 + table.insert(args, '--listen') + table.insert(args, _G._nvim_test_id) + end + local new_args --- @type string[] + local io_extra --- @type uv.uv_pipe_t? + local env --- @type string[]? + --- @type test.new_argv.Opts|string + local opts = select(1, ...) + if type(opts) ~= 'table' then + new_args = { ... } + else + args = remove_args(args, opts.args_rm) + if opts.env then + local env_opt = {} --- @type table<string,string> + for k, v in pairs(opts.env) do + assert(type(k) == 'string') + assert(type(v) == 'string') + env_opt[k] = v + end + for _, k in ipairs({ + 'HOME', + 'ASAN_OPTIONS', + 'TSAN_OPTIONS', + 'MSAN_OPTIONS', + 'LD_LIBRARY_PATH', + 'PATH', + 'NVIM_LOG_FILE', + 'NVIM_RPLUGIN_MANIFEST', + 'GCOV_ERROR_FILE', + 'XDG_DATA_DIRS', + 'TMPDIR', + 'VIMRUNTIME', + }) do + -- Set these from the environment unless the caller defined them. + if not env_opt[k] then + env_opt[k] = os.getenv(k) + end + end + env = {} + for k, v in pairs(env_opt) do + env[#env + 1] = k .. '=' .. v + end + end + new_args = opts.args or {} + io_extra = opts.io_extra + end + for _, arg in ipairs(new_args) do + table.insert(args, arg) + end + return args, env, io_extra +end + +--- @param ... string +function module.insert(...) + nvim_feed('i') + for _, v in ipairs({ ... }) do + local escaped = v:gsub('<', '<lt>') + module.feed(escaped) + end + nvim_feed('<ESC>') +end + +--- Executes an ex-command by user input. Because nvim_input() is used, Vimscript +--- errors will not manifest as client (lua) errors. Use command() for that. +--- @param ... string +function module.feed_command(...) + for _, v in ipairs({ ... }) do + if v:sub(1, 1) ~= '/' then + -- not a search command, prefix with colon + nvim_feed(':') + end + nvim_feed(v:gsub('<', '<lt>')) + nvim_feed('<CR>') + end +end + +-- @deprecated use nvim_exec2() +function module.source(code) + module.exec(dedent(code)) +end + +function module.has_powershell() + return module.eval('executable("' .. (is_os('win') and 'powershell' or 'pwsh') .. '")') == 1 +end + +--- Sets Nvim shell to powershell. +--- +--- @param fake (boolean) If true, a fake will be used if powershell is not +--- found on the system. +--- @returns true if powershell was found on the system, else false. +function module.set_shell_powershell(fake) + local found = module.has_powershell() + if not fake then + assert(found) + end + local shell = found and (is_os('win') and 'powershell' or 'pwsh') or module.testprg('pwsh-test') + local cmd = 'Remove-Item -Force ' + .. table.concat( + is_os('win') and { 'alias:cat', 'alias:echo', 'alias:sleep', 'alias:sort', 'alias:tee' } + or { 'alias:echo' }, + ',' + ) + .. ';' + module.exec([[ + let &shell = ']] .. shell .. [[' + set shellquote= shellxquote= + let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ' + let &shellcmdflag .= '[Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.UTF8Encoding]::new();' + let &shellcmdflag .= '$PSDefaultParameterValues[''Out-File:Encoding'']=''utf8'';' + let &shellcmdflag .= ']] .. cmd .. [[' + let &shellredir = '2>&1 | %%{ "$_" } | Out-File %s; exit $LastExitCode' + let &shellpipe = '2>&1 | %%{ "$_" } | tee %s; exit $LastExitCode' + ]]) + return found +end + +---@param func function +---@return table<string,function> +function module.create_callindex(func) + return setmetatable({}, { + --- @param tbl table<any,function> + --- @param arg1 string + --- @return function + __index = function(tbl, arg1) + local ret = function(...) + return func(arg1, ...) + end + tbl[arg1] = ret + return ret + end, + }) +end + +--- @param method string +--- @param ... any +function module.nvim_async(method, ...) + assert(session):notify(method, ...) +end + +--- Executes a Vimscript function via RPC. +--- Fails on Vimscript error, but does not update v:errmsg. +--- @param name string +--- @param ... any +--- @return any +function module.call(name, ...) + return module.request('nvim_call_function', name, { ... }) +end + +module.async_meths = module.create_callindex(module.nvim_async) + +module.rpc = { + fn = module.create_callindex(module.call), + api = module.create_callindex(module.request), +} + +module.lua = { + fn = module.create_callindex(module.call_lua), + api = module.create_callindex(module.request_lua), +} + +module.describe_lua_and_rpc = function(describe) + return function(what, tests) + local function d(flavour) + describe(string.format('%s (%s)', what, flavour), function(...) + return tests(module[flavour].api, ...) + end) + end + + d('rpc') + d('lua') + end +end + +--- add for typing. The for loop after will overwrite this +module.api = vim.api +module.fn = vim.fn + +for name, fns in pairs(module.rpc) do + --- @diagnostic disable-next-line:no-unknown + module[name] = fns +end + +-- Executes an ex-command. Vimscript errors manifest as client (lua) errors, but +-- v:errmsg will not be updated. +module.command = module.api.nvim_command + +-- Evaluates a Vimscript expression. +-- Fails on Vimscript error, but does not update v:errmsg. +module.eval = module.api.nvim_eval + +function module.poke_eventloop() + -- Execute 'nvim_eval' (a deferred function) to + -- force at least one main_loop iteration + module.api.nvim_eval('1') +end + +function module.buf_lines(bufnr) + return module.exec_lua('return vim.api.nvim_buf_get_lines((...), 0, -1, false)', bufnr) +end + +---@see buf_lines() +function module.curbuf_contents() + module.poke_eventloop() -- Before inspecting the buffer, do whatever. + return table.concat(module.api.nvim_buf_get_lines(0, 0, -1, true), '\n') +end + +function module.expect(contents) + return eq(dedent(contents), module.curbuf_contents()) +end + +function module.expect_any(contents) + contents = dedent(contents) + return ok(nil ~= string.find(module.curbuf_contents(), contents, 1, true)) +end + +--- @param expected any[] +--- @param received any[] +--- @param kind string +--- @return any +function module.expect_events(expected, received, kind) + if not pcall(eq, expected, received) then + local msg = 'unexpected ' .. kind .. ' received.\n\n' + + msg = msg .. 'received events:\n' + for _, e in ipairs(received) do + msg = msg .. ' ' .. vim.inspect(e) .. ';\n' + end + msg = msg .. '\nexpected events:\n' + for _, e in ipairs(expected) do + msg = msg .. ' ' .. vim.inspect(e) .. ';\n' + end + fail(msg) + end + return received +end + +-- Checks that the Nvim session did not terminate. +function module.assert_alive() + assert(2 == module.eval('1+1'), 'crash? request failed') +end + +-- Asserts that buffer is loaded and visible in the current tabpage. +function module.assert_visible(bufnr, visible) + assert(type(visible) == 'boolean') + eq(visible, module.api.nvim_buf_is_loaded(bufnr)) + if visible then + assert( + -1 ~= module.fn.bufwinnr(bufnr), + 'expected buffer to be visible in current tabpage: ' .. tostring(bufnr) + ) + else + assert( + -1 == module.fn.bufwinnr(bufnr), + 'expected buffer NOT visible in current tabpage: ' .. tostring(bufnr) + ) + end +end + +--- @param path string +local function do_rmdir(path) + local stat = uv.fs_stat(path) + if stat == nil then + return + end + if stat.type ~= 'directory' then + error(string.format('rmdir: not a directory: %s', path)) + end + for file in vim.fs.dir(path) do + if file ~= '.' and file ~= '..' then + local abspath = path .. '/' .. file + if t_global.isdir(abspath) then + do_rmdir(abspath) -- recurse + else + local ret, err = os.remove(abspath) + if not ret then + if not session then + error('os.remove: ' .. err) + else + -- Try Nvim delete(): it handles `readonly` attribute on Windows, + -- and avoids Lua cross-version/platform incompatibilities. + if -1 == module.call('delete', abspath) then + local hint = (is_os('win') and ' (hint: try :%bwipeout! before rmdir())' or '') + error('delete() failed' .. hint .. ': ' .. abspath) + end + end + end + end + end + end + local ret, err = uv.fs_rmdir(path) + if not ret then + error('luv.fs_rmdir(' .. path .. '): ' .. err) + end +end + +local start_dir = uv.cwd() + +function module.rmdir(path) + local ret, _ = pcall(do_rmdir, path) + if not ret and is_os('win') then + -- Maybe "Permission denied"; try again after changing the nvim + -- process to the top-level directory. + module.command([[exe 'cd '.fnameescape(']] .. start_dir .. "')") + ret, _ = pcall(do_rmdir, path) + end + -- During teardown, the nvim process may not exit quickly enough, then rmdir() + -- will fail (on Windows). + if not ret then -- Try again. + sleep(1000) + do_rmdir(path) + end +end + +function module.exc_exec(cmd) + module.command(([[ + try + execute "%s" + catch + let g:__exception = v:exception + endtry + ]]):format(cmd:gsub('\n', '\\n'):gsub('[\\"]', '\\%0'))) + local ret = module.eval('get(g:, "__exception", 0)') + module.command('unlet! g:__exception') + return ret +end + +--- @param cond boolean +--- @param reason? string +--- @return boolean +function module.skip(cond, reason) + if cond then + --- @type fun(reason: string) + local pending = getfenv(2).pending + pending(reason or 'FIXME') + return true + end + return false +end + +-- Calls pending() and returns `true` if the system is too slow to +-- run fragile or expensive tests. Else returns `false`. +function module.skip_fragile(pending_fn, cond) + if pending_fn == nil or type(pending_fn) ~= type(function() end) then + error('invalid pending_fn') + end + if cond then + pending_fn('skipped (test is fragile on this system)', function() end) + return true + elseif os.getenv('TEST_SKIP_FRAGILE') then + pending_fn('skipped (TEST_SKIP_FRAGILE)', function() end) + return true + end + return false +end + +function module.exec(code) + module.api.nvim_exec2(code, {}) +end + +--- @param code string +--- @return string +function module.exec_capture(code) + return module.api.nvim_exec2(code, { output = true }).output +end + +--- @param code string +--- @return any +function module.exec_lua(code, ...) + return module.api.nvim_exec_lua(code, { ... }) +end + +function module.get_pathsep() + return is_os('win') and '\\' or '/' +end + +--- Gets the filesystem root dir, namely "/" or "C:/". +function module.pathroot() + local pathsep = package.config:sub(1, 1) + return is_os('win') and (module.nvim_dir:sub(1, 2) .. pathsep) or '/' +end + +--- Gets the full `…/build/bin/{name}` path of a test program produced by +--- `test/functional/fixtures/CMakeLists.txt`. +--- +--- @param name (string) Name of the test program. +function module.testprg(name) + local ext = module.is_os('win') and '.exe' or '' + return ('%s/%s%s'):format(module.nvim_dir, name, ext) +end + +function module.is_asan() + local version = module.eval('execute("verbose version")') + return version:match('-fsanitize=[a-z,]*address') +end + +-- Returns a valid, platform-independent Nvim listen address. +-- Useful for communicating with child instances. +function module.new_pipename() + -- HACK: Start a server temporarily, get the name, then stop it. + local pipename = module.eval('serverstart()') + module.fn.serverstop(pipename) + -- Remove the pipe so that trying to connect to it without a server listening + -- will be an error instead of a hang. + os.remove(pipename) + return pipename +end + +--- @param provider string +--- @return string|boolean? +function module.missing_provider(provider) + if provider == 'ruby' or provider == 'perl' then + --- @type string? + local e = module.exec_lua("return {require('vim.provider." .. provider .. "').detect()}")[2] + return e ~= '' and e or false + elseif provider == 'node' then + --- @type string? + local e = module.fn['provider#node#Detect']()[2] + return e ~= '' and e or false + elseif provider == 'python' then + return module.exec_lua([[return {require('vim.provider.python').detect_by_module('neovim')}]])[2] + end + assert(false, 'Unknown provider: ' .. provider) +end + +--- @param obj string|table +--- @return any +function module.alter_slashes(obj) + if not is_os('win') then + return obj + end + if type(obj) == 'string' then + local ret = obj:gsub('/', '\\') + return ret + elseif type(obj) == 'table' then + --- @cast obj table<any,any> + local ret = {} --- @type table<any,any> + for k, v in pairs(obj) do + ret[k] = module.alter_slashes(v) + end + return ret + end + assert(false, 'expected string or table of strings, got ' .. type(obj)) +end + +local load_factor = 1 +if t_global.is_ci() then + -- Compute load factor only once (but outside of any tests). + module.clear() + module.request('nvim_command', 'source test/old/testdir/load.vim') + load_factor = module.request('nvim_eval', 'g:test_load_factor') +end + +--- @param num number +--- @return number +function module.load_adjust(num) + return math.ceil(num * load_factor) +end + +--- @param ctx table<string,any> +--- @return table +function module.parse_context(ctx) + local parsed = {} --- @type table<string,any> + for _, item in ipairs({ 'regs', 'jumps', 'bufs', 'gvars' }) do + --- @param v any + parsed[item] = vim.tbl_filter(function(v) + return type(v) == 'table' + end, module.call('msgpackparse', ctx[item])) + end + parsed['bufs'] = parsed['bufs'][1] + --- @param v any + return vim.tbl_map(function(v) + if #v == 0 then + return nil + end + return v + end, parsed) +end + +function module.add_builddir_to_rtp() + -- Add runtime from build dir for doc/tags (used with :help). + module.command(string.format([[set rtp+=%s/runtime]], module.paths.test_build_dir)) +end + +--- Kill (reap) a process by PID. +--- @param pid string +--- @return boolean? +function module.os_kill(pid) + return os.execute( + ( + is_os('win') and 'taskkill /f /t /pid ' .. pid .. ' > nul' + or 'kill -9 ' .. pid .. ' > /dev/null' + ) + ) +end + +--- Create folder with non existing parents +--- @param path string +--- @return boolean? +function module.mkdir_p(path) + return os.execute((is_os('win') and 'mkdir ' .. path or 'mkdir -p ' .. path)) +end + +--- @return test.functional.testutil +return function(after_each) + if after_each then + after_each(function() + check_logs() + check_cores('build/bin/nvim') + if session then + local msg = session:next_message(0) + if msg then + if msg[1] == 'notification' and msg[2] == 'nvim_error_event' then + error(msg[3][2]) + end + end + end + end) + end + return module +end diff --git a/test/functional/treesitter/fold_spec.lua b/test/functional/treesitter/fold_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local insert = helpers.insert -local exec_lua = helpers.exec_lua -local command = helpers.command -local feed = helpers.feed -local poke_eventloop = helpers.poke_eventloop +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eq = t.eq +local insert = t.insert +local exec_lua = t.exec_lua +local command = t.command +local feed = t.feed +local poke_eventloop = t.poke_eventloop local Screen = require('test.functional.ui.screen') before_each(clear) diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local insert = helpers.insert -local exec_lua = helpers.exec_lua -local feed = helpers.feed -local command = helpers.command -local api = helpers.api -local eq = helpers.eq +local clear = t.clear +local insert = t.insert +local exec_lua = t.exec_lua +local feed = t.feed +local command = t.command +local api = t.api +local eq = t.eq before_each(clear) @@ -872,7 +872,7 @@ describe('treesitter highlighting (help)', function() ]], } - helpers.api.nvim_buf_set_text(0, 0, 1, 0, 5, { 'lua' }) + t.api.nvim_buf_set_text(0, 0, 1, 0, 5, { 'lua' }) screen:expect { grid = [[ @@ -885,7 +885,7 @@ describe('treesitter highlighting (help)', function() ]], } - helpers.api.nvim_buf_set_text(0, 0, 1, 0, 4, { 'ruby' }) + t.api.nvim_buf_set_text(0, 0, 1, 0, 4, { 'ruby' }) screen:expect { grid = [[ diff --git a/test/functional/treesitter/inspect_tree_spec.lua b/test/functional/treesitter/inspect_tree_spec.lua @@ -1,17 +1,17 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local insert = helpers.insert -local dedent = helpers.dedent -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local feed = helpers.feed +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local insert = t.insert +local dedent = t.dedent +local eq = t.eq +local exec_lua = t.exec_lua +local feed = t.feed describe('vim.treesitter.inspect_tree', function() before_each(clear) local expect_tree = function(x) local expected = vim.split(vim.trim(dedent(x)), '\n') - local actual = helpers.buf_lines(0) ---@type string[] + local actual = t.buf_lines(0) ---@type string[] eq(expected, actual) end diff --git a/test/functional/treesitter/language_spec.lua b/test/functional/treesitter/language_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local eq = helpers.eq -local command = helpers.command -local exec_lua = helpers.exec_lua -local pcall_err = helpers.pcall_err -local matches = helpers.matches -local insert = helpers.insert +local t = require('test.functional.testutil')(after_each) + +local clear = t.clear +local eq = t.eq +local command = t.command +local exec_lua = t.exec_lua +local pcall_err = t.pcall_err +local matches = t.matches +local insert = t.insert before_each(clear) diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local insert = helpers.insert -local assert_alive = helpers.assert_alive +local clear = t.clear +local eq = t.eq +local exec_lua = t.exec_lua +local insert = t.insert +local assert_alive = t.assert_alive before_each(clear) diff --git a/test/functional/treesitter/parser_spec.lua b/test/functional/treesitter/parser_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local dedent = helpers.dedent -local eq = helpers.eq -local insert = helpers.insert -local exec_lua = helpers.exec_lua -local pcall_err = helpers.pcall_err -local feed = helpers.feed +local clear = t.clear +local dedent = t.dedent +local eq = t.eq +local insert = t.insert +local exec_lua = t.exec_lua +local pcall_err = t.pcall_err +local feed = t.feed describe('treesitter parser API', function() before_each(function() @@ -381,7 +381,7 @@ int x = INT_MAX; { 2, 29, 2, 66 }, -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y)) }, get_ranges()) - helpers.feed('ggo<esc>') + t.feed('ggo<esc>') eq(5, exec_lua('return #parser:children().c:trees()')) eq({ { 0, 0, 8, 0 }, -- root tree @@ -418,7 +418,7 @@ int x = INT_MAX; -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y)) }, get_ranges()) - helpers.feed('ggo<esc>') + t.feed('ggo<esc>') eq('table', exec_lua('return type(parser:children().c)')) eq(2, exec_lua('return #parser:children().c:trees()')) eq({ @@ -430,7 +430,7 @@ int x = INT_MAX; -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y)) }, get_ranges()) - helpers.feed('7ggI//<esc>') + t.feed('7ggI//<esc>') exec_lua([[parser:parse({6, 7})]]) eq('table', exec_lua('return type(parser:children().c)')) eq(2, exec_lua('return #parser:children().c:trees()')) @@ -468,7 +468,7 @@ int x = INT_MAX; { 2, 29, 2, 66 }, -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y)) }, get_ranges()) - helpers.feed('ggo<esc>') + t.feed('ggo<esc>') eq(5, exec_lua('return #parser:children().c:trees()')) eq({ { 0, 0, 8, 0 }, -- root tree @@ -657,7 +657,7 @@ int x = INT_MAX; { 'declaration', 1, 2, 1, 12 }, }, run_query()) - helpers.command 'normal ggO' + t.command 'normal ggO' insert('int a;') eq({ diff --git a/test/functional/treesitter/query_spec.lua b/test/functional/treesitter/query_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local dedent = helpers.dedent -local eq = helpers.eq -local insert = helpers.insert -local exec_lua = helpers.exec_lua -local pcall_err = helpers.pcall_err -local is_os = helpers.is_os -local api = helpers.api -local fn = helpers.fn +local t = require('test.functional.testutil')(after_each) + +local clear = t.clear +local dedent = t.dedent +local eq = t.eq +local insert = t.insert +local exec_lua = t.exec_lua +local pcall_err = t.pcall_err +local is_os = t.is_os +local api = t.api +local fn = t.fn describe('treesitter query API', function() before_each(function() diff --git a/test/functional/treesitter/utils_spec.lua b/test/functional/treesitter/utils_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local insert = helpers.insert -local eq = helpers.eq -local exec_lua = helpers.exec_lua +local clear = t.clear +local insert = t.insert +local eq = t.eq +local exec_lua = t.exec_lua before_each(clear) diff --git a/test/functional/ui/bufhl_spec.lua b/test/functional/ui/bufhl_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local command, neq = helpers.command, helpers.neq -local api = helpers.api -local eq = helpers.eq -local pcall_err = helpers.pcall_err +local clear, feed, insert = t.clear, t.feed, t.insert +local command, neq = t.command, t.neq +local api = t.api +local eq = t.eq +local pcall_err = t.pcall_err local set_virtual_text = api.nvim_buf_set_virtual_text describe('Buffer highlighting', function() diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local eq = helpers.eq -local feed = helpers.feed -local clear = helpers.clear -local api = helpers.api -local fn = helpers.fn -local source = helpers.source -local exec_capture = helpers.exec_capture -local dedent = helpers.dedent -local command = helpers.command +local eq = t.eq +local feed = t.feed +local clear = t.clear +local api = t.api +local fn = t.fn +local source = t.source +local exec_capture = t.exec_capture +local dedent = t.dedent +local command = t.command local screen diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed = helpers.clear, helpers.feed -local source = helpers.source -local command = helpers.command -local assert_alive = helpers.assert_alive -local poke_eventloop = helpers.poke_eventloop -local exec = helpers.exec -local eval = helpers.eval -local eq = helpers.eq -local is_os = helpers.is_os -local api = helpers.api +local clear, feed = t.clear, t.feed +local source = t.source +local command = t.command +local assert_alive = t.assert_alive +local poke_eventloop = t.poke_eventloop +local exec = t.exec +local eval = t.eval +local eq = t.eq +local is_os = t.is_os +local api = t.api local function new_screen(opt) local screen = Screen.new(25, 5) diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, api = helpers.clear, helpers.api -local eq = helpers.eq -local command = helpers.command +local clear, api = t.clear, t.api +local eq = t.eq +local command = t.command describe('ui/cursor', function() local screen @@ -213,8 +213,8 @@ describe('ui/cursor', function() } -- Change the cursor style. - helpers.command('hi Cursor guibg=DarkGray') - helpers.command( + t.command('hi Cursor guibg=DarkGray') + t.command( 'set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr-o:hor20' .. ',a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor' .. ',sm:block-blinkwait175-blinkoff150-blinkon175' @@ -260,8 +260,8 @@ describe('ui/cursor', function() end) -- Change hl groups only, should update the styles - helpers.command('hi Cursor guibg=Red') - helpers.command('hi lCursor guibg=Green') + t.command('hi Cursor guibg=Red') + t.command('hi lCursor guibg=Green') -- Update the expected values. for _, m in ipairs(expected_mode_info) do @@ -280,7 +280,7 @@ describe('ui/cursor', function() end) -- update the highlight again to hide cursor - helpers.command('hi Cursor blend=100') + t.command('hi Cursor blend=100') for _, m in ipairs(expected_mode_info) do if m.hl_id then diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua @@ -1,18 +1,18 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local feed = helpers.feed -local insert = helpers.insert -local exec_lua = helpers.exec_lua -local exec = helpers.exec -local expect_events = helpers.expect_events -local api = helpers.api -local fn = helpers.fn -local command = helpers.command -local eq = helpers.eq -local assert_alive = helpers.assert_alive -local pcall_err = helpers.pcall_err +local clear = t.clear +local feed = t.feed +local insert = t.insert +local exec_lua = t.exec_lua +local exec = t.exec +local expect_events = t.expect_events +local api = t.api +local fn = t.fn +local command = t.command +local eq = t.eq +local assert_alive = t.assert_alive +local pcall_err = t.pcall_err describe('decorations providers', function() local screen @@ -696,7 +696,7 @@ describe('decorations providers', function() end ]] - helpers.assert_alive() + t.assert_alive() end) it('supports subpriorities (order of definitions in a query file #27131)', function() @@ -2411,7 +2411,7 @@ describe('extmark decorations', function() | ]]} - helpers.assert_alive() + t.assert_alive() end) it('priority ordering of overlay or win_col virtual text at same position', function() @@ -5044,8 +5044,8 @@ l5 insert(example_test3) feed 'gg' - helpers.command('sign define Oldsign text=x') - helpers.command([[exe 'sign place 42 line=2 name=Oldsign buffer=' . bufnr('')]]) + t.command('sign define Oldsign text=x') + t.command([[exe 'sign place 42 line=2 name=Oldsign buffer=' . bufnr('')]]) api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S1'}) api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S2'}) @@ -5068,8 +5068,8 @@ l5 insert(example_test3) feed 'gg' - helpers.command('sign define Oldsign text=x') - helpers.command([[exe 'sign place 42 line=2 name=Oldsign buffer=' . bufnr('')]]) + t.command('sign define Oldsign text=x') + t.command([[exe 'sign place 42 line=2 name=Oldsign buffer=' . bufnr('')]]) api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S1'}) api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S2'}) diff --git a/test/functional/ui/diff_spec.lua b/test/functional/ui/diff_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local feed = helpers.feed -local clear = helpers.clear -local command = helpers.command -local insert = helpers.insert -local write_file = helpers.write_file -local dedent = helpers.dedent -local exec = helpers.exec -local eq = helpers.eq -local api = helpers.api +local feed = t.feed +local clear = t.clear +local command = t.command +local insert = t.insert +local write_file = t.write_file +local dedent = t.dedent +local exec = t.exec +local eq = t.eq +local api = t.api before_each(clear) diff --git a/test/functional/ui/embed_spec.lua b/test/functional/ui/embed_spec.lua @@ -1,21 +1,21 @@ local uv = vim.uv -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local api = helpers.api -local feed = helpers.feed -local eq = helpers.eq -local neq = helpers.neq -local clear = helpers.clear -local ok = helpers.ok -local fn = helpers.fn -local nvim_prog = helpers.nvim_prog -local retry = helpers.retry -local write_file = helpers.write_file -local assert_log = helpers.assert_log -local check_close = helpers.check_close -local is_os = helpers.is_os +local api = t.api +local feed = t.feed +local eq = t.eq +local neq = t.neq +local clear = t.clear +local ok = t.ok +local fn = t.fn +local nvim_prog = t.nvim_prog +local retry = t.retry +local write_file = t.write_file +local assert_log = t.assert_log +local check_close = t.check_close +local is_os = t.is_os local testlog = 'Xtest-embed-log' @@ -58,7 +58,7 @@ local function test_embed(ext_linegrid) end) it("doesn't erase output when setting color scheme", function() - if helpers.is_os('openbsd') then + if t.is_os('openbsd') then pending('FIXME #10804') end startup('--cmd', 'echoerr "foo"', '--cmd', 'color default', '--cmd', 'echoerr "bar"') @@ -143,7 +143,7 @@ describe('--embed UI', function() ]] if not is_os('win') then - assert_log('Failed to get flags on descriptor 3: Bad file descriptor', testlog) + assert_log('Failed to get flags on descriptor 3: Bad file descriptor', testlog, 100) end end) @@ -233,7 +233,7 @@ describe('--embed UI', function() } eq({ [16777215] = true }, seen) - -- NB: by accident how functional/helpers.lua currently handles the default color scheme, the + -- NB: by accident how functional/t.lua currently handles the default color scheme, the -- above is sufficient to test the behavior. But in case that workaround is removed, we need -- a test with an explicit override like below, so do it to remain safe. startup('--cmd', 'hi NORMAL guibg=#FF00FF') @@ -253,44 +253,44 @@ describe('--embed UI', function() screen:expect { condition = function() - eq(helpers.paths.test_source_path, screen.pwd) + eq(t.paths.test_source_path, screen.pwd) end, } -- Change global cwd - helpers.command(string.format('cd %s/src/nvim', helpers.paths.test_source_path)) + t.command(string.format('cd %s/src/nvim', t.paths.test_source_path)) screen:expect { condition = function() - eq(string.format('%s/src/nvim', helpers.paths.test_source_path), screen.pwd) + eq(string.format('%s/src/nvim', t.paths.test_source_path), screen.pwd) end, } -- Split the window and change the cwd in the split - helpers.command('new') - helpers.command(string.format('lcd %s/test', helpers.paths.test_source_path)) + t.command('new') + t.command(string.format('lcd %s/test', t.paths.test_source_path)) screen:expect { condition = function() - eq(string.format('%s/test', helpers.paths.test_source_path), screen.pwd) + eq(string.format('%s/test', t.paths.test_source_path), screen.pwd) end, } -- Move to the original window - helpers.command('wincmd p') + t.command('wincmd p') screen:expect { condition = function() - eq(string.format('%s/src/nvim', helpers.paths.test_source_path), screen.pwd) + eq(string.format('%s/src/nvim', t.paths.test_source_path), screen.pwd) end, } -- Change global cwd again - helpers.command(string.format('cd %s', helpers.paths.test_source_path)) + t.command(string.format('cd %s', t.paths.test_source_path)) screen:expect { condition = function() - eq(helpers.paths.test_source_path, screen.pwd) + eq(t.paths.test_source_path, screen.pwd) end, } end) @@ -298,9 +298,9 @@ end) describe('--embed --listen UI', function() it('waits for connection on listening address', function() - helpers.skip(helpers.is_os('win')) + t.skip(t.is_os('win')) clear() - local child_server = assert(helpers.new_pipename()) + local child_server = assert(t.new_pipename()) fn.jobstart({ nvim_prog, '--embed', @@ -314,7 +314,7 @@ describe('--embed --listen UI', function() neq(nil, uv.fs_stat(child_server)) end) - local child_session = helpers.connect(child_server) + local child_session = t.connect(child_server) local info_ok, api_info = child_session:request('nvim_get_api_info') ok(info_ok) diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua @@ -1,24 +1,24 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') local os = require('os') -local clear, feed = helpers.clear, helpers.feed -local assert_alive = helpers.assert_alive -local command, feed_command = helpers.command, helpers.feed_command -local eval = helpers.eval -local eq = helpers.eq -local neq = helpers.neq -local expect = helpers.expect -local exec = helpers.exec -local exec_lua = helpers.exec_lua -local insert = helpers.insert -local api = helpers.api -local fn = helpers.fn -local run = helpers.run -local pcall_err = helpers.pcall_err +local clear, feed = t.clear, t.feed +local assert_alive = t.assert_alive +local command, feed_command = t.command, t.feed_command +local eval = t.eval +local eq = t.eq +local neq = t.neq +local expect = t.expect +local exec = t.exec +local exec_lua = t.exec_lua +local insert = t.insert +local api = t.api +local fn = t.fn +local run = t.run +local pcall_err = t.pcall_err local tbl_contains = vim.tbl_contains -local curbuf = helpers.api.nvim_get_current_buf -local curwin = helpers.api.nvim_get_current_win -local curtab = helpers.api.nvim_get_current_tabpage +local curbuf = t.api.nvim_get_current_buf +local curwin = t.api.nvim_get_current_win +local curtab = t.api.nvim_get_current_tabpage local NIL = vim.NIL describe('float window', function() @@ -4080,7 +4080,7 @@ describe('float window', function() if multigrid then pending("supports second UI without multigrid", function() - local session2 = helpers.connect(eval('v:servername')) + local session2 = t.connect(eval('v:servername')) print(session2:request("nvim_eval", "2+2")) local screen2 = Screen.new(40,7) screen2:attach(nil, session2) @@ -7978,7 +7978,7 @@ describe('float window', function() end) it("correctly redraws when overlaid windows are resized #13991", function() - helpers.source([[ + t.source([[ let popup_config = {"relative" : "editor", \ "width" : 7, \ "height" : 3, @@ -8042,7 +8042,7 @@ describe('float window', function() ]]) end - helpers.source([[ + t.source([[ let new_popup_config = {"width" : 1, "height" : 3} let new_border_config = {"width" : 3, "height" : 5} @@ -8057,7 +8057,7 @@ describe('float window', function() nnoremap zz <cmd>call Resize()<cr> ]]) - helpers.feed("zz") + t.feed("zz") if multigrid then screen:expect{grid=[[ ## grid 1 diff --git a/test/functional/ui/fold_spec.lua b/test/functional/ui/fold_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, eq = helpers.clear, helpers.feed, helpers.eq -local command = helpers.command -local feed_command = helpers.feed_command -local insert = helpers.insert -local fn = helpers.fn -local api = helpers.api -local exec = helpers.exec -local assert_alive = helpers.assert_alive +local clear, feed, eq = t.clear, t.feed, t.eq +local command = t.command +local feed_command = t.feed_command +local insert = t.insert +local fn = t.fn +local api = t.api +local exec = t.exec +local assert_alive = t.assert_alive local content1 = [[ This is a diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') local os = require('os') -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local command, exec = helpers.command, helpers.exec -local eval = helpers.eval -local feed_command, eq = helpers.feed_command, helpers.eq -local fn = helpers.fn -local api = helpers.api -local exec_lua = helpers.exec_lua +local clear, feed, insert = t.clear, t.feed, t.insert +local command, exec = t.command, t.exec +local eval = t.eval +local feed_command, eq = t.feed_command, t.eq +local fn = t.fn +local api = t.api +local exec_lua = t.exec_lua describe('colorscheme compatibility', function() before_each(function() @@ -2196,7 +2196,7 @@ describe("'winhighlight' highlight", function() ]], } - helpers.assert_alive() + t.assert_alive() end) it('can redraw statusline on cursor movement', function() diff --git a/test/functional/ui/hlstate_spec.lua b/test/functional/ui/hlstate_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, insert = helpers.clear, helpers.insert -local command = helpers.command -local api = helpers.api -local testprg = helpers.testprg -local thelpers = require('test.functional.terminal.helpers') -local skip = helpers.skip -local is_os = helpers.is_os +local clear, insert = t.clear, t.insert +local command = t.command +local api = t.api +local testprg = t.testprg +local tt = require('test.functional.terminal.testutil') +local skip = t.skip +local is_os = t.is_os describe('ext_hlstate detailed highlights', function() local screen @@ -236,11 +236,11 @@ describe('ext_hlstate detailed highlights', function() {7: }| ]]) - thelpers.feed_data('x ') - thelpers.set_fg(45) - thelpers.feed_data('y ') - thelpers.set_bold() - thelpers.feed_data('z\n') + tt.feed_data('x ') + tt.set_fg(45) + tt.feed_data('y ') + tt.set_bold() + tt.feed_data('z\n') -- TODO(bfredl): check if this distinction makes sense if is_os('win') then screen:expect([[ @@ -260,8 +260,8 @@ describe('ext_hlstate detailed highlights', function() ]]) end - thelpers.feed_termcode('[A') - thelpers.feed_termcode('[2C') + tt.feed_termcode('[A') + tt.feed_termcode('[2C') if is_os('win') then screen:expect([[ ^tty ready | @@ -381,7 +381,7 @@ describe('ext_hlstate detailed highlights', function() }, } - helpers.feed('3ggV2jd') + t.feed('3ggV2jd') --screen:redraw_debug() screen:expect { grid = [[ @@ -478,7 +478,7 @@ describe('ext_hlstate detailed highlights', function() }, } - helpers.feed('3ggV2jd') + t.feed('3ggV2jd') --screen:redraw_debug() screen:expect { grid = [[ @@ -512,7 +512,7 @@ describe('ext_hlstate detailed highlights', function() end insert('last line') - helpers.feed('gg') + t.feed('gg') screen:expect { grid = [[ ^first line | @@ -555,7 +555,7 @@ describe('ext_hlstate detailed highlights', function() }, } - helpers.feed(string.format('3ggV%ijd', num_lines - 2)) + t.feed(string.format('3ggV%ijd', num_lines - 2)) --screen:redraw_debug(nil, nil, 100000) local expected_ids = {} diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua @@ -1,22 +1,22 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval -local expect = helpers.expect -local feed = helpers.feed -local insert = helpers.insert -local fn = helpers.fn -local api = helpers.api -local neq = helpers.neq -local ok = helpers.ok -local retry = helpers.retry -local source = helpers.source -local poke_eventloop = helpers.poke_eventloop +local clear = t.clear +local command = t.command +local eq = t.eq +local eval = t.eval +local expect = t.expect +local feed = t.feed +local insert = t.insert +local fn = t.fn +local api = t.api +local neq = t.neq +local ok = t.ok +local retry = t.retry +local source = t.source +local poke_eventloop = t.poke_eventloop local sleep = vim.uv.sleep -local testprg = helpers.testprg -local assert_alive = helpers.assert_alive +local testprg = t.testprg +local assert_alive = t.assert_alive local default_text = [[ Inc substitution on @@ -1736,9 +1736,9 @@ describe("'inccommand' autocommands", function() CmdwinLeave = {}, } - local function bufferlist(t) + local function bufferlist(q) local s = '' - for _, buffer in pairs(t) do + for _, buffer in pairs(q) do s = s .. ', ' .. tostring(buffer) end return s @@ -2559,7 +2559,7 @@ describe(':substitute', function() end) it(':substitute with inccommand during :terminal activity', function() - if helpers.skip_fragile(pending) then + if t.skip_fragile(pending) then return end retry(2, 40000, function() diff --git a/test/functional/ui/inccommand_user_spec.lua b/test/functional/ui/inccommand_user_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local api = helpers.api -local clear = helpers.clear -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local insert = helpers.insert -local feed = helpers.feed -local command = helpers.command -local assert_alive = helpers.assert_alive +local api = t.api +local clear = t.clear +local eq = t.eq +local exec_lua = t.exec_lua +local insert = t.insert +local feed = t.feed +local command = t.command +local assert_alive = t.assert_alive -- Implements a :Replace command that works like :substitute and has multibuffer support. local setup_replace_cmd = [[ diff --git a/test/functional/ui/input_spec.lua b/test/functional/ui/input_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, feed_command = helpers.clear, helpers.feed_command -local feed, next_msg, eq = helpers.feed, helpers.next_msg, helpers.eq -local command = helpers.command -local expect = helpers.expect -local curbuf_contents = helpers.curbuf_contents -local api = helpers.api -local exec_lua = helpers.exec_lua -local write_file = helpers.write_file -local fn = helpers.fn -local eval = helpers.eval +local t = require('test.functional.testutil')(after_each) +local clear, feed_command = t.clear, t.feed_command +local feed, next_msg, eq = t.feed, t.next_msg, t.eq +local command = t.command +local expect = t.expect +local curbuf_contents = t.curbuf_contents +local api = t.api +local exec_lua = t.exec_lua +local write_file = t.write_file +local fn = t.fn +local eval = t.eval local Screen = require('test.functional.ui.screen') before_each(clear) diff --git a/test/functional/ui/linematch_spec.lua b/test/functional/ui/linematch_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local feed = helpers.feed -local clear = helpers.clear -local write_file = helpers.write_file +local feed = t.feed +local clear = t.clear +local write_file = t.write_file describe('Diff mode screen with 3 diffs open', function() local fname = 'Xtest-functional-diff-screen-1' @@ -1094,10 +1094,10 @@ describe('regressions', function() screen = Screen.new(100, 20) screen:attach() -- line must be greater than MATCH_CHAR_MAX_LEN - helpers.api.nvim_buf_set_lines(0, 0, -1, false, { string.rep('a', 1000) .. 'hello' }) - helpers.exec 'vnew' - helpers.api.nvim_buf_set_lines(0, 0, -1, false, { string.rep('a', 1010) .. 'world' }) - helpers.exec 'windo diffthis' + t.api.nvim_buf_set_lines(0, 0, -1, false, { string.rep('a', 1000) .. 'hello' }) + t.exec 'vnew' + t.api.nvim_buf_set_lines(0, 0, -1, false, { string.rep('a', 1010) .. 'world' }) + t.exec 'windo diffthis' end) it('properly computes filler lines for hunks bigger than linematch limit', function() @@ -1109,10 +1109,10 @@ describe('regressions', function() for i = 0, 29 do lines[#lines + 1] = tostring(i) end - helpers.api.nvim_buf_set_lines(0, 0, -1, false, lines) - helpers.exec 'vnew' - helpers.api.nvim_buf_set_lines(0, 0, -1, false, { '00', '29' }) - helpers.exec 'windo diffthis' + t.api.nvim_buf_set_lines(0, 0, -1, false, lines) + t.exec 'vnew' + t.api.nvim_buf_set_lines(0, 0, -1, false, { '00', '29' }) + t.exec 'windo diffthis' feed('<C-e>') screen:expect { grid = [[ diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua @@ -1,26 +1,26 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed = helpers.clear, helpers.feed -local eval = helpers.eval -local eq = helpers.eq -local neq = helpers.neq -local command = helpers.command -local set_method_error = helpers.set_method_error -local api = helpers.api -local async_meths = helpers.async_meths -local test_build_dir = helpers.paths.test_build_dir -local nvim_prog = helpers.nvim_prog -local testprg = helpers.testprg -local exec = helpers.exec -local exec_capture = helpers.exec_capture -local exc_exec = helpers.exc_exec -local exec_lua = helpers.exec_lua -local poke_eventloop = helpers.poke_eventloop -local assert_alive = helpers.assert_alive -local retry = helpers.retry -local is_os = helpers.is_os -local fn = helpers.fn -local skip = helpers.skip +local clear, feed = t.clear, t.feed +local eval = t.eval +local eq = t.eq +local neq = t.neq +local command = t.command +local set_method_error = t.set_method_error +local api = t.api +local async_meths = t.async_meths +local test_build_dir = t.paths.test_build_dir +local nvim_prog = t.nvim_prog +local testprg = t.testprg +local exec = t.exec +local exec_capture = t.exec_capture +local exc_exec = t.exc_exec +local exec_lua = t.exec_lua +local poke_eventloop = t.poke_eventloop +local assert_alive = t.assert_alive +local retry = t.retry +local is_os = t.is_os +local fn = t.fn +local skip = t.skip describe('ui/ext_messages', function() local screen @@ -2683,13 +2683,13 @@ end) it('pager works in headless mode with UI attached', function() skip(is_os('win')) clear() - local child_server = assert(helpers.new_pipename()) + local child_server = assert(t.new_pipename()) fn.jobstart({ nvim_prog, '--clean', '--headless', '--listen', child_server }) retry(nil, nil, function() neq(nil, vim.uv.fs_stat(child_server)) end) - local child_session = helpers.connect(child_server) + local child_session = t.connect(child_server) local child_screen = Screen.new(40, 6) child_screen:attach(nil, child_session) child_screen._default_attr_ids = nil -- TODO: unskip with new color scheme diff --git a/test/functional/ui/mode_spec.lua b/test/functional/ui/mode_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local command = helpers.command -local retry = helpers.retry +local clear, feed, insert = t.clear, t.feed, t.insert +local command = t.command +local retry = t.retry describe('ui mode_change event', function() local screen diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, api = helpers.clear, helpers.feed, helpers.api -local insert, feed_command = helpers.insert, helpers.feed_command -local eq, fn = helpers.eq, helpers.fn -local poke_eventloop = helpers.poke_eventloop -local command = helpers.command -local exec = helpers.exec +local clear, feed, api = t.clear, t.feed, t.api +local insert, feed_command = t.insert, t.feed_command +local eq, fn = t.eq, t.fn +local poke_eventloop = t.poke_eventloop +local command = t.command +local exec = t.exec describe('ui/mouse/input', function() local screen @@ -575,7 +575,7 @@ describe('ui/mouse/input', function() :tabprevious | ]]) feed('<LeftMouse><10,0><LeftRelease>') -- go to second tab - helpers.poke_eventloop() + t.poke_eventloop() feed('<LeftMouse><0,1>') screen:expect([[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| @@ -1856,8 +1856,8 @@ describe('ui/mouse/input', function() it('feeding <MouseMove> in Normal mode does not use uninitialized memory #19480', function() feed('<MouseMove>') - helpers.poke_eventloop() - helpers.assert_alive() + t.poke_eventloop() + t.assert_alive() end) it('mousemodel=popup_setpos', function() diff --git a/test/functional/ui/multibyte_spec.lua b/test/functional/ui/multibyte_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local feed = helpers.feed -local feed_command = helpers.feed_command -local insert = helpers.insert -local fn = helpers.fn -local api = helpers.api +local clear = t.clear +local command = t.command +local feed = t.feed +local feed_command = t.feed_command +local insert = t.insert +local fn = t.fn +local api = t.api local split = vim.split -local dedent = helpers.dedent +local dedent = t.dedent describe('multibyte rendering', function() local screen diff --git a/test/functional/ui/multigrid_spec.lua b/test/functional/ui/multigrid_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local feed, command, insert = helpers.feed, helpers.command, helpers.insert -local eq = helpers.eq -local fn = helpers.fn -local api = helpers.api -local curwin = helpers.api.nvim_get_current_win -local poke_eventloop = helpers.poke_eventloop +local clear = t.clear +local feed, command, insert = t.feed, t.command, t.insert +local eq = t.eq +local fn = t.fn +local api = t.api +local curwin = t.api.nvim_get_current_win +local poke_eventloop = t.poke_eventloop describe('ext_multigrid', function() diff --git a/test/functional/ui/options_spec.lua b/test/functional/ui/options_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local shallowcopy = helpers.shallowcopy -local eval = helpers.eval +local clear = t.clear +local command = t.command +local eq = t.eq +local shallowcopy = t.shallowcopy +local eval = t.eval describe('UI receives option updates', function() local screen diff --git a/test/functional/ui/output_spec.lua b/test/functional/ui/output_spec.lua @@ -1,19 +1,20 @@ local Screen = require('test.functional.ui.screen') -local helpers = require('test.functional.helpers')(after_each) -local child_session = require('test.functional.terminal.helpers') -local assert_alive = helpers.assert_alive -local mkdir, write_file, rmdir = helpers.mkdir, helpers.write_file, helpers.rmdir -local eq = helpers.eq -local feed = helpers.feed -local feed_command = helpers.feed_command -local clear = helpers.clear -local command = helpers.command -local testprg = helpers.testprg -local nvim_dir = helpers.nvim_dir -local has_powershell = helpers.has_powershell -local set_shell_powershell = helpers.set_shell_powershell -local skip = helpers.skip -local is_os = helpers.is_os +local t = require('test.functional.testutil')(after_each) +local tt = require('test.functional.terminal.testutil') + +local assert_alive = t.assert_alive +local mkdir, write_file, rmdir = t.mkdir, t.write_file, t.rmdir +local eq = t.eq +local feed = t.feed +local feed_command = t.feed_command +local clear = t.clear +local command = t.command +local testprg = t.testprg +local nvim_dir = t.nvim_dir +local has_powershell = t.has_powershell +local set_shell_powershell = t.set_shell_powershell +local skip = t.skip +local is_os = t.is_os clear() -- for has_powershell() @@ -21,7 +22,7 @@ describe('shell command :!', function() local screen before_each(function() clear() - screen = child_session.setup_child_nvim({ + screen = tt.setup_child_nvim({ '-u', 'NONE', '-i', @@ -29,7 +30,7 @@ describe('shell command :!', function() '--cmd', 'colorscheme vim', '--cmd', - helpers.nvim_set .. ' notermguicolors', + t.nvim_set .. ' notermguicolors', }) screen:expect([[ {1: } | @@ -40,14 +41,14 @@ describe('shell command :!', function() end) after_each(function() - child_session.feed_data('\3') -- Ctrl-C + tt.feed_data('\3') -- Ctrl-C end) it('displays output without LF/EOF. #4646 #4569 #3772', function() skip(is_os('win')) -- NOTE: We use a child nvim (within a :term buffer) -- to avoid triggering a UI flush. - child_session.feed_data(':!printf foo; sleep 200\n') + tt.feed_data(':!printf foo; sleep 200\n') screen:expect([[ | {4:~ }|*2 @@ -61,7 +62,7 @@ describe('shell command :!', function() it('throttles shell-command output greater than ~10KB', function() skip(is_os('openbsd'), 'FIXME #10804') skip(is_os('win')) - child_session.feed_data((':!%s REP 30001 foo\n'):format(testprg('shell-test'))) + tt.feed_data((':!%s REP 30001 foo\n'):format(testprg('shell-test'))) -- If we observe any line starting with a dot, then throttling occurred. -- Avoid false failure on slow systems. @@ -80,7 +81,7 @@ describe('shell command :!', function() {3:-- TERMINAL --} | ]], { - -- test/functional/helpers.lua defaults to background=light. + -- test/functional/t.lua defaults to background=light. [1] = { reverse = true }, [3] = { bold = true }, [10] = { foreground = 2 }, diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua @@ -1,17 +1,17 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local assert_alive = helpers.assert_alive -local clear, feed = helpers.clear, helpers.feed -local source = helpers.source -local insert = helpers.insert -local api = helpers.api -local async_meths = helpers.async_meths -local command = helpers.command -local fn = helpers.fn -local eq = helpers.eq -local pcall_err = helpers.pcall_err -local exec_lua = helpers.exec_lua -local exec = helpers.exec +local assert_alive = t.assert_alive +local clear, feed = t.clear, t.feed +local source = t.source +local insert = t.insert +local api = t.api +local async_meths = t.async_meths +local command = t.command +local fn = t.fn +local eq = t.eq +local pcall_err = t.pcall_err +local exec_lua = t.exec_lua +local exec = t.exec describe('ui/ext_popupmenu', function() local screen diff --git a/test/functional/ui/quickfix_spec.lua b/test/functional/ui/quickfix_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, api = helpers.clear, helpers.feed, helpers.api -local insert, command = helpers.insert, helpers.command +local clear, feed, api = t.clear, t.feed, t.api +local insert, command = t.insert, t.command describe('quickfix selection highlight', function() local screen diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua @@ -70,17 +70,17 @@ -- To help write screen tests, see Screen:snapshot_util(). -- To debug screen tests, see Screen:redraw_debug(). -local helpers = require('test.functional.helpers')(nil) +local t = require('test.functional.testutil')(nil) local busted = require('busted') local deepcopy = vim.deepcopy -local shallowcopy = helpers.shallowcopy -local concat_tables = helpers.concat_tables +local shallowcopy = t.shallowcopy +local concat_tables = t.concat_tables local pesc = vim.pesc -local run_session = helpers.run_session -local eq = helpers.eq -local dedent = helpers.dedent -local get_session = helpers.get_session -local create_callindex = helpers.create_callindex +local run_session = t.run_session +local eq = t.eq +local dedent = t.dedent +local get_session = t.get_session +local create_callindex = t.create_callindex local inspect = vim.inspect diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local spawn, set_session, clear = helpers.spawn, helpers.set_session, helpers.clear -local feed, command = helpers.feed, helpers.command -local insert = helpers.insert -local eq = helpers.eq -local fn, api = helpers.fn, helpers.api +local spawn, set_session, clear = t.spawn, t.set_session, t.clear +local feed, command = t.feed, t.command +local insert = t.insert +local eq = t.eq +local fn, api = t.fn, t.api describe('screen', function() local screen local nvim_argv = { - helpers.nvim_prog, + t.nvim_prog, '-u', 'NONE', '-i', @@ -700,7 +700,7 @@ describe('Screen default colors', function() local extra = (light and ' background=light') or '' local nvim_argv = { - helpers.nvim_prog, + t.nvim_prog, '-u', 'NONE', '-i', diff --git a/test/functional/ui/searchhl_spec.lua b/test/functional/ui/searchhl_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local command = helpers.command -local feed_command = helpers.feed_command -local eq = helpers.eq -local eval = helpers.eval -local fn = helpers.fn -local testprg = helpers.testprg +local clear, feed, insert = t.clear, t.feed, t.insert +local command = t.command +local feed_command = t.feed_command +local eq = t.eq +local eval = t.eval +local fn = t.fn +local testprg = t.testprg describe('search highlighting', function() local screen diff --git a/test/functional/ui/sign_spec.lua b/test/functional/ui/sign_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local api, clear, eq = helpers.api, helpers.clear, helpers.eq -local eval, exec, feed = helpers.eval, helpers.exec, helpers.feed +local api, clear, eq = t.api, t.clear, t.eq +local eval, exec, feed = t.eval, t.exec, t.feed describe('Signs', function() local screen diff --git a/test/functional/ui/spell_spec.lua b/test/functional/ui/spell_spec.lua @@ -1,13 +1,13 @@ -- Test for scenarios involving 'spell' -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local exec = helpers.exec -local feed = helpers.feed -local insert = helpers.insert -local api = helpers.api -local is_os = helpers.is_os +local clear = t.clear +local exec = t.exec +local feed = t.feed +local insert = t.insert +local api = t.api +local is_os = t.is_os describe("'spell'", function() local screen diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local exec = helpers.exec -local eval = helpers.eval -local exec_lua = helpers.exec_lua -local feed = helpers.feed -local api = helpers.api -local pcall_err = helpers.pcall_err -local assert_alive = helpers.assert_alive +local clear = t.clear +local command = t.command +local eq = t.eq +local exec = t.exec +local eval = t.eval +local exec_lua = t.exec_lua +local feed = t.feed +local api = t.api +local pcall_err = t.pcall_err +local assert_alive = t.assert_alive local mousemodels = { 'extend', 'popup', 'popup_setpos' } diff --git a/test/functional/ui/statusline_spec.lua b/test/functional/ui/statusline_spec.lua @@ -1,17 +1,17 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local assert_alive = helpers.assert_alive -local clear = helpers.clear -local command = helpers.command -local feed = helpers.feed -local eq = helpers.eq -local fn = helpers.fn -local api = helpers.api -local exec = helpers.exec -local exec_lua = helpers.exec_lua -local eval = helpers.eval +local assert_alive = t.assert_alive +local clear = t.clear +local command = t.command +local feed = t.feed +local eq = t.eq +local fn = t.fn +local api = t.api +local exec = t.exec +local exec_lua = t.exec_lua +local eval = t.eval local sleep = vim.uv.sleep -local pcall_err = helpers.pcall_err +local pcall_err = t.pcall_err local mousemodels = { 'extend', 'popup', 'popup_setpos' } diff --git a/test/functional/ui/syntax_conceal_spec.lua b/test/functional/ui/syntax_conceal_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, command = helpers.clear, helpers.feed, helpers.command -local eq = helpers.eq -local insert = helpers.insert -local poke_eventloop = helpers.poke_eventloop -local exec = helpers.exec +local clear, feed, command = t.clear, t.feed, t.command +local eq = t.eq +local insert = t.insert +local poke_eventloop = t.poke_eventloop +local exec = t.exec describe('Screen', function() local screen diff --git a/test/functional/ui/tabline_spec.lua b/test/functional/ui/tabline_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, command, eq = helpers.clear, helpers.command, helpers.eq -local insert = helpers.insert -local api = helpers.api -local assert_alive = helpers.assert_alive +local clear, command, eq = t.clear, t.command, t.eq +local insert = t.insert +local api = t.api +local assert_alive = t.assert_alive describe('ui/ext_tabline', function() local screen diff --git a/test/functional/ui/title_spec.lua b/test/functional/ui/title_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local curwin = helpers.api.nvim_get_current_win -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local feed = helpers.feed -local fn = helpers.fn -local api = helpers.api -local is_os = helpers.is_os +local clear = t.clear +local command = t.command +local curwin = t.api.nvim_get_current_win +local eq = t.eq +local exec_lua = t.exec_lua +local feed = t.feed +local fn = t.fn +local api = t.api +local is_os = t.is_os describe('title', function() local screen diff --git a/test/functional/ui/wildmode_spec.lua b/test/functional/ui/wildmode_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, command = helpers.clear, helpers.feed, helpers.command -local fn = helpers.fn -local api = helpers.api -local eq = helpers.eq -local eval = helpers.eval -local retry = helpers.retry -local testprg = helpers.testprg -local is_os = helpers.is_os +local clear, feed, command = t.clear, t.feed, t.command +local fn = t.fn +local api = t.api +local eq = t.eq +local eval = t.eval +local retry = t.retry +local testprg = t.testprg +local is_os = t.is_os describe("'wildmenu'", function() local screen diff --git a/test/functional/ui/winbar_spec.lua b/test/functional/ui/winbar_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local insert = helpers.insert -local api = helpers.api -local eq = helpers.eq -local poke_eventloop = helpers.poke_eventloop -local feed = helpers.feed -local fn = helpers.fn -local pcall_err = helpers.pcall_err +local clear = t.clear +local command = t.command +local insert = t.insert +local api = t.api +local eq = t.eq +local poke_eventloop = t.poke_eventloop +local feed = t.feed +local fn = t.fn +local pcall_err = t.pcall_err describe('winbar', function() local screen diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local neq, eq, command = helpers.neq, helpers.eq, helpers.command -local clear = helpers.clear -local exc_exec, expect, eval = helpers.exc_exec, helpers.expect, helpers.eval -local exec_lua = helpers.exec_lua -local insert, pcall_err = helpers.insert, helpers.pcall_err -local matches = helpers.matches -local api = helpers.api -local feed = helpers.feed +local neq, eq, command = t.neq, t.eq, t.command +local clear = t.clear +local exc_exec, expect, eval = t.exc_exec, t.expect, t.eval +local exec_lua = t.exec_lua +local insert, pcall_err = t.insert, t.pcall_err +local matches = t.matches +local api = t.api +local feed = t.feed describe('eval-API', function() before_each(clear) diff --git a/test/functional/vimscript/buf_functions_spec.lua b/test/functional/vimscript/buf_functions_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local clear = helpers.clear -local fn = helpers.fn -local api = helpers.api -local command = helpers.command -local exc_exec = helpers.exc_exec -local get_pathsep = helpers.get_pathsep -local rmdir = helpers.rmdir -local pcall_err = helpers.pcall_err -local mkdir = helpers.mkdir +local eq = t.eq +local clear = t.clear +local fn = t.fn +local api = t.api +local command = t.command +local exc_exec = t.exc_exec +local get_pathsep = t.get_pathsep +local rmdir = t.rmdir +local pcall_err = t.pcall_err +local mkdir = t.mkdir local fname = 'Xtest-functional-eval-buf_functions' local fname2 = fname .. '.2' diff --git a/test/functional/vimscript/changedtick_spec.lua b/test/functional/vimscript/changedtick_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local eval = helpers.eval -local feed = helpers.feed -local clear = helpers.clear -local fn = helpers.fn -local api = helpers.api -local command = helpers.command -local exc_exec = helpers.exc_exec -local pcall_err = helpers.pcall_err -local exec_capture = helpers.exec_capture +local eq = t.eq +local eval = t.eval +local feed = t.feed +local clear = t.clear +local fn = t.fn +local api = t.api +local command = t.command +local exc_exec = t.exc_exec +local pcall_err = t.pcall_err +local exec_capture = t.exec_capture before_each(clear) diff --git a/test/functional/vimscript/container_functions_spec.lua b/test/functional/vimscript/container_functions_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local eval = helpers.eval -local api = helpers.api -local clear = helpers.clear +local eq = t.eq +local eval = t.eval +local api = t.api +local clear = t.clear before_each(clear) diff --git a/test/functional/vimscript/ctx_functions_spec.lua b/test/functional/vimscript/ctx_functions_spec.lua @@ -1,19 +1,19 @@ -local helpers = require('test.functional.helpers')(after_each) - -local call = helpers.call -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval -local feed = helpers.feed +local t = require('test.functional.testutil')(after_each) + +local call = t.call +local clear = t.clear +local command = t.command +local eq = t.eq +local eval = t.eval +local feed = t.feed local map = vim.tbl_map -local api = helpers.api -local parse_context = helpers.parse_context -local exec_capture = helpers.exec_capture -local source = helpers.source +local api = t.api +local parse_context = t.parse_context +local exec_capture = t.exec_capture +local source = t.source local trim = vim.trim -local write_file = helpers.write_file -local pcall_err = helpers.pcall_err +local write_file = t.write_file +local pcall_err = t.pcall_err describe('context functions', function() local fname1 = 'Xtest-functional-eval-ctx1' diff --git a/test/functional/vimscript/environ_spec.lua b/test/functional/vimscript/environ_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local environ = helpers.fn.environ -local exists = helpers.fn.exists -local system = helpers.fn.system -local nvim_prog = helpers.nvim_prog -local command = helpers.command -local eval = helpers.eval -local setenv = helpers.fn.setenv +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eq = t.eq +local environ = t.fn.environ +local exists = t.fn.exists +local system = t.fn.system +local nvim_prog = t.nvim_prog +local command = t.command +local eval = t.eval +local setenv = t.fn.setenv describe('environment variables', function() it('environ() handles empty env variable', function() diff --git a/test/functional/vimscript/errorlist_spec.lua b/test/functional/vimscript/errorlist_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local exc_exec = helpers.exc_exec -local get_win_var = helpers.api.nvim_win_get_var +local clear = t.clear +local command = t.command +local eq = t.eq +local exc_exec = t.exc_exec +local get_win_var = t.api.nvim_win_get_var describe('setqflist()', function() - local setqflist = helpers.fn.setqflist + local setqflist = t.fn.setqflist before_each(clear) @@ -46,7 +46,7 @@ describe('setqflist()', function() end) describe('setloclist()', function() - local setloclist = helpers.fn.setloclist + local setloclist = t.fn.setloclist before_each(clear) @@ -73,7 +73,7 @@ describe('setloclist()', function() end) it("doesn't crash when when window is closed in the middle #13721", function() - helpers.insert([[ + t.insert([[ hello world]]) command('vsplit') @@ -82,6 +82,6 @@ describe('setloclist()', function() command('call setloclist(0, [])') command('lopen') - helpers.assert_alive() + t.assert_alive() end) end) diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua @@ -9,37 +9,37 @@ -- test/functional/vimscript/<funcname>_spec.lua -- test/functional/vimscript/functions_spec.lua -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local mkdir = helpers.mkdir -local clear = helpers.clear -local eq = helpers.eq -local exec = helpers.exec -local exc_exec = helpers.exc_exec -local exec_lua = helpers.exec_lua -local exec_capture = helpers.exec_capture -local eval = helpers.eval -local command = helpers.command -local write_file = helpers.write_file -local api = helpers.api +local mkdir = t.mkdir +local clear = t.clear +local eq = t.eq +local exec = t.exec +local exc_exec = t.exc_exec +local exec_lua = t.exec_lua +local exec_capture = t.exec_capture +local eval = t.eval +local command = t.command +local write_file = t.write_file +local api = t.api local sleep = vim.uv.sleep -local matches = helpers.matches -local pcall_err = helpers.pcall_err -local assert_alive = helpers.assert_alive -local poke_eventloop = helpers.poke_eventloop -local feed = helpers.feed -local expect_exit = helpers.expect_exit +local matches = t.matches +local pcall_err = t.pcall_err +local assert_alive = t.assert_alive +local poke_eventloop = t.poke_eventloop +local feed = t.feed +local expect_exit = t.expect_exit describe('Up to MAX_FUNC_ARGS arguments are handled by', function() local max_func_args = 20 -- from eval.h - local range = helpers.fn.range + local range = t.fn.range before_each(clear) it('printf()', function() - local printf = helpers.fn.printf - local rep = helpers.fn['repeat'] + local printf = t.fn.printf + local rep = t.fn['repeat'] local expected = '2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,' eq(expected, printf(rep('%d,', max_func_args - 1), unpack(range(2, max_func_args)))) local ret = exc_exec('call printf("", 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)') @@ -47,7 +47,7 @@ describe('Up to MAX_FUNC_ARGS arguments are handled by', function() end) it('rpcnotify()', function() - local rpcnotify = helpers.fn.rpcnotify + local rpcnotify = t.fn.rpcnotify local ret = rpcnotify(0, 'foo', unpack(range(3, max_func_args))) eq(1, ret) ret = exc_exec('call rpcnotify(0, "foo", 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)') @@ -69,17 +69,17 @@ describe('backtick expansion', function() end) teardown(function() - helpers.rmdir('test-backticks') + t.rmdir('test-backticks') end) it("with default 'shell'", function() - if helpers.is_os('win') then + if t.is_os('win') then command(':silent args `dir /b *2`') else command(':silent args `echo ***2`') end eq({ 'file2' }, eval('argv()')) - if helpers.is_os('win') then + if t.is_os('win') then command(':silent args `dir /s/b *4`') eq({ 'subdir\\file4' }, eval('map(argv(), \'fnamemodify(v:val, ":.")\')')) else diff --git a/test/functional/vimscript/executable_spec.lua b/test/functional/vimscript/executable_spec.lua @@ -1,9 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq, clear, call, write_file, command = - helpers.eq, helpers.clear, helpers.call, helpers.write_file, helpers.command -local exc_exec = helpers.exc_exec -local eval = helpers.eval -local is_os = helpers.is_os +local t = require('test.functional.testutil')(after_each) +local eq, clear, call, write_file, command = t.eq, t.clear, t.call, t.write_file, t.command +local exc_exec = t.exc_exec +local eval = t.eval +local is_os = t.is_os describe('executable()', function() before_each(clear) diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq = helpers.eq -local eval = helpers.eval -local clear = helpers.clear -local source = helpers.source -local exc_exec = helpers.exc_exec -local pcall_err = helpers.pcall_err -local fn = helpers.fn +local t = require('test.functional.testutil')(after_each) +local eq = t.eq +local eval = t.eval +local clear = t.clear +local source = t.source +local exc_exec = t.exc_exec +local pcall_err = t.pcall_err +local fn = t.fn local Screen = require('test.functional.ui.screen') -local command = helpers.command -local feed = helpers.feed -local is_os = helpers.is_os +local command = t.command +local feed = t.feed +local is_os = t.is_os describe('execute()', function() before_each(clear) diff --git a/test/functional/vimscript/exepath_spec.lua b/test/functional/vimscript/exepath_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq, clear, call = helpers.eq, helpers.clear, helpers.call -local command = helpers.command -local exc_exec = helpers.exc_exec -local matches = helpers.matches -local is_os = helpers.is_os -local set_shell_powershell = helpers.set_shell_powershell -local eval = helpers.eval +local t = require('test.functional.testutil')(after_each) +local eq, clear, call = t.eq, t.clear, t.call +local command = t.command +local exc_exec = t.exc_exec +local matches = t.matches +local is_os = t.is_os +local set_shell_powershell = t.set_shell_powershell +local eval = t.eval local find_dummies = function(ext_pat) local tmp_path = eval('$PATH') diff --git a/test/functional/vimscript/fnamemodify_spec.lua b/test/functional/vimscript/fnamemodify_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local fnamemodify = helpers.fn.fnamemodify -local getcwd = helpers.fn.getcwd -local command = helpers.command -local write_file = helpers.write_file -local alter_slashes = helpers.alter_slashes -local is_os = helpers.is_os +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eq = t.eq +local fnamemodify = t.fn.fnamemodify +local getcwd = t.fn.getcwd +local command = t.command +local write_file = t.write_file +local alter_slashes = t.alter_slashes +local is_os = t.is_os local function eq_slashconvert(expected, got) eq(alter_slashes(expected), alter_slashes(got)) @@ -24,7 +24,7 @@ describe('fnamemodify()', function() end) it('handles the root path', function() - local root = helpers.pathroot() + local root = t.pathroot() eq(root, fnamemodify([[/]], ':p:h')) eq(root, fnamemodify([[/]], ':p')) if is_os('win') then diff --git a/test/functional/vimscript/functions_spec.lua b/test/functional/vimscript/functions_spec.lua @@ -5,12 +5,12 @@ -- -- Core "eval" tests live in eval_spec.lua. -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local eval = helpers.eval -local matches = helpers.matches -local is_os = helpers.is_os +local clear = t.clear +local eval = t.eval +local matches = t.matches +local is_os = t.is_os before_each(clear) diff --git a/test/functional/vimscript/getline_spec.lua b/test/functional/vimscript/getline_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local call = helpers.call -local clear = helpers.clear -local eq = helpers.eq -local expect = helpers.expect +local call = t.call +local clear = t.clear +local eq = t.eq +local expect = t.expect describe('getline()', function() before_each(function() diff --git a/test/functional/vimscript/glob_spec.lua b/test/functional/vimscript/glob_spec.lua @@ -1,6 +1,6 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, command, eval, eq = helpers.clear, helpers.command, helpers.eval, helpers.eq -local mkdir = helpers.mkdir +local t = require('test.functional.testutil')(after_each) +local clear, command, eval, eq = t.clear, t.command, t.eval, t.eq +local mkdir = t.mkdir before_each(function() clear() diff --git a/test/functional/vimscript/has_spec.lua b/test/functional/vimscript/has_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local connect = helpers.connect -local eq = helpers.eq -local fn = helpers.fn -local is_os = helpers.is_os -local nvim_prog = helpers.nvim_prog +local clear = t.clear +local connect = t.connect +local eq = t.eq +local fn = t.fn +local is_os = t.is_os +local nvim_prog = t.nvim_prog describe('has()', function() before_each(clear) diff --git a/test/functional/vimscript/hostname_spec.lua b/test/functional/vimscript/hostname_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq = helpers.eq -local ok = helpers.ok -local call = helpers.call -local clear = helpers.clear -local is_os = helpers.is_os +local t = require('test.functional.testutil')(after_each) +local eq = t.eq +local ok = t.ok +local call = t.call +local clear = t.clear +local is_os = t.is_os describe('hostname()', function() before_each(clear) diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local eq = helpers.eq -local feed = helpers.feed -local api = helpers.api -local clear = helpers.clear -local source = helpers.source -local command = helpers.command -local exc_exec = helpers.exc_exec -local async_meths = helpers.async_meths +local eq = t.eq +local feed = t.feed +local api = t.api +local clear = t.clear +local source = t.source +local command = t.command +local exc_exec = t.exc_exec +local async_meths = t.async_meths local NIL = vim.NIL local screen diff --git a/test/functional/vimscript/json_functions_spec.lua b/test/functional/vimscript/json_functions_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local fn = helpers.fn -local api = helpers.api -local eq = helpers.eq -local eval = helpers.eval -local command = helpers.command -local exc_exec = helpers.exc_exec -local pcall_err = helpers.pcall_err +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local fn = t.fn +local api = t.api +local eq = t.eq +local eval = t.eval +local command = t.command +local exc_exec = t.exc_exec +local pcall_err = t.pcall_err local NIL = vim.NIL -local source = helpers.source +local source = t.source describe('json_decode() function', function() local restart = function(...) diff --git a/test/functional/vimscript/lang_spec.lua b/test/functional/vimscript/lang_spec.lua @@ -1,6 +1,6 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq -local exc_exec, source = helpers.exc_exec, helpers.source +local t = require('test.functional.testutil')(after_each) +local clear, eval, eq = t.clear, t.eval, t.eq +local exc_exec, source = t.exc_exec, t.source describe('vimscript', function() before_each(clear) diff --git a/test/functional/vimscript/let_spec.lua b/test/functional/vimscript/let_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local clear = helpers.clear -local command = helpers.command -local eval = helpers.eval -local api = helpers.api -local exec = helpers.exec -local exec_capture = helpers.exec_capture -local expect_exit = helpers.expect_exit -local source = helpers.source -local testprg = helpers.testprg +local eq = t.eq +local clear = t.clear +local command = t.command +local eval = t.eval +local api = t.api +local exec = t.exec +local exec_capture = t.exec_capture +local expect_exit = t.expect_exit +local source = t.source +local testprg = t.testprg before_each(clear) diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua @@ -1,18 +1,18 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local eq = helpers.eq -local eval = helpers.eval -local exec = helpers.exec -local exec_lua = helpers.exec_lua -local expect = helpers.expect -local feed = helpers.feed -local fn = helpers.fn -local api = helpers.api -local source = helpers.source -local command = helpers.command -local exec_capture = helpers.exec_capture -local pcall_err = helpers.pcall_err +local t = require('test.functional.testutil')(after_each) + +local clear = t.clear +local eq = t.eq +local eval = t.eval +local exec = t.exec +local exec_lua = t.exec_lua +local expect = t.expect +local feed = t.feed +local fn = t.fn +local api = t.api +local source = t.source +local command = t.command +local exec_capture = t.exec_capture +local pcall_err = t.pcall_err describe('maparg()', function() before_each(clear) diff --git a/test/functional/vimscript/match_functions_spec.lua b/test/functional/vimscript/match_functions_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local eq = helpers.eq -local clear = helpers.clear -local fn = helpers.fn -local command = helpers.command -local exc_exec = helpers.exc_exec +local eq = t.eq +local clear = t.clear +local fn = t.fn +local command = t.command +local exc_exec = t.exc_exec before_each(clear) diff --git a/test/functional/vimscript/minmax_functions_spec.lua b/test/functional/vimscript/minmax_functions_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local eval = helpers.eval -local command = helpers.command -local clear = helpers.clear -local fn = helpers.fn -local pcall_err = helpers.pcall_err +local eq = t.eq +local eval = t.eval +local command = t.command +local clear = t.clear +local fn = t.fn +local pcall_err = t.pcall_err before_each(clear) for _, func in ipairs({ 'min', 'max' }) do diff --git a/test/functional/vimscript/modeline_spec.lua b/test/functional/vimscript/modeline_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) -local assert_alive = helpers.assert_alive -local clear, command, write_file = helpers.clear, helpers.command, helpers.write_file +local t = require('test.functional.testutil')(after_each) +local assert_alive = t.assert_alive +local clear, command, write_file = t.clear, t.command, t.write_file describe('modeline', function() - local tempfile = helpers.tmpname() + local tempfile = t.tmpname() before_each(clear) after_each(function() diff --git a/test/functional/vimscript/msgpack_functions_spec.lua b/test/functional/vimscript/msgpack_functions_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local fn = helpers.fn -local eval, eq = helpers.eval, helpers.eq -local command = helpers.command -local api = helpers.api -local exc_exec = helpers.exc_exec -local is_os = helpers.is_os +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local fn = t.fn +local eval, eq = t.eval, t.eq +local command = t.command +local api = t.api +local exc_exec = t.exc_exec +local is_os = t.is_os describe('msgpack*() functions', function() before_each(clear) @@ -469,12 +469,12 @@ describe('msgpackparse() function', function() end) it('msgpackparse(systemlist(...)) does not segfault. #3135', function() - local cmd = "sort(keys(msgpackparse(systemlist('" .. helpers.nvim_prog .. " --api-info'))[0]))" + local cmd = "sort(keys(msgpackparse(systemlist('" .. t.nvim_prog .. " --api-info'))[0]))" eval(cmd) eval(cmd) -- do it again (try to force segfault) local api_info = eval(cmd) -- do it again if is_os('win') then - helpers.assert_alive() + t.assert_alive() pending('msgpackparse() has a bug on windows') return end diff --git a/test/functional/vimscript/null_spec.lua b/test/functional/vimscript/null_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local exc_exec = helpers.exc_exec -local command = helpers.command -local clear = helpers.clear -local api = helpers.api -local fn = helpers.fn -local eq = helpers.eq +local exc_exec = t.exc_exec +local command = t.command +local clear = t.clear +local api = t.api +local fn = t.fn +local eq = t.eq local function redir_exec(cmd) api.nvim_set_var('__redir_exec_cmd', cmd) diff --git a/test/functional/vimscript/operators_spec.lua b/test/functional/vimscript/operators_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq = helpers.eq -local eval = helpers.eval -local clear = helpers.clear +local t = require('test.functional.testutil')(after_each) +local eq = t.eq +local eval = t.eval +local clear = t.clear describe('Division operator', function() before_each(clear) diff --git a/test/functional/vimscript/printf_spec.lua b/test/functional/vimscript/printf_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local eval = helpers.eval -local fn = helpers.fn -local api = helpers.api -local exc_exec = helpers.exc_exec +local clear = t.clear +local eq = t.eq +local eval = t.eval +local fn = t.fn +local api = t.api +local exc_exec = t.exc_exec describe('printf()', function() before_each(clear) diff --git a/test/functional/vimscript/reltime_spec.lua b/test/functional/vimscript/reltime_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, eq, ok = helpers.clear, helpers.eq, helpers.ok -local neq, command, fn = helpers.neq, helpers.command, helpers.fn -local matches = helpers.matches +local t = require('test.functional.testutil')(after_each) +local clear, eq, ok = t.clear, t.eq, t.ok +local neq, command, fn = t.neq, t.command, t.fn +local matches = t.matches local reltime, reltimestr, reltimefloat = fn.reltime, fn.reltimestr, fn.reltimefloat describe('reltimestr(), reltimefloat()', function() diff --git a/test/functional/vimscript/screenchar_spec.lua b/test/functional/vimscript/screenchar_spec.lua @@ -1,6 +1,6 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, eq, neq = helpers.clear, helpers.eq, helpers.neq -local command, api, fn = helpers.command, helpers.api, helpers.fn +local t = require('test.functional.testutil')(after_each) +local clear, eq, neq = t.clear, t.eq, t.neq +local command, api, fn = t.command, t.api, t.fn local tbl_deep_extend = vim.tbl_deep_extend -- Set up two overlapping floating windows diff --git a/test/functional/vimscript/screenpos_spec.lua b/test/functional/vimscript/screenpos_spec.lua @@ -1,7 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, eq, api = helpers.clear, helpers.eq, helpers.api -local command, fn = helpers.command, helpers.fn -local feed = helpers.feed +local t = require('test.functional.testutil')(after_each) +local clear, eq, api = t.clear, t.eq, t.api +local command, fn = t.command, t.fn +local feed = t.feed before_each(clear) diff --git a/test/functional/vimscript/server_spec.lua b/test/functional/vimscript/server_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) -local assert_log = helpers.assert_log -local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval -local clear, fn, api = helpers.clear, helpers.fn, helpers.api -local ok = helpers.ok -local matches = helpers.matches -local pcall_err = helpers.pcall_err -local check_close = helpers.check_close -local mkdir = helpers.mkdir -local rmdir = helpers.rmdir -local is_os = helpers.is_os +local t = require('test.functional.testutil')(after_each) +local assert_log = t.assert_log +local eq, neq, eval = t.eq, t.neq, t.eval +local clear, fn, api = t.clear, t.fn, t.api +local ok = t.ok +local matches = t.matches +local pcall_err = t.pcall_err +local check_close = t.check_close +local mkdir = t.mkdir +local rmdir = t.rmdir +local is_os = t.is_os local testlog = 'Xtest-server-log' @@ -176,11 +176,11 @@ end) describe('startup --listen', function() it('validates', function() clear() - local cmd = { unpack(helpers.nvim_argv) } + local cmd = { unpack(t.nvim_argv) } table.insert(cmd, '--listen') matches('nvim.*: Argument missing after: "%-%-listen"', fn.system(cmd)) - cmd = { unpack(helpers.nvim_argv) } + cmd = { unpack(t.nvim_argv) } table.insert(cmd, '--listen2') matches('nvim.*: Garbage after option argument: "%-%-listen2"', fn.system(cmd)) end) diff --git a/test/functional/vimscript/setpos_spec.lua b/test/functional/vimscript/setpos_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) -local setpos = helpers.fn.setpos -local getpos = helpers.fn.getpos -local insert = helpers.insert -local clear = helpers.clear -local command = helpers.command -local eval = helpers.eval -local eq = helpers.eq -local exc_exec = helpers.exc_exec +local t = require('test.functional.testutil')(after_each) +local setpos = t.fn.setpos +local getpos = t.fn.getpos +local insert = t.insert +local clear = t.clear +local command = t.command +local eval = t.eval +local eq = t.eq +local exc_exec = t.exc_exec describe('setpos() function', function() before_each(function() diff --git a/test/functional/vimscript/sort_spec.lua b/test/functional/vimscript/sort_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq +local eq = t.eq local NIL = vim.NIL -local eval = helpers.eval -local clear = helpers.clear -local api = helpers.api -local fn = helpers.fn -local command = helpers.command -local exc_exec = helpers.exc_exec -local pcall_err = helpers.pcall_err +local eval = t.eval +local clear = t.clear +local api = t.api +local fn = t.fn +local command = t.command +local exc_exec = t.exc_exec +local pcall_err = t.pcall_err before_each(clear) diff --git a/test/functional/vimscript/special_vars_spec.lua b/test/functional/vimscript/special_vars_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local exc_exec = helpers.exc_exec -local command = helpers.command -local fn = helpers.fn -local clear = helpers.clear -local eval = helpers.eval -local eq = helpers.eq -local api = helpers.api +local t = require('test.functional.testutil')(after_each) +local exc_exec = t.exc_exec +local command = t.command +local fn = t.fn +local clear = t.clear +local eval = t.eval +local eq = t.eq +local api = t.api local NIL = vim.NIL describe('Special values', function() diff --git a/test/functional/vimscript/state_spec.lua b/test/functional/vimscript/state_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local exec = helpers.exec -local exec_lua = helpers.exec_lua -local feed = helpers.feed -local api = helpers.api -local poke_eventloop = helpers.poke_eventloop +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eq = t.eq +local exec = t.exec +local exec_lua = t.exec_lua +local feed = t.feed +local api = t.api +local poke_eventloop = t.poke_eventloop before_each(clear) diff --git a/test/functional/vimscript/string_spec.lua b/test/functional/vimscript/string_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local command = helpers.command -local api = helpers.api -local eval = helpers.eval -local exc_exec = helpers.exc_exec -local pcall_err = helpers.pcall_err -local fn = helpers.fn +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local eq = t.eq +local command = t.command +local api = t.api +local eval = t.eval +local exc_exec = t.exc_exec +local pcall_err = t.pcall_err +local fn = t.fn local NIL = vim.NIL -local source = helpers.source +local source = t.source describe('string() function', function() before_each(clear) @@ -190,7 +190,7 @@ describe('string() function', function() eval('add(l, l)') -- Regression: the below line used to crash (add returns original list and -- there was error in dumping partials). Tested explicitly in - -- test/unit/api/private_helpers_spec.lua. + -- test/unit/api/private_t_spec.lua. eval('add(l, function("Test1", l))') eq( [=[Vim(echo):E724: unable to correctly dump variable with self-referencing container]=], diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua @@ -1,24 +1,18 @@ -- Tests for system() and :! shell. -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local assert_alive = helpers.assert_alive -local testprg = helpers.testprg +local assert_alive = t.assert_alive +local testprg = t.testprg local eq, call, clear, eval, feed_command, feed, api = - helpers.eq, - helpers.call, - helpers.clear, - helpers.eval, - helpers.feed_command, - helpers.feed, - helpers.api -local command = helpers.command -local insert = helpers.insert -local expect = helpers.expect -local exc_exec = helpers.exc_exec -local os_kill = helpers.os_kill -local pcall_err = helpers.pcall_err -local is_os = helpers.is_os + t.eq, t.call, t.clear, t.eval, t.feed_command, t.feed, t.api +local command = t.command +local insert = t.insert +local expect = t.expect +local exc_exec = t.exc_exec +local os_kill = t.os_kill +local pcall_err = t.pcall_err +local is_os = t.is_os local Screen = require('test.functional.ui.screen') @@ -189,7 +183,7 @@ describe('system()', function() end) it('with powershell', function() - helpers.set_shell_powershell() + t.set_shell_powershell() eq('a\nb\n', eval([[system('Write-Output a b')]])) eq('C:\\\n', eval([[system('cd c:\; (Get-Location).Path')]])) eq('a b\n', eval([[system('Write-Output "a b"')]])) @@ -197,11 +191,11 @@ describe('system()', function() end it('powershell w/ UTF-8 text #13713', function() - if not helpers.has_powershell() then + if not t.has_powershell() then pending('powershell not found', function() end) return end - helpers.set_shell_powershell() + t.set_shell_powershell() eq('ああ\n', eval([[system('Write-Output "ああ"')]])) -- Sanity test w/ default encoding -- * on Windows, expected to default to Western European enc @@ -234,7 +228,7 @@ describe('system()', function() end) it('self and total time recorded separately', function() - local tempfile = helpers.tmpname() + local tempfile = t.tmpname() feed(':function! AlmostNoSelfTime()<cr>') feed('echo system("echo hi")<cr>') @@ -247,11 +241,11 @@ describe('system()', function() feed(':edit ' .. tempfile .. '<cr>') - local command_total_time = tonumber(helpers.fn.split(helpers.fn.getline(7))[2]) - local command_self_time = tonumber(helpers.fn.split(helpers.fn.getline(7))[3]) + local command_total_time = tonumber(t.fn.split(t.fn.getline(7))[2]) + local command_self_time = tonumber(t.fn.split(t.fn.getline(7))[3]) - helpers.neq(nil, command_total_time) - helpers.neq(nil, command_self_time) + t.neq(nil, command_total_time) + t.neq(nil, command_self_time) end) it('`yes` interrupted with CTRL-C', function() @@ -554,11 +548,11 @@ describe('systemlist()', function() end) it('powershell w/ UTF-8 text #13713', function() - if not helpers.has_powershell() then + if not t.has_powershell() then pending('powershell not found', function() end) return end - helpers.set_shell_powershell() + t.set_shell_powershell() eq({ is_os('win') and 'あ\r' or 'あ' }, eval([[systemlist('Write-Output あ')]])) -- Sanity test w/ default encoding -- * on Windows, expected to default to Western European enc @@ -574,7 +568,7 @@ describe('shell :!', function() it(':{range}! with powershell filter/redirect #16271 #19250', function() local screen = Screen.new(500, 8) screen:attach() - local found = helpers.set_shell_powershell(true) + local found = t.set_shell_powershell(true) insert([[ 3 1 @@ -621,12 +615,12 @@ describe('shell :!', function() } end feed('<CR>') - helpers.set_shell_powershell(true) + t.set_shell_powershell(true) feed(':4verbose %w !sort<cr>') screen:expect { any = [[Executing command: .?& { Get%-Content .* | & sort }]], } feed('<CR>') - helpers.expect_exit(command, 'qall!') + t.expect_exit(command, 'qall!') end) end) diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local feed, eq, eval, ok = helpers.feed, helpers.eq, helpers.eval, helpers.ok -local source, async_meths, run = helpers.source, helpers.async_meths, helpers.run -local clear, command, fn = helpers.clear, helpers.command, helpers.fn -local exc_exec = helpers.exc_exec -local api = helpers.api -local load_adjust = helpers.load_adjust -local retry = helpers.retry +local feed, eq, eval, ok = t.feed, t.eq, t.eval, t.ok +local source, async_meths, run = t.source, t.async_meths, t.run +local clear, command, fn = t.clear, t.command, t.fn +local exc_exec = t.exc_exec +local api = t.api +local load_adjust = t.load_adjust +local retry = t.retry describe('timers', function() before_each(function() diff --git a/test/functional/vimscript/uniq_spec.lua b/test/functional/vimscript/uniq_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local clear = helpers.clear -local command = helpers.command -local exc_exec = helpers.exc_exec -local pcall_err = helpers.pcall_err +local eq = t.eq +local clear = t.clear +local command = t.command +local exc_exec = t.exc_exec +local pcall_err = t.pcall_err before_each(clear) diff --git a/test/functional/vimscript/vvar_event_spec.lua b/test/functional/vimscript/vvar_event_spec.lua @@ -1,6 +1,6 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq -local command = helpers.command +local t = require('test.functional.testutil')(after_each) +local clear, eval, eq = t.clear, t.eval, t.eq +local command = t.command describe('v:event', function() before_each(clear) it('is empty before any autocommand', function() diff --git a/test/functional/vimscript/wait_spec.lua b/test/functional/vimscript/wait_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) -local call = helpers.call -local clear = helpers.clear -local command = helpers.command -local eval = helpers.eval -local eq = helpers.eq -local feed = helpers.feed -local feed_command = helpers.feed_command -local next_msg = helpers.next_msg -local api = helpers.api -local source = helpers.source -local pcall_err = helpers.pcall_err +local t = require('test.functional.testutil')(after_each) +local call = t.call +local clear = t.clear +local command = t.command +local eval = t.eval +local eq = t.eq +local feed = t.feed +local feed_command = t.feed_command +local next_msg = t.next_msg +local api = t.api +local source = t.source +local pcall_err = t.pcall_err before_each(function() clear() @@ -60,7 +60,7 @@ describe('wait()', function() ]]) -- XXX: flaky (#11137) - helpers.retry(nil, nil, function() + t.retry(nil, nil, function() api.nvim_set_var('counter', 0) eq(-1, call('wait', 20, 'Count() >= 5', 99999)) end) diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local mkdir = helpers.mkdir -local clear = helpers.clear -local eq = helpers.eq -local fn = helpers.fn -local api = helpers.api -local exc_exec = helpers.exc_exec -local read_file = helpers.read_file -local write_file = helpers.write_file -local pcall_err = helpers.pcall_err -local command = helpers.command +local mkdir = t.mkdir +local clear = t.clear +local eq = t.eq +local fn = t.fn +local api = t.api +local exc_exec = t.exc_exec +local read_file = t.read_file +local write_file = t.write_file +local pcall_err = t.pcall_err +local command = t.command local fname = 'Xtest-functional-eval-writefile' local dname = fname .. '.d' diff --git a/test/helpers.lua b/test/helpers.lua @@ -1,779 +0,0 @@ -local luaassert = require('luassert') -local busted = require('busted') -local uv = vim.uv -local Paths = require('test.cmakeconfig.paths') - -luaassert:set_parameter('TableFormatLevel', 100) - -local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote) - ---- @param str string ---- @return string -local function shell_quote(str) - if string.find(str, quote_me) or str == '' then - return '"' .. str:gsub('[$%%"\\]', '\\%0') .. '"' - end - return str -end - ---- @class test.helpers -local module = { - paths = Paths, -} - ---- @param p string ---- @return string -local function relpath(p) - p = vim.fs.normalize(p) - return (p:gsub('^' .. uv.cwd, '')) -end - ---- @param path string ---- @return boolean -function module.isdir(path) - if not path then - return false - end - local stat = uv.fs_stat(path) - if not stat then - return false - end - return stat.type == 'directory' -end - ---- @param ... string|string[] ---- @return string -function module.argss_to_cmd(...) - local cmd = {} --- @type string[] - for i = 1, select('#', ...) do - local arg = select(i, ...) - if type(arg) == 'string' then - cmd[#cmd + 1] = shell_quote(arg) - else - --- @cast arg string[] - for _, subarg in ipairs(arg) do - cmd[#cmd + 1] = shell_quote(subarg) - end - end - end - return table.concat(cmd, ' ') -end - -function module.popen_r(...) - return io.popen(module.argss_to_cmd(...), 'r') -end - ---- Calls fn() until it succeeds, up to `max` times or until `max_ms` ---- milliseconds have passed. ---- @param max integer? ---- @param max_ms integer? ---- @param fn function ---- @return any -function module.retry(max, max_ms, fn) - luaassert(max == nil or max > 0) - luaassert(max_ms == nil or max_ms > 0) - local tries = 1 - local timeout = (max_ms and max_ms or 10000) - local start_time = uv.now() - while true do - --- @type boolean, any - local status, result = pcall(fn) - if status then - return result - end - uv.update_time() -- Update cached value of luv.now() (libuv: uv_now()). - if (max and tries >= max) or (uv.now() - start_time > timeout) then - busted.fail(string.format('retry() attempts: %d\n%s', tries, tostring(result)), 2) - end - tries = tries + 1 - uv.sleep(20) -- Avoid hot loop... - end -end - -local check_logs_useless_lines = { - ['Warning: noted but unhandled ioctl'] = 1, - ['could cause spurious value errors to appear'] = 2, - ['See README_MISSING_SYSCALL_OR_IOCTL for guidance'] = 3, -} - -function module.eq(expected, actual, context) - return luaassert.are.same(expected, actual, context) -end -function module.neq(expected, actual, context) - return luaassert.are_not.same(expected, actual, context) -end - ---- Asserts that `cond` is true, or prints a message. ---- ---- @param cond (boolean) expression to assert ---- @param expected (any) description of expected result ---- @param actual (any) description of actual result -function module.ok(cond, expected, actual) - luaassert( - (not expected and not actual) or (expected and actual), - 'if "expected" is given, "actual" is also required' - ) - local msg = expected and ('expected %s, got: %s'):format(expected, tostring(actual)) or nil - return luaassert(cond, msg) -end - -local function epicfail(state, arguments, _) - state.failure_message = arguments[1] - return false -end -luaassert:register('assertion', 'epicfail', epicfail) -function module.fail(msg) - return luaassert.epicfail(msg) -end - ---- @param pat string ---- @param actual string ---- @return boolean -function module.matches(pat, actual) - if nil ~= string.match(actual, pat) then - return true - end - error(string.format('Pattern does not match.\nPattern:\n%s\nActual:\n%s', pat, actual)) -end - ---- Asserts that `pat` matches (or *not* if inverse=true) any line in the tail of `logfile`. ---- ---- Retries for 1 second in case of filesystem delay. ---- ----@param pat (string) Lua pattern to match lines in the log file ----@param logfile? (string) Full path to log file (default=$NVIM_LOG_FILE) ----@param nrlines? (number) Search up to this many log lines ----@param inverse? (boolean) Assert that the pattern does NOT match. -function module.assert_log(pat, logfile, nrlines, inverse) - logfile = logfile or os.getenv('NVIM_LOG_FILE') or '.nvimlog' - luaassert(logfile ~= nil, 'no logfile') - nrlines = nrlines or 10 - inverse = inverse or false - - module.retry(nil, 1000, function() - local lines = module.read_file_list(logfile, -nrlines) or {} - local msg = string.format( - 'Pattern %q %sfound in log (last %d lines): %s:\n%s', - pat, - (inverse and '' or 'not '), - nrlines, - logfile, - ' ' .. table.concat(lines, '\n ') - ) - for _, line in ipairs(lines) do - if line:match(pat) then - if inverse then - error(msg) - else - return - end - end - end - if not inverse then - error(msg) - end - end) -end - ---- Asserts that `pat` does NOT match any line in the tail of `logfile`. ---- ---- @see assert_log ---- @param pat (string) Lua pattern to match lines in the log file ---- @param logfile? (string) Full path to log file (default=$NVIM_LOG_FILE) ---- @param nrlines? (number) Search up to this many log lines -function module.assert_nolog(pat, logfile, nrlines) - return module.assert_log(pat, logfile, nrlines, true) -end - ---- @param fn fun(...): any ---- @param ... any ---- @return boolean, any -function module.pcall(fn, ...) - luaassert(type(fn) == 'function') - local status, rv = pcall(fn, ...) - if status then - return status, rv - end - - -- From: - -- C:/long/path/foo.lua:186: Expected string, got number - -- to: - -- .../foo.lua:0: Expected string, got number - local errmsg = tostring(rv) - :gsub('([%s<])vim[/\\]([^%s:/\\]+):%d+', '%1\xffvim\xff%2:0') - :gsub('[^%s<]-[/\\]([^%s:/\\]+):%d+', '.../%1:0') - :gsub('\xffvim\xff', 'vim/') - - -- Scrub numbers in paths/stacktraces: - -- shared.lua:0: in function 'gsplit' - -- shared.lua:0: in function <shared.lua:0>' - errmsg = errmsg:gsub('([^%s].lua):%d+', '%1:0') - -- [string "<nvim>"]:0: - -- [string ":lua"]:0: - -- [string ":luado"]:0: - errmsg = errmsg:gsub('(%[string "[^"]+"%]):%d+', '%1:0') - - -- Scrub tab chars: - errmsg = errmsg:gsub('\t', ' ') - -- In Lua 5.1, we sometimes get a "(tail call): ?" on the last line. - -- We remove this so that the tests are not lua dependent. - errmsg = errmsg:gsub('%s*%(tail call%): %?', '') - - return status, errmsg -end - --- Invokes `fn` and returns the error string (with truncated paths), or raises --- an error if `fn` succeeds. --- --- Replaces line/column numbers with zero: --- shared.lua:0: in function 'gsplit' --- shared.lua:0: in function <shared.lua:0>' --- --- Usage: --- -- Match exact string. --- eq('e', pcall_err(function(a, b) error('e') end, 'arg1', 'arg2')) --- -- Match Lua pattern. --- matches('e[or]+$', pcall_err(function(a, b) error('some error') end, 'arg1', 'arg2')) --- ---- @param fn function ---- @return string -function module.pcall_err_withfile(fn, ...) - luaassert(type(fn) == 'function') - local status, rv = module.pcall(fn, ...) - if status == true then - error('expected failure, but got success') - end - return rv -end - ---- @param fn function ---- @param ... any ---- @return string -function module.pcall_err_withtrace(fn, ...) - local errmsg = module.pcall_err_withfile(fn, ...) - - return ( - errmsg - :gsub('^%.%.%./helpers%.lua:0: ', '') - :gsub('^Error executing lua:- ', '') - :gsub('^%[string "<nvim>"%]:0: ', '') - ) -end - ---- @param fn function ---- @param ... any ---- @return string -function module.pcall_err(fn, ...) - return module.remove_trace(module.pcall_err_withtrace(fn, ...)) -end - ---- @param s string ---- @return string -function module.remove_trace(s) - return (s:gsub('\n%s*stack traceback:.*', '')) -end - --- initial_path: directory to recurse into --- re: include pattern (string) --- exc_re: exclude pattern(s) (string or table) -function module.glob(initial_path, re, exc_re) - exc_re = type(exc_re) == 'table' and exc_re or { exc_re } - local paths_to_check = { initial_path } --- @type string[] - local ret = {} --- @type string[] - local checked_files = {} --- @type table<string,true> - local function is_excluded(path) - for _, pat in pairs(exc_re) do - if path:match(pat) then - return true - end - end - return false - end - - if is_excluded(initial_path) then - return ret - end - while #paths_to_check > 0 do - local cur_path = paths_to_check[#paths_to_check] - paths_to_check[#paths_to_check] = nil - for e in vim.fs.dir(cur_path) do - local full_path = cur_path .. '/' .. e - local checked_path = full_path:sub(#initial_path + 1) - if (not is_excluded(checked_path)) and e:sub(1, 1) ~= '.' then - local stat = uv.fs_stat(full_path) - if stat then - local check_key = stat.dev .. ':' .. tostring(stat.ino) - if not checked_files[check_key] then - checked_files[check_key] = true - if stat.type == 'directory' then - paths_to_check[#paths_to_check + 1] = full_path - elseif not re or checked_path:match(re) then - ret[#ret + 1] = full_path - end - end - end - end - end - end - return ret -end - -function module.check_logs() - local log_dir = os.getenv('LOG_DIR') - local runtime_errors = {} - if log_dir and module.isdir(log_dir) then - for tail in vim.fs.dir(log_dir) do - if tail:sub(1, 30) == 'valgrind-' or tail:find('san%.') then - local file = log_dir .. '/' .. tail - local fd = assert(io.open(file)) - local start_msg = ('='):rep(20) .. ' File ' .. file .. ' ' .. ('='):rep(20) - local lines = {} --- @type string[] - local warning_line = 0 - for line in fd:lines() do - local cur_warning_line = check_logs_useless_lines[line] - if cur_warning_line == warning_line + 1 then - warning_line = cur_warning_line - else - lines[#lines + 1] = line - end - end - fd:close() - if #lines > 0 then - --- @type boolean?, file*? - local status, f - local out = io.stdout - if os.getenv('SYMBOLIZER') then - status, f = pcall(module.popen_r, os.getenv('SYMBOLIZER'), '-l', file) - end - out:write(start_msg .. '\n') - if status then - assert(f) - for line in f:lines() do - out:write('= ' .. line .. '\n') - end - f:close() - else - out:write('= ' .. table.concat(lines, '\n= ') .. '\n') - end - out:write(select(1, start_msg:gsub('.', '=')) .. '\n') - table.insert(runtime_errors, file) - end - os.remove(file) - end - end - end - luaassert( - 0 == #runtime_errors, - string.format('Found runtime errors in logfile(s): %s', table.concat(runtime_errors, ', ')) - ) -end - -function module.sysname() - return uv.os_uname().sysname:lower() -end - ---- @param s 'win'|'mac'|'freebsd'|'openbsd'|'bsd' ---- @return boolean -function module.is_os(s) - if not (s == 'win' or s == 'mac' or s == 'freebsd' or s == 'openbsd' or s == 'bsd') then - error('unknown platform: ' .. tostring(s)) - end - return not not ( - (s == 'win' and (module.sysname():find('windows') or module.sysname():find('mingw'))) - or (s == 'mac' and module.sysname() == 'darwin') - or (s == 'freebsd' and module.sysname() == 'freebsd') - or (s == 'openbsd' and module.sysname() == 'openbsd') - or (s == 'bsd' and module.sysname():find('bsd')) - ) -end - -local function tmpdir_get() - return os.getenv('TMPDIR') and os.getenv('TMPDIR') or os.getenv('TEMP') -end - ---- Is temp directory `dir` defined local to the project workspace? ---- @param dir string? ---- @return boolean -local function tmpdir_is_local(dir) - return not not (dir and dir:find('Xtest')) -end - -local tmpname_id = 0 -local tmpdir = tmpdir_get() - ---- Creates a new temporary file for use by tests. -function module.tmpname() - if tmpdir_is_local(tmpdir) then - -- Cannot control os.tmpname() dir, so hack our own tmpname() impl. - tmpname_id = tmpname_id + 1 - -- "…/Xtest_tmpdir/T42.7" - local fname = ('%s/%s.%d'):format(tmpdir, (_G._nvim_test_id or 'nvim-test'), tmpname_id) - io.open(fname, 'w'):close() - return fname - end - - local fname = os.tmpname() - if module.is_os('win') and fname:sub(1, 2) == '\\s' then - -- In Windows tmpname() returns a filename starting with - -- special sequence \s, prepend $TEMP path - return tmpdir .. fname - elseif module.is_os('mac') and fname:match('^/tmp') then - -- In OS X /tmp links to /private/tmp - return '/private' .. fname - end - - return fname -end - -local function deps_prefix() - local env = os.getenv('DEPS_PREFIX') - return (env and env ~= '') and env or '.deps/usr' -end - -local tests_skipped = 0 - -function module.check_cores(app, force) -- luacheck: ignore - -- Temporary workaround: skip core check as it interferes with CI. - if true then - return - end - app = app or 'build/bin/nvim' -- luacheck: ignore - --- @type string, string?, string[] - local initial_path, re, exc_re - local gdb_db_cmd = - 'gdb -n -batch -ex "thread apply all bt full" "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"' - local lldb_db_cmd = 'lldb -Q -o "bt all" -f "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"' - local random_skip = false - -- Workspace-local $TMPDIR, scrubbed and pattern-escaped. - -- "./Xtest-tmpdir/" => "Xtest%-tmpdir" - local local_tmpdir = ( - tmpdir_is_local(tmpdir_get()) - and relpath(tmpdir_get()):gsub('^[ ./]+', ''):gsub('%/+$', ''):gsub('([^%w])', '%%%1') - or nil - ) - local db_cmd --- @type string - local test_glob_dir = os.getenv('NVIM_TEST_CORE_GLOB_DIRECTORY') - if test_glob_dir and test_glob_dir ~= '' then - initial_path = test_glob_dir - re = os.getenv('NVIM_TEST_CORE_GLOB_RE') - exc_re = { os.getenv('NVIM_TEST_CORE_EXC_RE'), local_tmpdir } - db_cmd = os.getenv('NVIM_TEST_CORE_DB_CMD') or gdb_db_cmd - random_skip = os.getenv('NVIM_TEST_CORE_RANDOM_SKIP') ~= '' - elseif module.is_os('mac') then - initial_path = '/cores' - re = nil - exc_re = { local_tmpdir } - db_cmd = lldb_db_cmd - else - initial_path = '.' - if module.is_os('freebsd') then - re = '/nvim.core$' - else - re = '/core[^/]*$' - end - exc_re = { '^/%.deps$', '^/%' .. deps_prefix() .. '$', local_tmpdir, '^/%node_modules$' } - db_cmd = gdb_db_cmd - random_skip = true - end - -- Finding cores takes too much time on linux - if not force and random_skip and math.random() < 0.9 then - tests_skipped = tests_skipped + 1 - return - end - local cores = module.glob(initial_path, re, exc_re) - local found_cores = 0 - local out = io.stdout - for _, core in ipairs(cores) do - local len = 80 - #core - #'Core file ' - 2 - local esigns = ('='):rep(len / 2) - out:write(('\n%s Core file %s %s\n'):format(esigns, core, esigns)) - out:flush() - os.execute(db_cmd:gsub('%$_NVIM_TEST_APP', app):gsub('%$_NVIM_TEST_CORE', core) .. ' 2>&1') - out:write('\n') - found_cores = found_cores + 1 - os.remove(core) - end - if found_cores ~= 0 then - out:write(('\nTests covered by this check: %u\n'):format(tests_skipped + 1)) - end - tests_skipped = 0 - if found_cores > 0 then - error('crash detected (see above)') - end -end - ---- @return string? -function module.repeated_read_cmd(...) - for _ = 1, 10 do - local stream = module.popen_r(...) - local ret = stream:read('*a') - stream:close() - if ret then - return ret - end - end - print('ERROR: Failed to execute ' .. module.argss_to_cmd(...) .. ': nil return after 10 attempts') - return nil -end - ---- @generic T ---- @param orig T ---- @return T -function module.shallowcopy(orig) - if type(orig) ~= 'table' then - return orig - end - --- @cast orig table<any,any> - local copy = {} --- @type table<any,any> - for orig_key, orig_value in pairs(orig) do - copy[orig_key] = orig_value - end - return copy -end - ---- @param d1 table<any,any> ---- @param d2 table<any,any> ---- @return table<any,any> -function module.mergedicts_copy(d1, d2) - local ret = module.shallowcopy(d1) - for k, v in pairs(d2) do - if d2[k] == vim.NIL then - ret[k] = nil - elseif type(d1[k]) == 'table' and type(v) == 'table' then - ret[k] = module.mergedicts_copy(d1[k], v) - else - ret[k] = v - end - end - return ret -end - ---- dictdiff: find a diff so that mergedicts_copy(d1, diff) is equal to d2 ---- ---- Note: does not do copies of d2 values used. ---- @param d1 table<any,any> ---- @param d2 table<any,any> -function module.dictdiff(d1, d2) - local ret = {} --- @type table<any,any> - local hasdiff = false - for k, v in pairs(d1) do - if d2[k] == nil then - hasdiff = true - ret[k] = vim.NIL - elseif type(v) == type(d2[k]) then - if type(v) == 'table' then - local subdiff = module.dictdiff(v, d2[k]) - if subdiff ~= nil then - hasdiff = true - ret[k] = subdiff - end - elseif v ~= d2[k] then - ret[k] = d2[k] - hasdiff = true - end - else - ret[k] = d2[k] - hasdiff = true - end - end - local shallowcopy = module.shallowcopy - for k, v in pairs(d2) do - if d1[k] == nil then - ret[k] = shallowcopy(v) - hasdiff = true - end - end - if hasdiff then - return ret - else - return nil - end -end - --- Concat list-like tables. -function module.concat_tables(...) - local ret = {} --- @type table<any,any> - for i = 1, select('#', ...) do - --- @type table<any,any> - local tbl = select(i, ...) - if tbl then - for _, v in ipairs(tbl) do - ret[#ret + 1] = v - end - end - end - return ret -end - ---- @param str string ---- @param leave_indent? integer ---- @return string -function module.dedent(str, leave_indent) - -- find minimum common indent across lines - local indent --- @type string? - for line in str:gmatch('[^\n]+') do - local line_indent = line:match('^%s+') or '' - if indent == nil or #line_indent < #indent then - indent = line_indent - end - end - - if not indent or #indent == 0 then - -- no minimum common indent - return str - end - - local left_indent = (' '):rep(leave_indent or 0) - -- create a pattern for the indent - indent = indent:gsub('%s', '[ \t]') - -- strip it from the first line - str = str:gsub('^' .. indent, left_indent) - -- strip it from the remaining lines - str = str:gsub('[\n]' .. indent, '\n' .. left_indent) - return str -end - -function module.intchar2lua(ch) - ch = tonumber(ch) - return (20 <= ch and ch < 127) and ('%c'):format(ch) or ch -end - ---- @param str string ---- @return string -function module.hexdump(str) - local len = string.len(str) - local dump = '' - local hex = '' - local asc = '' - - for i = 1, len do - if 1 == i % 8 then - dump = dump .. hex .. asc .. '\n' - hex = string.format('%04x: ', i - 1) - asc = '' - end - - local ord = string.byte(str, i) - hex = hex .. string.format('%02x ', ord) - if ord >= 32 and ord <= 126 then - asc = asc .. string.char(ord) - else - asc = asc .. '.' - end - end - - return dump .. hex .. string.rep(' ', 8 - len % 8) .. asc -end - ---- Reads text lines from `filename` into a table. ---- @param filename string path to file ---- @param start? integer start line (1-indexed), negative means "lines before end" (tail) ---- @return string[]? -function module.read_file_list(filename, start) - local lnum = (start ~= nil and type(start) == 'number') and start or 1 - local tail = (lnum < 0) - local maxlines = tail and math.abs(lnum) or nil - local file = io.open(filename, 'r') - if not file then - return nil - end - - -- There is no need to read more than the last 2MB of the log file, so seek - -- to that. - local file_size = file:seek('end') - local offset = file_size - 2000000 - if offset < 0 then - offset = 0 - end - file:seek('set', offset) - - local lines = {} - local i = 1 - local line = file:read('*l') - while line ~= nil do - if i >= start then - table.insert(lines, line) - if #lines > maxlines then - table.remove(lines, 1) - end - end - i = i + 1 - line = file:read('*l') - end - file:close() - return lines -end - ---- Reads the entire contents of `filename` into a string. ---- @param filename string ---- @return string? -function module.read_file(filename) - local file = io.open(filename, 'r') - if not file then - return nil - end - local ret = file:read('*a') - file:close() - return ret -end - --- Dedent the given text and write it to the file name. -function module.write_file(name, text, no_dedent, append) - local file = assert(io.open(name, (append and 'a' or 'w'))) - if type(text) == 'table' then - -- Byte blob - --- @type string[] - local bytes = text - text = '' - for _, char in ipairs(bytes) do - text = ('%s%c'):format(text, char) - end - elseif not no_dedent then - text = module.dedent(text) - end - file:write(text) - file:flush() - file:close() -end - ---- @param name? 'cirrus'|'github' ---- @return boolean -function module.is_ci(name) - local any = (name == nil) - luaassert(any or name == 'github' or name == 'cirrus') - local gh = ((any or name == 'github') and nil ~= os.getenv('GITHUB_ACTIONS')) - local cirrus = ((any or name == 'cirrus') and nil ~= os.getenv('CIRRUS_CI')) - return gh or cirrus -end - --- Gets the (tail) contents of `logfile`. --- Also moves the file to "${NVIM_LOG_FILE}.displayed" on CI environments. -function module.read_nvim_log(logfile, ci_rename) - logfile = logfile or os.getenv('NVIM_LOG_FILE') or '.nvimlog' - local is_ci = module.is_ci() - local keep = is_ci and 100 or 10 - local lines = module.read_file_list(logfile, -keep) or {} - local log = ( - ('-'):rep(78) - .. '\n' - .. string.format('$NVIM_LOG_FILE: %s\n', logfile) - .. (#lines > 0 and '(last ' .. tostring(keep) .. ' lines)\n' or '(empty)\n') - ) - for _, line in ipairs(lines) do - log = log .. line .. '\n' - end - log = log .. ('-'):rep(78) .. '\n' - if is_ci and ci_rename then - os.rename(logfile, logfile .. '.displayed') - end - return log -end - ---- @param path string ---- @return boolean? -function module.mkdir(path) - -- 493 is 0755 in decimal - return (uv.fs_mkdir(path, 493)) -end - -return module diff --git a/test/old/testdir/load.vim b/test/old/testdir/load.vim @@ -1,4 +1,4 @@ -" Also used by: test/functional/helpers.lua +" Also used by: test/functional/testutil.lua function! s:load_factor() abort let timeout = 200 diff --git a/test/testutil.lua b/test/testutil.lua @@ -0,0 +1,779 @@ +local luaassert = require('luassert') +local busted = require('busted') +local uv = vim.uv +local Paths = require('test.cmakeconfig.paths') + +luaassert:set_parameter('TableFormatLevel', 100) + +local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote) + +--- @param str string +--- @return string +local function shell_quote(str) + if string.find(str, quote_me) or str == '' then + return '"' .. str:gsub('[$%%"\\]', '\\%0') .. '"' + end + return str +end + +--- @class test.testutil +local module = { + paths = Paths, +} + +--- @param p string +--- @return string +local function relpath(p) + p = vim.fs.normalize(p) + return (p:gsub('^' .. uv.cwd, '')) +end + +--- @param path string +--- @return boolean +function module.isdir(path) + if not path then + return false + end + local stat = uv.fs_stat(path) + if not stat then + return false + end + return stat.type == 'directory' +end + +--- @param ... string|string[] +--- @return string +function module.argss_to_cmd(...) + local cmd = {} --- @type string[] + for i = 1, select('#', ...) do + local arg = select(i, ...) + if type(arg) == 'string' then + cmd[#cmd + 1] = shell_quote(arg) + else + --- @cast arg string[] + for _, subarg in ipairs(arg) do + cmd[#cmd + 1] = shell_quote(subarg) + end + end + end + return table.concat(cmd, ' ') +end + +function module.popen_r(...) + return io.popen(module.argss_to_cmd(...), 'r') +end + +--- Calls fn() until it succeeds, up to `max` times or until `max_ms` +--- milliseconds have passed. +--- @param max integer? +--- @param max_ms integer? +--- @param fn function +--- @return any +function module.retry(max, max_ms, fn) + luaassert(max == nil or max > 0) + luaassert(max_ms == nil or max_ms > 0) + local tries = 1 + local timeout = (max_ms and max_ms or 10000) + local start_time = uv.now() + while true do + --- @type boolean, any + local status, result = pcall(fn) + if status then + return result + end + uv.update_time() -- Update cached value of luv.now() (libuv: uv_now()). + if (max and tries >= max) or (uv.now() - start_time > timeout) then + busted.fail(string.format('retry() attempts: %d\n%s', tries, tostring(result)), 2) + end + tries = tries + 1 + uv.sleep(20) -- Avoid hot loop... + end +end + +local check_logs_useless_lines = { + ['Warning: noted but unhandled ioctl'] = 1, + ['could cause spurious value errors to appear'] = 2, + ['See README_MISSING_SYSCALL_OR_IOCTL for guidance'] = 3, +} + +function module.eq(expected, actual, context) + return luaassert.are.same(expected, actual, context) +end +function module.neq(expected, actual, context) + return luaassert.are_not.same(expected, actual, context) +end + +--- Asserts that `cond` is true, or prints a message. +--- +--- @param cond (boolean) expression to assert +--- @param expected (any) description of expected result +--- @param actual (any) description of actual result +function module.ok(cond, expected, actual) + luaassert( + (not expected and not actual) or (expected and actual), + 'if "expected" is given, "actual" is also required' + ) + local msg = expected and ('expected %s, got: %s'):format(expected, tostring(actual)) or nil + return luaassert(cond, msg) +end + +local function epicfail(state, arguments, _) + state.failure_message = arguments[1] + return false +end +luaassert:register('assertion', 'epicfail', epicfail) +function module.fail(msg) + return luaassert.epicfail(msg) +end + +--- @param pat string +--- @param actual string +--- @return boolean +function module.matches(pat, actual) + if nil ~= string.match(actual, pat) then + return true + end + error(string.format('Pattern does not match.\nPattern:\n%s\nActual:\n%s', pat, actual)) +end + +--- Asserts that `pat` matches (or *not* if inverse=true) any line in the tail of `logfile`. +--- +--- Retries for 1 second in case of filesystem delay. +--- +---@param pat (string) Lua pattern to match lines in the log file +---@param logfile? (string) Full path to log file (default=$NVIM_LOG_FILE) +---@param nrlines? (number) Search up to this many log lines +---@param inverse? (boolean) Assert that the pattern does NOT match. +function module.assert_log(pat, logfile, nrlines, inverse) + logfile = logfile or os.getenv('NVIM_LOG_FILE') or '.nvimlog' + luaassert(logfile ~= nil, 'no logfile') + nrlines = nrlines or 10 + inverse = inverse or false + + module.retry(nil, 1000, function() + local lines = module.read_file_list(logfile, -nrlines) or {} + local msg = string.format( + 'Pattern %q %sfound in log (last %d lines): %s:\n%s', + pat, + (inverse and '' or 'not '), + nrlines, + logfile, + ' ' .. table.concat(lines, '\n ') + ) + for _, line in ipairs(lines) do + if line:match(pat) then + if inverse then + error(msg) + else + return + end + end + end + if not inverse then + error(msg) + end + end) +end + +--- Asserts that `pat` does NOT match any line in the tail of `logfile`. +--- +--- @see assert_log +--- @param pat (string) Lua pattern to match lines in the log file +--- @param logfile? (string) Full path to log file (default=$NVIM_LOG_FILE) +--- @param nrlines? (number) Search up to this many log lines +function module.assert_nolog(pat, logfile, nrlines) + return module.assert_log(pat, logfile, nrlines, true) +end + +--- @param fn fun(...): any +--- @param ... any +--- @return boolean, any +function module.pcall(fn, ...) + luaassert(type(fn) == 'function') + local status, rv = pcall(fn, ...) + if status then + return status, rv + end + + -- From: + -- C:/long/path/foo.lua:186: Expected string, got number + -- to: + -- .../foo.lua:0: Expected string, got number + local errmsg = tostring(rv) + :gsub('([%s<])vim[/\\]([^%s:/\\]+):%d+', '%1\xffvim\xff%2:0') + :gsub('[^%s<]-[/\\]([^%s:/\\]+):%d+', '.../%1:0') + :gsub('\xffvim\xff', 'vim/') + + -- Scrub numbers in paths/stacktraces: + -- shared.lua:0: in function 'gsplit' + -- shared.lua:0: in function <shared.lua:0>' + errmsg = errmsg:gsub('([^%s].lua):%d+', '%1:0') + -- [string "<nvim>"]:0: + -- [string ":lua"]:0: + -- [string ":luado"]:0: + errmsg = errmsg:gsub('(%[string "[^"]+"%]):%d+', '%1:0') + + -- Scrub tab chars: + errmsg = errmsg:gsub('\t', ' ') + -- In Lua 5.1, we sometimes get a "(tail call): ?" on the last line. + -- We remove this so that the tests are not lua dependent. + errmsg = errmsg:gsub('%s*%(tail call%): %?', '') + + return status, errmsg +end + +-- Invokes `fn` and returns the error string (with truncated paths), or raises +-- an error if `fn` succeeds. +-- +-- Replaces line/column numbers with zero: +-- shared.lua:0: in function 'gsplit' +-- shared.lua:0: in function <shared.lua:0>' +-- +-- Usage: +-- -- Match exact string. +-- eq('e', pcall_err(function(a, b) error('e') end, 'arg1', 'arg2')) +-- -- Match Lua pattern. +-- matches('e[or]+$', pcall_err(function(a, b) error('some error') end, 'arg1', 'arg2')) +-- +--- @param fn function +--- @return string +function module.pcall_err_withfile(fn, ...) + luaassert(type(fn) == 'function') + local status, rv = module.pcall(fn, ...) + if status == true then + error('expected failure, but got success') + end + return rv +end + +--- @param fn function +--- @param ... any +--- @return string +function module.pcall_err_withtrace(fn, ...) + local errmsg = module.pcall_err_withfile(fn, ...) + + return ( + errmsg + :gsub('^%.%.%./testutil%.lua:0: ', '') + :gsub('^Error executing lua:- ', '') + :gsub('^%[string "<nvim>"%]:0: ', '') + ) +end + +--- @param fn function +--- @param ... any +--- @return string +function module.pcall_err(fn, ...) + return module.remove_trace(module.pcall_err_withtrace(fn, ...)) +end + +--- @param s string +--- @return string +function module.remove_trace(s) + return (s:gsub('\n%s*stack traceback:.*', '')) +end + +-- initial_path: directory to recurse into +-- re: include pattern (string) +-- exc_re: exclude pattern(s) (string or table) +function module.glob(initial_path, re, exc_re) + exc_re = type(exc_re) == 'table' and exc_re or { exc_re } + local paths_to_check = { initial_path } --- @type string[] + local ret = {} --- @type string[] + local checked_files = {} --- @type table<string,true> + local function is_excluded(path) + for _, pat in pairs(exc_re) do + if path:match(pat) then + return true + end + end + return false + end + + if is_excluded(initial_path) then + return ret + end + while #paths_to_check > 0 do + local cur_path = paths_to_check[#paths_to_check] + paths_to_check[#paths_to_check] = nil + for e in vim.fs.dir(cur_path) do + local full_path = cur_path .. '/' .. e + local checked_path = full_path:sub(#initial_path + 1) + if (not is_excluded(checked_path)) and e:sub(1, 1) ~= '.' then + local stat = uv.fs_stat(full_path) + if stat then + local check_key = stat.dev .. ':' .. tostring(stat.ino) + if not checked_files[check_key] then + checked_files[check_key] = true + if stat.type == 'directory' then + paths_to_check[#paths_to_check + 1] = full_path + elseif not re or checked_path:match(re) then + ret[#ret + 1] = full_path + end + end + end + end + end + end + return ret +end + +function module.check_logs() + local log_dir = os.getenv('LOG_DIR') + local runtime_errors = {} + if log_dir and module.isdir(log_dir) then + for tail in vim.fs.dir(log_dir) do + if tail:sub(1, 30) == 'valgrind-' or tail:find('san%.') then + local file = log_dir .. '/' .. tail + local fd = assert(io.open(file)) + local start_msg = ('='):rep(20) .. ' File ' .. file .. ' ' .. ('='):rep(20) + local lines = {} --- @type string[] + local warning_line = 0 + for line in fd:lines() do + local cur_warning_line = check_logs_useless_lines[line] + if cur_warning_line == warning_line + 1 then + warning_line = cur_warning_line + else + lines[#lines + 1] = line + end + end + fd:close() + if #lines > 0 then + --- @type boolean?, file*? + local status, f + local out = io.stdout + if os.getenv('SYMBOLIZER') then + status, f = pcall(module.popen_r, os.getenv('SYMBOLIZER'), '-l', file) + end + out:write(start_msg .. '\n') + if status then + assert(f) + for line in f:lines() do + out:write('= ' .. line .. '\n') + end + f:close() + else + out:write('= ' .. table.concat(lines, '\n= ') .. '\n') + end + out:write(select(1, start_msg:gsub('.', '=')) .. '\n') + table.insert(runtime_errors, file) + end + os.remove(file) + end + end + end + luaassert( + 0 == #runtime_errors, + string.format('Found runtime errors in logfile(s): %s', table.concat(runtime_errors, ', ')) + ) +end + +function module.sysname() + return uv.os_uname().sysname:lower() +end + +--- @param s 'win'|'mac'|'freebsd'|'openbsd'|'bsd' +--- @return boolean +function module.is_os(s) + if not (s == 'win' or s == 'mac' or s == 'freebsd' or s == 'openbsd' or s == 'bsd') then + error('unknown platform: ' .. tostring(s)) + end + return not not ( + (s == 'win' and (module.sysname():find('windows') or module.sysname():find('mingw'))) + or (s == 'mac' and module.sysname() == 'darwin') + or (s == 'freebsd' and module.sysname() == 'freebsd') + or (s == 'openbsd' and module.sysname() == 'openbsd') + or (s == 'bsd' and module.sysname():find('bsd')) + ) +end + +local function tmpdir_get() + return os.getenv('TMPDIR') and os.getenv('TMPDIR') or os.getenv('TEMP') +end + +--- Is temp directory `dir` defined local to the project workspace? +--- @param dir string? +--- @return boolean +local function tmpdir_is_local(dir) + return not not (dir and dir:find('Xtest')) +end + +local tmpname_id = 0 +local tmpdir = tmpdir_get() + +--- Creates a new temporary file for use by tests. +function module.tmpname() + if tmpdir_is_local(tmpdir) then + -- Cannot control os.tmpname() dir, so hack our own tmpname() impl. + tmpname_id = tmpname_id + 1 + -- "…/Xtest_tmpdir/T42.7" + local fname = ('%s/%s.%d'):format(tmpdir, (_G._nvim_test_id or 'nvim-test'), tmpname_id) + io.open(fname, 'w'):close() + return fname + end + + local fname = os.tmpname() + if module.is_os('win') and fname:sub(1, 2) == '\\s' then + -- In Windows tmpname() returns a filename starting with + -- special sequence \s, prepend $TEMP path + return tmpdir .. fname + elseif module.is_os('mac') and fname:match('^/tmp') then + -- In OS X /tmp links to /private/tmp + return '/private' .. fname + end + + return fname +end + +local function deps_prefix() + local env = os.getenv('DEPS_PREFIX') + return (env and env ~= '') and env or '.deps/usr' +end + +local tests_skipped = 0 + +function module.check_cores(app, force) -- luacheck: ignore + -- Temporary workaround: skip core check as it interferes with CI. + if true then + return + end + app = app or 'build/bin/nvim' -- luacheck: ignore + --- @type string, string?, string[] + local initial_path, re, exc_re + local gdb_db_cmd = + 'gdb -n -batch -ex "thread apply all bt full" "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"' + local lldb_db_cmd = 'lldb -Q -o "bt all" -f "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"' + local random_skip = false + -- Workspace-local $TMPDIR, scrubbed and pattern-escaped. + -- "./Xtest-tmpdir/" => "Xtest%-tmpdir" + local local_tmpdir = ( + tmpdir_is_local(tmpdir_get()) + and relpath(tmpdir_get()):gsub('^[ ./]+', ''):gsub('%/+$', ''):gsub('([^%w])', '%%%1') + or nil + ) + local db_cmd --- @type string + local test_glob_dir = os.getenv('NVIM_TEST_CORE_GLOB_DIRECTORY') + if test_glob_dir and test_glob_dir ~= '' then + initial_path = test_glob_dir + re = os.getenv('NVIM_TEST_CORE_GLOB_RE') + exc_re = { os.getenv('NVIM_TEST_CORE_EXC_RE'), local_tmpdir } + db_cmd = os.getenv('NVIM_TEST_CORE_DB_CMD') or gdb_db_cmd + random_skip = os.getenv('NVIM_TEST_CORE_RANDOM_SKIP') ~= '' + elseif module.is_os('mac') then + initial_path = '/cores' + re = nil + exc_re = { local_tmpdir } + db_cmd = lldb_db_cmd + else + initial_path = '.' + if module.is_os('freebsd') then + re = '/nvim.core$' + else + re = '/core[^/]*$' + end + exc_re = { '^/%.deps$', '^/%' .. deps_prefix() .. '$', local_tmpdir, '^/%node_modules$' } + db_cmd = gdb_db_cmd + random_skip = true + end + -- Finding cores takes too much time on linux + if not force and random_skip and math.random() < 0.9 then + tests_skipped = tests_skipped + 1 + return + end + local cores = module.glob(initial_path, re, exc_re) + local found_cores = 0 + local out = io.stdout + for _, core in ipairs(cores) do + local len = 80 - #core - #'Core file ' - 2 + local esigns = ('='):rep(len / 2) + out:write(('\n%s Core file %s %s\n'):format(esigns, core, esigns)) + out:flush() + os.execute(db_cmd:gsub('%$_NVIM_TEST_APP', app):gsub('%$_NVIM_TEST_CORE', core) .. ' 2>&1') + out:write('\n') + found_cores = found_cores + 1 + os.remove(core) + end + if found_cores ~= 0 then + out:write(('\nTests covered by this check: %u\n'):format(tests_skipped + 1)) + end + tests_skipped = 0 + if found_cores > 0 then + error('crash detected (see above)') + end +end + +--- @return string? +function module.repeated_read_cmd(...) + for _ = 1, 10 do + local stream = module.popen_r(...) + local ret = stream:read('*a') + stream:close() + if ret then + return ret + end + end + print('ERROR: Failed to execute ' .. module.argss_to_cmd(...) .. ': nil return after 10 attempts') + return nil +end + +--- @generic T +--- @param orig T +--- @return T +function module.shallowcopy(orig) + if type(orig) ~= 'table' then + return orig + end + --- @cast orig table<any,any> + local copy = {} --- @type table<any,any> + for orig_key, orig_value in pairs(orig) do + copy[orig_key] = orig_value + end + return copy +end + +--- @param d1 table<any,any> +--- @param d2 table<any,any> +--- @return table<any,any> +function module.mergedicts_copy(d1, d2) + local ret = module.shallowcopy(d1) + for k, v in pairs(d2) do + if d2[k] == vim.NIL then + ret[k] = nil + elseif type(d1[k]) == 'table' and type(v) == 'table' then + ret[k] = module.mergedicts_copy(d1[k], v) + else + ret[k] = v + end + end + return ret +end + +--- dictdiff: find a diff so that mergedicts_copy(d1, diff) is equal to d2 +--- +--- Note: does not do copies of d2 values used. +--- @param d1 table<any,any> +--- @param d2 table<any,any> +function module.dictdiff(d1, d2) + local ret = {} --- @type table<any,any> + local hasdiff = false + for k, v in pairs(d1) do + if d2[k] == nil then + hasdiff = true + ret[k] = vim.NIL + elseif type(v) == type(d2[k]) then + if type(v) == 'table' then + local subdiff = module.dictdiff(v, d2[k]) + if subdiff ~= nil then + hasdiff = true + ret[k] = subdiff + end + elseif v ~= d2[k] then + ret[k] = d2[k] + hasdiff = true + end + else + ret[k] = d2[k] + hasdiff = true + end + end + local shallowcopy = module.shallowcopy + for k, v in pairs(d2) do + if d1[k] == nil then + ret[k] = shallowcopy(v) + hasdiff = true + end + end + if hasdiff then + return ret + else + return nil + end +end + +-- Concat list-like tables. +function module.concat_tables(...) + local ret = {} --- @type table<any,any> + for i = 1, select('#', ...) do + --- @type table<any,any> + local tbl = select(i, ...) + if tbl then + for _, v in ipairs(tbl) do + ret[#ret + 1] = v + end + end + end + return ret +end + +--- @param str string +--- @param leave_indent? integer +--- @return string +function module.dedent(str, leave_indent) + -- find minimum common indent across lines + local indent --- @type string? + for line in str:gmatch('[^\n]+') do + local line_indent = line:match('^%s+') or '' + if indent == nil or #line_indent < #indent then + indent = line_indent + end + end + + if not indent or #indent == 0 then + -- no minimum common indent + return str + end + + local left_indent = (' '):rep(leave_indent or 0) + -- create a pattern for the indent + indent = indent:gsub('%s', '[ \t]') + -- strip it from the first line + str = str:gsub('^' .. indent, left_indent) + -- strip it from the remaining lines + str = str:gsub('[\n]' .. indent, '\n' .. left_indent) + return str +end + +function module.intchar2lua(ch) + ch = tonumber(ch) + return (20 <= ch and ch < 127) and ('%c'):format(ch) or ch +end + +--- @param str string +--- @return string +function module.hexdump(str) + local len = string.len(str) + local dump = '' + local hex = '' + local asc = '' + + for i = 1, len do + if 1 == i % 8 then + dump = dump .. hex .. asc .. '\n' + hex = string.format('%04x: ', i - 1) + asc = '' + end + + local ord = string.byte(str, i) + hex = hex .. string.format('%02x ', ord) + if ord >= 32 and ord <= 126 then + asc = asc .. string.char(ord) + else + asc = asc .. '.' + end + end + + return dump .. hex .. string.rep(' ', 8 - len % 8) .. asc +end + +--- Reads text lines from `filename` into a table. +--- @param filename string path to file +--- @param start? integer start line (1-indexed), negative means "lines before end" (tail) +--- @return string[]? +function module.read_file_list(filename, start) + local lnum = (start ~= nil and type(start) == 'number') and start or 1 + local tail = (lnum < 0) + local maxlines = tail and math.abs(lnum) or nil + local file = io.open(filename, 'r') + if not file then + return nil + end + + -- There is no need to read more than the last 2MB of the log file, so seek + -- to that. + local file_size = file:seek('end') + local offset = file_size - 2000000 + if offset < 0 then + offset = 0 + end + file:seek('set', offset) + + local lines = {} + local i = 1 + local line = file:read('*l') + while line ~= nil do + if i >= start then + table.insert(lines, line) + if #lines > maxlines then + table.remove(lines, 1) + end + end + i = i + 1 + line = file:read('*l') + end + file:close() + return lines +end + +--- Reads the entire contents of `filename` into a string. +--- @param filename string +--- @return string? +function module.read_file(filename) + local file = io.open(filename, 'r') + if not file then + return nil + end + local ret = file:read('*a') + file:close() + return ret +end + +-- Dedent the given text and write it to the file name. +function module.write_file(name, text, no_dedent, append) + local file = assert(io.open(name, (append and 'a' or 'w'))) + if type(text) == 'table' then + -- Byte blob + --- @type string[] + local bytes = text + text = '' + for _, char in ipairs(bytes) do + text = ('%s%c'):format(text, char) + end + elseif not no_dedent then + text = module.dedent(text) + end + file:write(text) + file:flush() + file:close() +end + +--- @param name? 'cirrus'|'github' +--- @return boolean +function module.is_ci(name) + local any = (name == nil) + luaassert(any or name == 'github' or name == 'cirrus') + local gh = ((any or name == 'github') and nil ~= os.getenv('GITHUB_ACTIONS')) + local cirrus = ((any or name == 'cirrus') and nil ~= os.getenv('CIRRUS_CI')) + return gh or cirrus +end + +-- Gets the (tail) contents of `logfile`. +-- Also moves the file to "${NVIM_LOG_FILE}.displayed" on CI environments. +function module.read_nvim_log(logfile, ci_rename) + logfile = logfile or os.getenv('NVIM_LOG_FILE') or '.nvimlog' + local is_ci = module.is_ci() + local keep = is_ci and 100 or 10 + local lines = module.read_file_list(logfile, -keep) or {} + local log = ( + ('-'):rep(78) + .. '\n' + .. string.format('$NVIM_LOG_FILE: %s\n', logfile) + .. (#lines > 0 and '(last ' .. tostring(keep) .. ' lines)\n' or '(empty)\n') + ) + for _, line in ipairs(lines) do + log = log .. line .. '\n' + end + log = log .. ('-'):rep(78) .. '\n' + if is_ci and ci_rename then + os.rename(logfile, logfile .. '.displayed') + end + return log +end + +--- @param path string +--- @return boolean? +function module.mkdir(path) + -- 493 is 0755 in decimal + return (uv.fs_mkdir(path, 493)) +end + +return module diff --git a/test/unit/api/helpers.lua b/test/unit/api/helpers.lua @@ -1,177 +0,0 @@ -local helpers = require('test.unit.helpers')(nil) -local eval_helpers = require('test.unit.eval.helpers') - -local cimport = helpers.cimport -local to_cstr = helpers.to_cstr -local ffi = helpers.ffi - -local list_type = eval_helpers.list_type -local dict_type = eval_helpers.dict_type -local func_type = eval_helpers.func_type -local nil_value = eval_helpers.nil_value -local int_type = eval_helpers.int_type -local flt_type = eval_helpers.flt_type -local type_key = eval_helpers.type_key - -local api = cimport( - './src/nvim/api/private/defs.h', - './src/nvim/api/private/helpers.h', - './src/nvim/memory.h' -) - -local obj2lua - -local obj2lua_tab = nil - -local function init_obj2lua_tab() - if obj2lua_tab then - return - end - obj2lua_tab = { - [tonumber(api.kObjectTypeArray)] = function(obj) - local ret = { [type_key] = list_type } - for i = 1, tonumber(obj.data.array.size) do - ret[i] = obj2lua(obj.data.array.items[i - 1]) - end - if ret[1] then - ret[type_key] = nil - end - return ret - end, - [tonumber(api.kObjectTypeDictionary)] = function(obj) - local ret = {} - for i = 1, tonumber(obj.data.dictionary.size) do - local kv_pair = obj.data.dictionary.items[i - 1] - ret[ffi.string(kv_pair.key.data, kv_pair.key.size)] = obj2lua(kv_pair.value) - end - return ret - end, - [tonumber(api.kObjectTypeBoolean)] = function(obj) - if obj.data.boolean == false then - return false - else - return true - end - end, - [tonumber(api.kObjectTypeNil)] = function(_) - return nil_value - end, - [tonumber(api.kObjectTypeFloat)] = function(obj) - return tonumber(obj.data.floating) - end, - [tonumber(api.kObjectTypeInteger)] = function(obj) - return { [type_key] = int_type, value = tonumber(obj.data.integer) } - end, - [tonumber(api.kObjectTypeString)] = function(obj) - return ffi.string(obj.data.string.data, obj.data.string.size) - end, - } -end - -obj2lua = function(obj) - init_obj2lua_tab() - return ( - (obj2lua_tab[tonumber(obj['type'])] or function(obj_inner) - assert( - false, - 'Converting ' .. tostring(tonumber(obj_inner['type'])) .. ' is not implementing yet' - ) - end)(obj) - ) -end - -local obj = function(typ, data) - return ffi.gc(ffi.new('Object', { ['type'] = typ, data = data }), api.api_free_object) -end - -local lua2obj - -local lua2obj_type_tab = { - [int_type] = function(l) - return obj(api.kObjectTypeInteger, { integer = l.value }) - end, - [flt_type] = function(l) - return obj(api.kObjectTypeFloat, { floating = l }) - end, - [list_type] = function(l) - local len = #l - local arr = obj(api.kObjectTypeArray, { - array = { - size = len, - capacity = len, - items = ffi.cast('Object *', api.xmalloc(len * ffi.sizeof('Object'))), - }, - }) - for i = 1, len do - arr.data.array.items[i - 1] = ffi.gc(lua2obj(l[i]), nil) - end - return arr - end, - [dict_type] = function(l) - local kvs = {} - for k, v in pairs(l) do - if type(k) == 'string' then - kvs[#kvs + 1] = { k, v } - end - end - local len = #kvs - local dct = obj(api.kObjectTypeDictionary, { - dictionary = { - size = len, - capacity = len, - items = ffi.cast('KeyValuePair *', api.xmalloc(len * ffi.sizeof('KeyValuePair'))), - }, - }) - for i = 1, len do - local key, val = unpack(kvs[i]) - dct.data.dictionary.items[i - 1] = ffi.new( - 'KeyValuePair', - { key = ffi.gc(lua2obj(key), nil).data.string, value = ffi.gc(lua2obj(val), nil) } - ) - end - return dct - end, -} - -lua2obj = function(l) - if type(l) == 'table' then - if l[type_key] then - return lua2obj_type_tab[l[type_key]](l) - else - if l[1] then - return lua2obj_type_tab[list_type](l) - else - return lua2obj_type_tab[dict_type](l) - end - end - elseif type(l) == 'number' then - return lua2obj_type_tab[flt_type](l) - elseif type(l) == 'boolean' then - return obj(api.kObjectTypeBoolean, { boolean = l }) - elseif type(l) == 'string' then - return obj( - api.kObjectTypeString, - { string = { - size = #l, - data = api.xmemdupz(to_cstr(l), #l), - } } - ) - elseif l == nil or l == nil_value then - return obj(api.kObjectTypeNil, { integer = 0 }) - end -end - -return { - list_type = list_type, - dict_type = dict_type, - func_type = func_type, - int_type = int_type, - flt_type = flt_type, - - nil_value = nil_value, - - type_key = type_key, - - obj2lua = obj2lua, - lua2obj = lua2obj, -} diff --git a/test/unit/api/private_helpers_spec.lua b/test/unit/api/private_helpers_spec.lua @@ -1,24 +1,24 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) -local eval_helpers = require('test.unit.eval.helpers') -local api_helpers = require('test.unit.api.helpers') - -local cimport = helpers.cimport -local NULL = helpers.NULL -local eq = helpers.eq - -local lua2typvalt = eval_helpers.lua2typvalt -local typvalt2lua = eval_helpers.typvalt2lua -local typvalt = eval_helpers.typvalt - -local nil_value = api_helpers.nil_value -local list_type = api_helpers.list_type -local int_type = api_helpers.int_type -local type_key = api_helpers.type_key -local obj2lua = api_helpers.obj2lua -local func_type = api_helpers.func_type - -local api = cimport('./src/nvim/api/private/helpers.h', './src/nvim/api/private/converter.h') +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) +local t_eval = require('test.unit.eval.testutil') +local api_t = require('test.unit.api.testutil') + +local cimport = t.cimport +local NULL = t.NULL +local eq = t.eq + +local lua2typvalt = t_eval.lua2typvalt +local typvalt2lua = t_eval.typvalt2lua +local typvalt = t_eval.typvalt + +local nil_value = api_t.nil_value +local list_type = api_t.list_type +local int_type = api_t.int_type +local type_key = api_t.type_key +local obj2lua = api_t.obj2lua +local func_type = api_t.func_type + +local api = cimport('./src/nvim/api/private/t.h', './src/nvim/api/private/converter.h') describe('vim_to_object', function() local vim_to_object = function(l) diff --git a/test/unit/api/testutil.lua b/test/unit/api/testutil.lua @@ -0,0 +1,174 @@ +local t = require('test.unit.testutil')(nil) +local t_eval = require('test.unit.eval.testutil') + +local cimport = t.cimport +local to_cstr = t.to_cstr +local ffi = t.ffi + +local list_type = t_eval.list_type +local dict_type = t_eval.dict_type +local func_type = t_eval.func_type +local nil_value = t_eval.nil_value +local int_type = t_eval.int_type +local flt_type = t_eval.flt_type +local type_key = t_eval.type_key + +local api = + cimport('./src/nvim/api/private/defs.h', './src/nvim/api/private/t.h', './src/nvim/memory.h') + +local obj2lua + +local obj2lua_tab = nil + +local function init_obj2lua_tab() + if obj2lua_tab then + return + end + obj2lua_tab = { + [tonumber(api.kObjectTypeArray)] = function(obj) + local ret = { [type_key] = list_type } + for i = 1, tonumber(obj.data.array.size) do + ret[i] = obj2lua(obj.data.array.items[i - 1]) + end + if ret[1] then + ret[type_key] = nil + end + return ret + end, + [tonumber(api.kObjectTypeDictionary)] = function(obj) + local ret = {} + for i = 1, tonumber(obj.data.dictionary.size) do + local kv_pair = obj.data.dictionary.items[i - 1] + ret[ffi.string(kv_pair.key.data, kv_pair.key.size)] = obj2lua(kv_pair.value) + end + return ret + end, + [tonumber(api.kObjectTypeBoolean)] = function(obj) + if obj.data.boolean == false then + return false + else + return true + end + end, + [tonumber(api.kObjectTypeNil)] = function(_) + return nil_value + end, + [tonumber(api.kObjectTypeFloat)] = function(obj) + return tonumber(obj.data.floating) + end, + [tonumber(api.kObjectTypeInteger)] = function(obj) + return { [type_key] = int_type, value = tonumber(obj.data.integer) } + end, + [tonumber(api.kObjectTypeString)] = function(obj) + return ffi.string(obj.data.string.data, obj.data.string.size) + end, + } +end + +obj2lua = function(obj) + init_obj2lua_tab() + return ( + (obj2lua_tab[tonumber(obj['type'])] or function(obj_inner) + assert( + false, + 'Converting ' .. tostring(tonumber(obj_inner['type'])) .. ' is not implementing yet' + ) + end)(obj) + ) +end + +local obj = function(typ, data) + return ffi.gc(ffi.new('Object', { ['type'] = typ, data = data }), api.api_free_object) +end + +local lua2obj + +local lua2obj_type_tab = { + [int_type] = function(l) + return obj(api.kObjectTypeInteger, { integer = l.value }) + end, + [flt_type] = function(l) + return obj(api.kObjectTypeFloat, { floating = l }) + end, + [list_type] = function(l) + local len = #l + local arr = obj(api.kObjectTypeArray, { + array = { + size = len, + capacity = len, + items = ffi.cast('Object *', api.xmalloc(len * ffi.sizeof('Object'))), + }, + }) + for i = 1, len do + arr.data.array.items[i - 1] = ffi.gc(lua2obj(l[i]), nil) + end + return arr + end, + [dict_type] = function(l) + local kvs = {} + for k, v in pairs(l) do + if type(k) == 'string' then + kvs[#kvs + 1] = { k, v } + end + end + local len = #kvs + local dct = obj(api.kObjectTypeDictionary, { + dictionary = { + size = len, + capacity = len, + items = ffi.cast('KeyValuePair *', api.xmalloc(len * ffi.sizeof('KeyValuePair'))), + }, + }) + for i = 1, len do + local key, val = unpack(kvs[i]) + dct.data.dictionary.items[i - 1] = ffi.new( + 'KeyValuePair', + { key = ffi.gc(lua2obj(key), nil).data.string, value = ffi.gc(lua2obj(val), nil) } + ) + end + return dct + end, +} + +lua2obj = function(l) + if type(l) == 'table' then + if l[type_key] then + return lua2obj_type_tab[l[type_key]](l) + else + if l[1] then + return lua2obj_type_tab[list_type](l) + else + return lua2obj_type_tab[dict_type](l) + end + end + elseif type(l) == 'number' then + return lua2obj_type_tab[flt_type](l) + elseif type(l) == 'boolean' then + return obj(api.kObjectTypeBoolean, { boolean = l }) + elseif type(l) == 'string' then + return obj( + api.kObjectTypeString, + { string = { + size = #l, + data = api.xmemdupz(to_cstr(l), #l), + } } + ) + elseif l == nil or l == nil_value then + return obj(api.kObjectTypeNil, { integer = 0 }) + end +end + +return { + list_type = list_type, + dict_type = dict_type, + func_type = func_type, + int_type = int_type, + flt_type = flt_type, + + nil_value = nil_value, + + type_key = type_key, + + obj2lua = obj2lua, + lua2obj = lua2obj, +} diff --git a/test/unit/buffer_spec.lua b/test/unit/buffer_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local to_cstr = helpers.to_cstr -local eq = helpers.eq -local NULL = helpers.NULL +local to_cstr = t.to_cstr +local eq = t.eq +local NULL = t.NULL -local buffer = helpers.cimport('./src/nvim/buffer.h') +local buffer = t.cimport('./src/nvim/buffer.h') describe('buffer functions', function() local buflist_new = function(file, flags) diff --git a/test/unit/charset/vim_str2nr_spec.lua b/test/unit/charset/vim_str2nr_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.unit.helpers')(after_each) +local t = require('test.unit.testutil')(after_each) local bit = require('bit') -local itp = helpers.gen_itp(it) +local itp = t.gen_itp(it) -local child_call_once = helpers.child_call_once -local cimport = helpers.cimport -local ffi = helpers.ffi +local child_call_once = t.child_call_once +local cimport = t.cimport +local ffi = t.ffi local lib = cimport('./src/nvim/charset.h') diff --git a/test/unit/eval/decode_spec.lua b/test/unit/eval/decode_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local cimport = helpers.cimport -local eq = helpers.eq -local neq = helpers.neq -local ffi = helpers.ffi +local cimport = t.cimport +local eq = t.eq +local neq = t.neq +local ffi = t.ffi local decode = cimport( './src/nvim/eval/decode.h', diff --git a/test/unit/eval/encode_spec.lua b/test/unit/eval/encode_spec.lua @@ -1,16 +1,16 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) -local eval_helpers = require('test.unit.eval.helpers') +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) +local t_eval = require('test.unit.eval.testutil') -local cimport = helpers.cimport -local to_cstr = helpers.to_cstr -local eq = helpers.eq +local cimport = t.cimport +local to_cstr = t.to_cstr +local eq = t.eq -local list = eval_helpers.list -local lst2tbl = eval_helpers.lst2tbl -local type_key = eval_helpers.type_key -local list_type = eval_helpers.list_type -local null_string = eval_helpers.null_string +local list = t_eval.list +local lst2tbl = t_eval.lst2tbl +local type_key = t_eval.type_key +local list_type = t_eval.list_type +local null_string = t_eval.null_string local encode = cimport('./src/nvim/eval/encode.h') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua @@ -1,606 +0,0 @@ -local helpers = require('test.unit.helpers')(nil) - -local ptr2key = helpers.ptr2key -local cimport = helpers.cimport -local to_cstr = helpers.to_cstr -local ffi = helpers.ffi -local eq = helpers.eq - -local eval = cimport( - './src/nvim/eval.h', - './src/nvim/eval/typval.h', - './src/nvim/hashtab.h', - './src/nvim/memory.h' -) - -local null_string = { [true] = 'NULL string' } -local null_list = { [true] = 'NULL list' } -local null_dict = { [true] = 'NULL dict' } -local type_key = { [true] = 'type key' } -local locks_key = { [true] = 'locks key' } -local list_type = { [true] = 'list type' } -local dict_type = { [true] = 'dict type' } -local func_type = { [true] = 'func type' } -local int_type = { [true] = 'int type' } -local flt_type = { [true] = 'flt type' } - -local nil_value = { [true] = 'nil' } - -local lua2typvalt - -local function tv_list_item_alloc() - return ffi.cast('listitem_T*', eval.xmalloc(ffi.sizeof('listitem_T'))) -end - -local function tv_list_item_free(li) - eval.tv_clear(li.li_tv) - eval.xfree(li) -end - -local function li_alloc(nogc) - local gcfunc = tv_list_item_free - if nogc then - gcfunc = nil - end - local li = ffi.gc(tv_list_item_alloc(), gcfunc) - li.li_next = nil - li.li_prev = nil - li.li_tv = { v_type = eval.VAR_UNKNOWN, v_lock = eval.VAR_UNLOCKED } - return li -end - -local function populate_list(l, lua_l, processed) - processed = processed or {} - eq(0, l.lv_refcount) - l.lv_refcount = 1 - processed[lua_l] = l - for i = 1, #lua_l do - local item_tv = ffi.gc(lua2typvalt(lua_l[i], processed), nil) - local item_li = tv_list_item_alloc() - item_li.li_tv = item_tv - eval.tv_list_append(l, item_li) - end - return l -end - -local function populate_dict(d, lua_d, processed) - processed = processed or {} - eq(0, d.dv_refcount) - d.dv_refcount = 1 - processed[lua_d] = d - for k, v in pairs(lua_d) do - if type(k) == 'string' then - local di = eval.tv_dict_item_alloc(to_cstr(k)) - local val_tv = ffi.gc(lua2typvalt(v, processed), nil) - eval.tv_copy(val_tv, di.di_tv) - eval.tv_clear(val_tv) - eval.tv_dict_add(d, di) - end - end - return d -end - -local function populate_partial(pt, lua_pt, processed) - processed = processed or {} - eq(0, pt.pt_refcount) - processed[lua_pt] = pt - local argv = nil - if lua_pt.args and #lua_pt.args > 0 then - argv = ffi.gc(ffi.cast('typval_T*', eval.xmalloc(ffi.sizeof('typval_T') * #lua_pt.args)), nil) - for i, arg in ipairs(lua_pt.args) do - local arg_tv = ffi.gc(lua2typvalt(arg, processed), nil) - argv[i - 1] = arg_tv - end - end - local dict = nil - if lua_pt.dict then - local dict_tv = ffi.gc(lua2typvalt(lua_pt.dict, processed), nil) - assert(dict_tv.v_type == eval.VAR_DICT) - dict = dict_tv.vval.v_dict - end - pt.pt_refcount = 1 - pt.pt_name = eval.xmemdupz(to_cstr(lua_pt.value), #lua_pt.value) - pt.pt_auto = not not lua_pt.auto - pt.pt_argc = lua_pt.args and #lua_pt.args or 0 - pt.pt_argv = argv - pt.pt_dict = dict - return pt -end - -local lst2tbl -local dct2tbl - -local typvalt2lua - -local function partial2lua(pt, processed) - processed = processed or {} - local value, auto, dict, argv = nil, nil, nil, nil - if pt ~= nil then - value = ffi.string(pt.pt_name) - auto = pt.pt_auto and true or nil - argv = {} - for i = 1, pt.pt_argc do - argv[i] = typvalt2lua(pt.pt_argv[i - 1], processed) - end - if pt.pt_dict ~= nil then - dict = dct2tbl(pt.pt_dict) - end - end - return { - [type_key] = func_type, - value = value, - auto = auto, - args = argv, - dict = dict, - } -end - -local typvalt2lua_tab = nil - -local function typvalt2lua_tab_init() - if typvalt2lua_tab then - return - end - typvalt2lua_tab = { - [tonumber(eval.VAR_BOOL)] = function(t) - return ({ - [tonumber(eval.kBoolVarFalse)] = false, - [tonumber(eval.kBoolVarTrue)] = true, - })[tonumber(t.vval.v_bool)] - end, - [tonumber(eval.VAR_SPECIAL)] = function(t) - return ({ - [tonumber(eval.kSpecialVarNull)] = nil_value, - })[tonumber(t.vval.v_special)] - end, - [tonumber(eval.VAR_NUMBER)] = function(t) - return { [type_key] = int_type, value = tonumber(t.vval.v_number) } - end, - [tonumber(eval.VAR_FLOAT)] = function(t) - return tonumber(t.vval.v_float) - end, - [tonumber(eval.VAR_STRING)] = function(t) - local str = t.vval.v_string - if str == nil then - return null_string - else - return ffi.string(str) - end - end, - [tonumber(eval.VAR_LIST)] = function(t, processed) - return lst2tbl(t.vval.v_list, processed) - end, - [tonumber(eval.VAR_DICT)] = function(t, processed) - return dct2tbl(t.vval.v_dict, processed) - end, - [tonumber(eval.VAR_FUNC)] = function(t, processed) - return { [type_key] = func_type, value = typvalt2lua_tab[eval.VAR_STRING](t, processed or {}) } - end, - [tonumber(eval.VAR_PARTIAL)] = function(t, processed) - local p_key = ptr2key(t) - if processed[p_key] then - return processed[p_key] - end - return partial2lua(t.vval.v_partial, processed) - end, - } -end - -typvalt2lua = function(t, processed) - typvalt2lua_tab_init() - return ( - (typvalt2lua_tab[tonumber(t.v_type)] or function(t_inner) - assert(false, 'Converting ' .. tonumber(t_inner.v_type) .. ' was not implemented yet') - end)(t, processed or {}) - ) -end - -local function list_iter(l) - local init_s = { - idx = 0, - li = l.lv_first, - } - local function f(s, _) - -- (listitem_T *) NULL is equal to nil, but yet it is not false. - if s.li == nil then - return nil - end - local ret_li = s.li - s.li = s.li.li_next - s.idx = s.idx + 1 - return s.idx, ret_li - end - return f, init_s, nil -end - -local function list_items(l) - local ret = {} - for i, li in list_iter(l) do - ret[i] = li - end - return ret -end - -lst2tbl = function(l, processed) - if l == nil then - return null_list - end - processed = processed or {} - local p_key = ptr2key(l) - if processed[p_key] then - return processed[p_key] - end - local ret = { [type_key] = list_type } - processed[p_key] = ret - for i, li in list_iter(l) do - ret[i] = typvalt2lua(li.li_tv, processed) - end - if ret[1] then - ret[type_key] = nil - end - return ret -end - -local hi_key_removed = nil - -local function dict_iter(d, return_hi) - hi_key_removed = hi_key_removed or eval._hash_key_removed() - local init_s = { - todo = d.dv_hashtab.ht_used, - hi = d.dv_hashtab.ht_array, - } - local function f(s, _) - if s.todo == 0 then - return nil - end - while s.todo > 0 do - if s.hi.hi_key ~= nil and s.hi.hi_key ~= hi_key_removed then - local key = ffi.string(s.hi.hi_key) - local ret - if return_hi then - ret = s.hi - else - ret = ffi.cast('dictitem_T*', s.hi.hi_key - ffi.offsetof('dictitem_T', 'di_key')) - end - s.todo = s.todo - 1 - s.hi = s.hi + 1 - return key, ret - end - s.hi = s.hi + 1 - end - end - return f, init_s, nil -end - -local function first_di(d) - local f, init_s, v = dict_iter(d) - return select(2, f(init_s, v)) -end - -local function dict_items(d) - local ret = { [0] = 0 } - for k, hi in dict_iter(d) do - ret[k] = hi - ret[0] = ret[0] + 1 - ret[ret[0]] = hi - end - return ret -end - -dct2tbl = function(d, processed) - if d == nil then - return null_dict - end - processed = processed or {} - local p_key = ptr2key(d) - if processed[p_key] then - return processed[p_key] - end - local ret = {} - processed[p_key] = ret - for k, di in dict_iter(d) do - ret[k] = typvalt2lua(di.di_tv, processed) - end - return ret -end - -local typvalt = function(typ, vval) - if typ == nil then - typ = eval.VAR_UNKNOWN - elseif type(typ) == 'string' then - typ = eval[typ] - end - return ffi.gc(ffi.new('typval_T', { v_type = typ, vval = vval }), eval.tv_clear) -end - -local lua2typvalt_type_tab = { - [int_type] = function(l, _) - return typvalt(eval.VAR_NUMBER, { v_number = l.value }) - end, - [flt_type] = function(l, processed) - return lua2typvalt(l.value, processed) - end, - [list_type] = function(l, processed) - if processed[l] then - processed[l].lv_refcount = processed[l].lv_refcount + 1 - return typvalt(eval.VAR_LIST, { v_list = processed[l] }) - end - local lst = populate_list(eval.tv_list_alloc(#l), l, processed) - return typvalt(eval.VAR_LIST, { v_list = lst }) - end, - [dict_type] = function(l, processed) - if processed[l] then - processed[l].dv_refcount = processed[l].dv_refcount + 1 - return typvalt(eval.VAR_DICT, { v_dict = processed[l] }) - end - local dct = populate_dict(eval.tv_dict_alloc(), l, processed) - return typvalt(eval.VAR_DICT, { v_dict = dct }) - end, - [func_type] = function(l, processed) - if processed[l] then - processed[l].pt_refcount = processed[l].pt_refcount + 1 - return typvalt(eval.VAR_PARTIAL, { v_partial = processed[l] }) - end - if l.args or l.dict then - local pt = populate_partial( - ffi.gc(ffi.cast('partial_T*', eval.xcalloc(1, ffi.sizeof('partial_T'))), nil), - l, - processed - ) - return typvalt(eval.VAR_PARTIAL, { v_partial = pt }) - else - return typvalt(eval.VAR_FUNC, { - v_string = eval.xmemdupz(to_cstr(l.value), #l.value), - }) - end - end, -} - -local special_vals = nil - -lua2typvalt = function(l, processed) - if not special_vals then - special_vals = { - [null_string] = { 'VAR_STRING', { v_string = ffi.cast('char*', nil) } }, - [null_list] = { 'VAR_LIST', { v_list = ffi.cast('list_T*', nil) } }, - [null_dict] = { 'VAR_DICT', { v_dict = ffi.cast('dict_T*', nil) } }, - [nil_value] = { 'VAR_SPECIAL', { v_special = eval.kSpecialVarNull } }, - [true] = { 'VAR_BOOL', { v_bool = eval.kBoolVarTrue } }, - [false] = { 'VAR_BOOL', { v_bool = eval.kBoolVarFalse } }, - } - - for k, v in pairs(special_vals) do - local tmp = function(typ, vval) - special_vals[k] = function() - return typvalt(eval[typ], vval) - end - end - tmp(v[1], v[2]) - end - end - processed = processed or {} - if l == nil or l == nil_value then - return special_vals[nil_value]() - elseif special_vals[l] then - return special_vals[l]() - elseif type(l) == 'table' then - if l[type_key] then - return lua2typvalt_type_tab[l[type_key]](l, processed) - else - if l[1] then - return lua2typvalt_type_tab[list_type](l, processed) - else - return lua2typvalt_type_tab[dict_type](l, processed) - end - end - elseif type(l) == 'number' then - return typvalt(eval.VAR_FLOAT, { v_float = l }) - elseif type(l) == 'string' then - return typvalt(eval.VAR_STRING, { v_string = eval.xmemdupz(to_cstr(l), #l) }) - elseif type(l) == 'cdata' then - local tv = typvalt(eval.VAR_UNKNOWN) - eval.tv_copy(l, tv) - return tv - end -end - -local void_ptr = ffi.typeof('void *') -local function void(ptr) - return ffi.cast(void_ptr, ptr) -end - -local function alloc_len(len, get_ptr) - if type(len) == 'string' or type(len) == 'table' then - return #len - elseif len == nil then - return eval.strlen(get_ptr()) - else - return len - end -end - -local alloc_logging_helpers = { - list = function(l) - return { func = 'calloc', args = { 1, ffi.sizeof('list_T') }, ret = void(l) } - end, - li = function(li) - return { func = 'malloc', args = { ffi.sizeof('listitem_T') }, ret = void(li) } - end, - dict = function(d) - return { func = 'calloc', args = { 1, ffi.sizeof('dict_T') }, ret = void(d) } - end, - di = function(di, size) - size = alloc_len(size, function() - return di.di_key - end) - return { - func = 'malloc', - args = { ffi.offsetof('dictitem_T', 'di_key') + size + 1 }, - ret = void(di), - } - end, - str = function(s, size) - size = alloc_len(size, function() - return s - end) - return { func = 'malloc', args = { size + 1 }, ret = void(s) } - end, - - dwatcher = function(w) - return { func = 'malloc', args = { ffi.sizeof('DictWatcher') }, ret = void(w) } - end, - - freed = function(p) - return { func = 'free', args = { type(p) == 'table' and p or void(p) } } - end, - - -- lua_…: allocated by this file, not by some Neovim function - lua_pt = function(pt) - return { func = 'calloc', args = { 1, ffi.sizeof('partial_T') }, ret = void(pt) } - end, - lua_tvs = function(argv, argc) - argc = alloc_len(argc) - return { func = 'malloc', args = { ffi.sizeof('typval_T') * argc }, ret = void(argv) } - end, -} - -local function int(n) - return { [type_key] = int_type, value = n } -end - -local function list(...) - return populate_list( - ffi.gc(eval.tv_list_alloc(select('#', ...)), eval.tv_list_unref), - { ... }, - {} - ) -end - -local function dict(d) - return populate_dict(ffi.gc(eval.tv_dict_alloc(), eval.tv_dict_free), d or {}, {}) -end - -local callback2tbl_type_tab = nil - -local function init_callback2tbl_type_tab() - if callback2tbl_type_tab then - return - end - callback2tbl_type_tab = { - [tonumber(eval.kCallbackNone)] = function(_) - return { type = 'none' } - end, - [tonumber(eval.kCallbackFuncref)] = function(cb) - return { type = 'fref', fref = ffi.string(cb.data.funcref) } - end, - [tonumber(eval.kCallbackPartial)] = function(cb) - local lua_pt = partial2lua(cb.data.partial) - return { type = 'pt', fref = ffi.string(lua_pt.value), pt = lua_pt } - end, - } -end - -local function callback2tbl(cb) - init_callback2tbl_type_tab() - return callback2tbl_type_tab[tonumber(cb.type)](cb) -end - -local function tbl2callback(tbl) - local ret = nil - if tbl.type == 'none' then - ret = ffi.new('Callback[1]', { { type = eval.kCallbackNone } }) - elseif tbl.type == 'fref' then - ret = ffi.new( - 'Callback[1]', - { { type = eval.kCallbackFuncref, data = { funcref = eval.xstrdup(tbl.fref) } } } - ) - elseif tbl.type == 'pt' then - local pt = ffi.gc(ffi.cast('partial_T*', eval.xcalloc(1, ffi.sizeof('partial_T'))), nil) - ret = ffi.new( - 'Callback[1]', - { { type = eval.kCallbackPartial, data = { partial = populate_partial(pt, tbl.pt, {}) } } } - ) - else - assert(false) - end - return ffi.gc(ffi.cast('Callback*', ret), helpers.callback_free) -end - -local function dict_watchers(d) - local ret = {} - local h = d.watchers - local q = h.next - local qs = {} - local key_patterns = {} - while q ~= h do - local qitem = - ffi.cast('DictWatcher *', ffi.cast('char *', q) - ffi.offsetof('DictWatcher', 'node')) - ret[#ret + 1] = { - cb = callback2tbl(qitem.callback), - pat = ffi.string(qitem.key_pattern, qitem.key_pattern_len), - busy = qitem.busy, - } - qs[#qs + 1] = qitem - key_patterns[#key_patterns + 1] = { qitem.key_pattern, qitem.key_pattern_len } - q = q.next - end - return ret, qs, key_patterns -end - -local function eval0(expr) - local tv = ffi.gc(ffi.new('typval_T', { v_type = eval.VAR_UNKNOWN }), eval.tv_clear) - local evalarg = ffi.new('evalarg_T', { eval_flags = eval.EVAL_EVALUATE }) - if eval.eval0(to_cstr(expr), tv, nil, evalarg) == 0 then - return nil - else - return tv - end -end - -return { - int = int, - - null_string = null_string, - null_list = null_list, - null_dict = null_dict, - list_type = list_type, - dict_type = dict_type, - func_type = func_type, - int_type = int_type, - flt_type = flt_type, - - nil_value = nil_value, - - type_key = type_key, - locks_key = locks_key, - - list = list, - dict = dict, - lst2tbl = lst2tbl, - dct2tbl = dct2tbl, - - lua2typvalt = lua2typvalt, - typvalt2lua = typvalt2lua, - - typvalt = typvalt, - - li_alloc = li_alloc, - tv_list_item_free = tv_list_item_free, - - dict_iter = dict_iter, - list_iter = list_iter, - first_di = first_di, - - alloc_logging_helpers = alloc_logging_helpers, - - list_items = list_items, - dict_items = dict_items, - - dict_watchers = dict_watchers, - tbl2callback = tbl2callback, - callback2tbl = callback2tbl, - - eval0 = eval0, - - empty_list = { [type_key] = list_type }, -} diff --git a/test/unit/eval/testutil.lua b/test/unit/eval/testutil.lua @@ -0,0 +1,606 @@ +local t = require('test.unit.testutil')(nil) + +local ptr2key = t.ptr2key +local cimport = t.cimport +local to_cstr = t.to_cstr +local ffi = t.ffi +local eq = t.eq + +local eval = cimport( + './src/nvim/eval.h', + './src/nvim/eval/typval.h', + './src/nvim/hashtab.h', + './src/nvim/memory.h' +) + +local null_string = { [true] = 'NULL string' } +local null_list = { [true] = 'NULL list' } +local null_dict = { [true] = 'NULL dict' } +local type_key = { [true] = 'type key' } +local locks_key = { [true] = 'locks key' } +local list_type = { [true] = 'list type' } +local dict_type = { [true] = 'dict type' } +local func_type = { [true] = 'func type' } +local int_type = { [true] = 'int type' } +local flt_type = { [true] = 'flt type' } + +local nil_value = { [true] = 'nil' } + +local lua2typvalt + +local function tv_list_item_alloc() + return ffi.cast('listitem_T*', eval.xmalloc(ffi.sizeof('listitem_T'))) +end + +local function tv_list_item_free(li) + eval.tv_clear(li.li_tv) + eval.xfree(li) +end + +local function li_alloc(nogc) + local gcfunc = tv_list_item_free + if nogc then + gcfunc = nil + end + local li = ffi.gc(tv_list_item_alloc(), gcfunc) + li.li_next = nil + li.li_prev = nil + li.li_tv = { v_type = eval.VAR_UNKNOWN, v_lock = eval.VAR_UNLOCKED } + return li +end + +local function populate_list(l, lua_l, processed) + processed = processed or {} + eq(0, l.lv_refcount) + l.lv_refcount = 1 + processed[lua_l] = l + for i = 1, #lua_l do + local item_tv = ffi.gc(lua2typvalt(lua_l[i], processed), nil) + local item_li = tv_list_item_alloc() + item_li.li_tv = item_tv + eval.tv_list_append(l, item_li) + end + return l +end + +local function populate_dict(d, lua_d, processed) + processed = processed or {} + eq(0, d.dv_refcount) + d.dv_refcount = 1 + processed[lua_d] = d + for k, v in pairs(lua_d) do + if type(k) == 'string' then + local di = eval.tv_dict_item_alloc(to_cstr(k)) + local val_tv = ffi.gc(lua2typvalt(v, processed), nil) + eval.tv_copy(val_tv, di.di_tv) + eval.tv_clear(val_tv) + eval.tv_dict_add(d, di) + end + end + return d +end + +local function populate_partial(pt, lua_pt, processed) + processed = processed or {} + eq(0, pt.pt_refcount) + processed[lua_pt] = pt + local argv = nil + if lua_pt.args and #lua_pt.args > 0 then + argv = ffi.gc(ffi.cast('typval_T*', eval.xmalloc(ffi.sizeof('typval_T') * #lua_pt.args)), nil) + for i, arg in ipairs(lua_pt.args) do + local arg_tv = ffi.gc(lua2typvalt(arg, processed), nil) + argv[i - 1] = arg_tv + end + end + local dict = nil + if lua_pt.dict then + local dict_tv = ffi.gc(lua2typvalt(lua_pt.dict, processed), nil) + assert(dict_tv.v_type == eval.VAR_DICT) + dict = dict_tv.vval.v_dict + end + pt.pt_refcount = 1 + pt.pt_name = eval.xmemdupz(to_cstr(lua_pt.value), #lua_pt.value) + pt.pt_auto = not not lua_pt.auto + pt.pt_argc = lua_pt.args and #lua_pt.args or 0 + pt.pt_argv = argv + pt.pt_dict = dict + return pt +end + +local lst2tbl +local dct2tbl + +local typvalt2lua + +local function partial2lua(pt, processed) + processed = processed or {} + local value, auto, dict, argv = nil, nil, nil, nil + if pt ~= nil then + value = ffi.string(pt.pt_name) + auto = pt.pt_auto and true or nil + argv = {} + for i = 1, pt.pt_argc do + argv[i] = typvalt2lua(pt.pt_argv[i - 1], processed) + end + if pt.pt_dict ~= nil then + dict = dct2tbl(pt.pt_dict) + end + end + return { + [type_key] = func_type, + value = value, + auto = auto, + args = argv, + dict = dict, + } +end + +local typvalt2lua_tab = nil + +local function typvalt2lua_tab_init() + if typvalt2lua_tab then + return + end + typvalt2lua_tab = { + [tonumber(eval.VAR_BOOL)] = function(q) + return ({ + [tonumber(eval.kBoolVarFalse)] = false, + [tonumber(eval.kBoolVarTrue)] = true, + })[tonumber(q.vval.v_bool)] + end, + [tonumber(eval.VAR_SPECIAL)] = function(q) + return ({ + [tonumber(eval.kSpecialVarNull)] = nil_value, + })[tonumber(q.vval.v_special)] + end, + [tonumber(eval.VAR_NUMBER)] = function(q) + return { [type_key] = int_type, value = tonumber(q.vval.v_number) } + end, + [tonumber(eval.VAR_FLOAT)] = function(q) + return tonumber(q.vval.v_float) + end, + [tonumber(eval.VAR_STRING)] = function(q) + local str = q.vval.v_string + if str == nil then + return null_string + else + return ffi.string(str) + end + end, + [tonumber(eval.VAR_LIST)] = function(q, processed) + return lst2tbl(q.vval.v_list, processed) + end, + [tonumber(eval.VAR_DICT)] = function(q, processed) + return dct2tbl(q.vval.v_dict, processed) + end, + [tonumber(eval.VAR_FUNC)] = function(q, processed) + return { [type_key] = func_type, value = typvalt2lua_tab[eval.VAR_STRING](q, processed or {}) } + end, + [tonumber(eval.VAR_PARTIAL)] = function(q, processed) + local p_key = ptr2key(q) + if processed[p_key] then + return processed[p_key] + end + return partial2lua(q.vval.v_partial, processed) + end, + } +end + +typvalt2lua = function(q, processed) + typvalt2lua_tab_init() + return ( + (typvalt2lua_tab[tonumber(q.v_type)] or function(t_inner) + assert(false, 'Converting ' .. tonumber(t_inner.v_type) .. ' was not implemented yet') + end)(q, processed or {}) + ) +end + +local function list_iter(l) + local init_s = { + idx = 0, + li = l.lv_first, + } + local function f(s, _) + -- (listitem_T *) NULL is equal to nil, but yet it is not false. + if s.li == nil then + return nil + end + local ret_li = s.li + s.li = s.li.li_next + s.idx = s.idx + 1 + return s.idx, ret_li + end + return f, init_s, nil +end + +local function list_items(l) + local ret = {} + for i, li in list_iter(l) do + ret[i] = li + end + return ret +end + +lst2tbl = function(l, processed) + if l == nil then + return null_list + end + processed = processed or {} + local p_key = ptr2key(l) + if processed[p_key] then + return processed[p_key] + end + local ret = { [type_key] = list_type } + processed[p_key] = ret + for i, li in list_iter(l) do + ret[i] = typvalt2lua(li.li_tv, processed) + end + if ret[1] then + ret[type_key] = nil + end + return ret +end + +local hi_key_removed = nil + +local function dict_iter(d, return_hi) + hi_key_removed = hi_key_removed or eval._hash_key_removed() + local init_s = { + todo = d.dv_hashtab.ht_used, + hi = d.dv_hashtab.ht_array, + } + local function f(s, _) + if s.todo == 0 then + return nil + end + while s.todo > 0 do + if s.hi.hi_key ~= nil and s.hi.hi_key ~= hi_key_removed then + local key = ffi.string(s.hi.hi_key) + local ret + if return_hi then + ret = s.hi + else + ret = ffi.cast('dictitem_T*', s.hi.hi_key - ffi.offsetof('dictitem_T', 'di_key')) + end + s.todo = s.todo - 1 + s.hi = s.hi + 1 + return key, ret + end + s.hi = s.hi + 1 + end + end + return f, init_s, nil +end + +local function first_di(d) + local f, init_s, v = dict_iter(d) + return select(2, f(init_s, v)) +end + +local function dict_items(d) + local ret = { [0] = 0 } + for k, hi in dict_iter(d) do + ret[k] = hi + ret[0] = ret[0] + 1 + ret[ret[0]] = hi + end + return ret +end + +dct2tbl = function(d, processed) + if d == nil then + return null_dict + end + processed = processed or {} + local p_key = ptr2key(d) + if processed[p_key] then + return processed[p_key] + end + local ret = {} + processed[p_key] = ret + for k, di in dict_iter(d) do + ret[k] = typvalt2lua(di.di_tv, processed) + end + return ret +end + +local typvalt = function(typ, vval) + if typ == nil then + typ = eval.VAR_UNKNOWN + elseif type(typ) == 'string' then + typ = eval[typ] + end + return ffi.gc(ffi.new('typval_T', { v_type = typ, vval = vval }), eval.tv_clear) +end + +local lua2typvalt_type_tab = { + [int_type] = function(l, _) + return typvalt(eval.VAR_NUMBER, { v_number = l.value }) + end, + [flt_type] = function(l, processed) + return lua2typvalt(l.value, processed) + end, + [list_type] = function(l, processed) + if processed[l] then + processed[l].lv_refcount = processed[l].lv_refcount + 1 + return typvalt(eval.VAR_LIST, { v_list = processed[l] }) + end + local lst = populate_list(eval.tv_list_alloc(#l), l, processed) + return typvalt(eval.VAR_LIST, { v_list = lst }) + end, + [dict_type] = function(l, processed) + if processed[l] then + processed[l].dv_refcount = processed[l].dv_refcount + 1 + return typvalt(eval.VAR_DICT, { v_dict = processed[l] }) + end + local dct = populate_dict(eval.tv_dict_alloc(), l, processed) + return typvalt(eval.VAR_DICT, { v_dict = dct }) + end, + [func_type] = function(l, processed) + if processed[l] then + processed[l].pt_refcount = processed[l].pt_refcount + 1 + return typvalt(eval.VAR_PARTIAL, { v_partial = processed[l] }) + end + if l.args or l.dict then + local pt = populate_partial( + ffi.gc(ffi.cast('partial_T*', eval.xcalloc(1, ffi.sizeof('partial_T'))), nil), + l, + processed + ) + return typvalt(eval.VAR_PARTIAL, { v_partial = pt }) + else + return typvalt(eval.VAR_FUNC, { + v_string = eval.xmemdupz(to_cstr(l.value), #l.value), + }) + end + end, +} + +local special_vals = nil + +lua2typvalt = function(l, processed) + if not special_vals then + special_vals = { + [null_string] = { 'VAR_STRING', { v_string = ffi.cast('char*', nil) } }, + [null_list] = { 'VAR_LIST', { v_list = ffi.cast('list_T*', nil) } }, + [null_dict] = { 'VAR_DICT', { v_dict = ffi.cast('dict_T*', nil) } }, + [nil_value] = { 'VAR_SPECIAL', { v_special = eval.kSpecialVarNull } }, + [true] = { 'VAR_BOOL', { v_bool = eval.kBoolVarTrue } }, + [false] = { 'VAR_BOOL', { v_bool = eval.kBoolVarFalse } }, + } + + for k, v in pairs(special_vals) do + local tmp = function(typ, vval) + special_vals[k] = function() + return typvalt(eval[typ], vval) + end + end + tmp(v[1], v[2]) + end + end + processed = processed or {} + if l == nil or l == nil_value then + return special_vals[nil_value]() + elseif special_vals[l] then + return special_vals[l]() + elseif type(l) == 'table' then + if l[type_key] then + return lua2typvalt_type_tab[l[type_key]](l, processed) + else + if l[1] then + return lua2typvalt_type_tab[list_type](l, processed) + else + return lua2typvalt_type_tab[dict_type](l, processed) + end + end + elseif type(l) == 'number' then + return typvalt(eval.VAR_FLOAT, { v_float = l }) + elseif type(l) == 'string' then + return typvalt(eval.VAR_STRING, { v_string = eval.xmemdupz(to_cstr(l), #l) }) + elseif type(l) == 'cdata' then + local tv = typvalt(eval.VAR_UNKNOWN) + eval.tv_copy(l, tv) + return tv + end +end + +local void_ptr = ffi.typeof('void *') +local function void(ptr) + return ffi.cast(void_ptr, ptr) +end + +local function alloc_len(len, get_ptr) + if type(len) == 'string' or type(len) == 'table' then + return #len + elseif len == nil then + return eval.strlen(get_ptr()) + else + return len + end +end + +local alloc_logging_t = { + list = function(l) + return { func = 'calloc', args = { 1, ffi.sizeof('list_T') }, ret = void(l) } + end, + li = function(li) + return { func = 'malloc', args = { ffi.sizeof('listitem_T') }, ret = void(li) } + end, + dict = function(d) + return { func = 'calloc', args = { 1, ffi.sizeof('dict_T') }, ret = void(d) } + end, + di = function(di, size) + size = alloc_len(size, function() + return di.di_key + end) + return { + func = 'malloc', + args = { ffi.offsetof('dictitem_T', 'di_key') + size + 1 }, + ret = void(di), + } + end, + str = function(s, size) + size = alloc_len(size, function() + return s + end) + return { func = 'malloc', args = { size + 1 }, ret = void(s) } + end, + + dwatcher = function(w) + return { func = 'malloc', args = { ffi.sizeof('DictWatcher') }, ret = void(w) } + end, + + freed = function(p) + return { func = 'free', args = { type(p) == 'table' and p or void(p) } } + end, + + -- lua_…: allocated by this file, not by some Neovim function + lua_pt = function(pt) + return { func = 'calloc', args = { 1, ffi.sizeof('partial_T') }, ret = void(pt) } + end, + lua_tvs = function(argv, argc) + argc = alloc_len(argc) + return { func = 'malloc', args = { ffi.sizeof('typval_T') * argc }, ret = void(argv) } + end, +} + +local function int(n) + return { [type_key] = int_type, value = n } +end + +local function list(...) + return populate_list( + ffi.gc(eval.tv_list_alloc(select('#', ...)), eval.tv_list_unref), + { ... }, + {} + ) +end + +local function dict(d) + return populate_dict(ffi.gc(eval.tv_dict_alloc(), eval.tv_dict_free), d or {}, {}) +end + +local callback2tbl_type_tab = nil + +local function init_callback2tbl_type_tab() + if callback2tbl_type_tab then + return + end + callback2tbl_type_tab = { + [tonumber(eval.kCallbackNone)] = function(_) + return { type = 'none' } + end, + [tonumber(eval.kCallbackFuncref)] = function(cb) + return { type = 'fref', fref = ffi.string(cb.data.funcref) } + end, + [tonumber(eval.kCallbackPartial)] = function(cb) + local lua_pt = partial2lua(cb.data.partial) + return { type = 'pt', fref = ffi.string(lua_pt.value), pt = lua_pt } + end, + } +end + +local function callback2tbl(cb) + init_callback2tbl_type_tab() + return callback2tbl_type_tab[tonumber(cb.type)](cb) +end + +local function tbl2callback(tbl) + local ret = nil + if tbl.type == 'none' then + ret = ffi.new('Callback[1]', { { type = eval.kCallbackNone } }) + elseif tbl.type == 'fref' then + ret = ffi.new( + 'Callback[1]', + { { type = eval.kCallbackFuncref, data = { funcref = eval.xstrdup(tbl.fref) } } } + ) + elseif tbl.type == 'pt' then + local pt = ffi.gc(ffi.cast('partial_T*', eval.xcalloc(1, ffi.sizeof('partial_T'))), nil) + ret = ffi.new( + 'Callback[1]', + { { type = eval.kCallbackPartial, data = { partial = populate_partial(pt, tbl.pt, {}) } } } + ) + else + assert(false) + end + return ffi.gc(ffi.cast('Callback*', ret), t.callback_free) +end + +local function dict_watchers(d) + local ret = {} + local h = d.watchers + local q = h.next + local qs = {} + local key_patterns = {} + while q ~= h do + local qitem = + ffi.cast('DictWatcher *', ffi.cast('char *', q) - ffi.offsetof('DictWatcher', 'node')) + ret[#ret + 1] = { + cb = callback2tbl(qitem.callback), + pat = ffi.string(qitem.key_pattern, qitem.key_pattern_len), + busy = qitem.busy, + } + qs[#qs + 1] = qitem + key_patterns[#key_patterns + 1] = { qitem.key_pattern, qitem.key_pattern_len } + q = q.next + end + return ret, qs, key_patterns +end + +local function eval0(expr) + local tv = ffi.gc(ffi.new('typval_T', { v_type = eval.VAR_UNKNOWN }), eval.tv_clear) + local evalarg = ffi.new('evalarg_T', { eval_flags = eval.EVAL_EVALUATE }) + if eval.eval0(to_cstr(expr), tv, nil, evalarg) == 0 then + return nil + else + return tv + end +end + +return { + int = int, + + null_string = null_string, + null_list = null_list, + null_dict = null_dict, + list_type = list_type, + dict_type = dict_type, + func_type = func_type, + int_type = int_type, + flt_type = flt_type, + + nil_value = nil_value, + + type_key = type_key, + locks_key = locks_key, + + list = list, + dict = dict, + lst2tbl = lst2tbl, + dct2tbl = dct2tbl, + + lua2typvalt = lua2typvalt, + typvalt2lua = typvalt2lua, + + typvalt = typvalt, + + li_alloc = li_alloc, + tv_list_item_free = tv_list_item_free, + + dict_iter = dict_iter, + list_iter = list_iter, + first_di = first_di, + + alloc_logging_t = alloc_logging_t, + + list_items = list_items, + dict_items = dict_items, + + dict_watchers = dict_watchers, + tbl2callback = tbl2callback, + callback2tbl = callback2tbl, + + eval0 = eval0, + + empty_list = { [type_key] = list_type }, +} diff --git a/test/unit/eval/tricks_spec.lua b/test/unit/eval/tricks_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.unit.helpers')(after_each) -local eval_helpers = require('test.unit.eval.helpers') +local t = require('test.unit.testutil')(after_each) +local t_eval = require('test.unit.eval.testutil') -local itp = helpers.gen_itp(it) +local itp = t.gen_itp(it) -local cimport = helpers.cimport -local eq = helpers.eq +local cimport = t.cimport +local eq = t.eq -local eval0 = eval_helpers.eval0 +local eval0 = t_eval.eval0 local eval = cimport('./src/nvim/eval.h', './src/nvim/eval/typval.h', './src/nvim/memory.h') diff --git a/test/unit/eval/tv_clear_spec.lua b/test/unit/eval/tv_clear_spec.lua @@ -1,18 +1,18 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) -local eval_helpers = require('test.unit.eval.helpers') +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) +local t_eval = require('test.unit.eval.testutil') -local alloc_log_new = helpers.alloc_log_new -local cimport = helpers.cimport -local ffi = helpers.ffi -local eq = helpers.eq +local alloc_log_new = t.alloc_log_new +local cimport = t.cimport +local ffi = t.ffi +local eq = t.eq -local a = eval_helpers.alloc_logging_helpers -local type_key = eval_helpers.type_key -local list_type = eval_helpers.list_type -local list_items = eval_helpers.list_items -local dict_items = eval_helpers.dict_items -local lua2typvalt = eval_helpers.lua2typvalt +local a = t_eval.alloc_logging_t +local type_key = t_eval.type_key +local list_type = t_eval.list_type +local list_items = t_eval.list_items +local dict_items = t_eval.dict_items +local lua2typvalt = t_eval.lua2typvalt local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/eval.h') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua @@ -1,45 +1,45 @@ local bit = require('bit') -local helpers = require('test.unit.helpers')(after_each) -local eval_helpers = require('test.unit.eval.helpers') - -local itp = helpers.gen_itp(it) - -local OK = helpers.OK -local eq = helpers.eq -local neq = helpers.neq -local ffi = helpers.ffi -local FAIL = helpers.FAIL -local NULL = helpers.NULL -local cimport = helpers.cimport -local to_cstr = helpers.to_cstr -local alloc_log_new = helpers.alloc_log_new -local concat_tables = helpers.concat_tables +local t = require('test.unit.testutil')(after_each) +local t_eval = require('test.unit.eval.testutil') + +local itp = t.gen_itp(it) + +local OK = t.OK +local eq = t.eq +local neq = t.neq +local ffi = t.ffi +local FAIL = t.FAIL +local NULL = t.NULL +local cimport = t.cimport +local to_cstr = t.to_cstr +local alloc_log_new = t.alloc_log_new +local concat_tables = t.concat_tables local map = vim.tbl_map -local a = eval_helpers.alloc_logging_helpers -local int = eval_helpers.int -local list = eval_helpers.list -local dict = eval_helpers.dict -local eval0 = eval_helpers.eval0 -local lst2tbl = eval_helpers.lst2tbl -local dct2tbl = eval_helpers.dct2tbl -local typvalt = eval_helpers.typvalt -local type_key = eval_helpers.type_key -local li_alloc = eval_helpers.li_alloc -local first_di = eval_helpers.first_di -local nil_value = eval_helpers.nil_value -local func_type = eval_helpers.func_type -local null_list = eval_helpers.null_list -local null_dict = eval_helpers.null_dict -local dict_items = eval_helpers.dict_items -local list_items = eval_helpers.list_items -local empty_list = eval_helpers.empty_list -local lua2typvalt = eval_helpers.lua2typvalt -local typvalt2lua = eval_helpers.typvalt2lua -local null_string = eval_helpers.null_string -local callback2tbl = eval_helpers.callback2tbl -local tbl2callback = eval_helpers.tbl2callback -local dict_watchers = eval_helpers.dict_watchers +local a = t_eval.alloc_logging_t +local int = t_eval.int +local list = t_eval.list +local dict = t_eval.dict +local eval0 = t_eval.eval0 +local lst2tbl = t_eval.lst2tbl +local dct2tbl = t_eval.dct2tbl +local typvalt = t_eval.typvalt +local type_key = t_eval.type_key +local li_alloc = t_eval.li_alloc +local first_di = t_eval.first_di +local nil_value = t_eval.nil_value +local func_type = t_eval.func_type +local null_list = t_eval.null_list +local null_dict = t_eval.null_dict +local dict_items = t_eval.dict_items +local list_items = t_eval.list_items +local empty_list = t_eval.empty_list +local lua2typvalt = t_eval.lua2typvalt +local typvalt2lua = t_eval.typvalt2lua +local null_string = t_eval.null_string +local callback2tbl = t_eval.callback2tbl +local tbl2callback = t_eval.tbl2callback +local dict_watchers = t_eval.dict_watchers local lib = cimport( './src/nvim/eval/typval.h', diff --git a/test/unit/fileio_spec.lua b/test/unit/fileio_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) ---{:cimport, :internalize, :eq, :neq, :ffi, :lib, :cstr, :to_cstr} = require 'test.unit.helpers' +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) +--{:cimport, :internalize, :eq, :neq, :ffi, :lib, :cstr, :to_cstr} = require 'test.unit.testutil' -local eq = helpers.eq -local ffi = helpers.ffi -local to_cstr = helpers.to_cstr -local NULL = helpers.NULL +local eq = t.eq +local ffi = t.ffi +local to_cstr = t.to_cstr +local NULL = t.NULL -local fileio = helpers.cimport('./src/nvim/fileio.h') +local fileio = t.cimport('./src/nvim/fileio.h') describe('file_pat functions', function() describe('file_pat_to_reg_pat', function() diff --git a/test/unit/garray_spec.lua b/test/unit/garray_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) - -local cimport = helpers.cimport -local internalize = helpers.internalize -local eq = helpers.eq -local neq = helpers.neq -local ffi = helpers.ffi -local to_cstr = helpers.to_cstr -local NULL = helpers.NULL +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) + +local cimport = t.cimport +local internalize = t.internalize +local eq = t.eq +local neq = t.neq +local ffi = t.ffi +local to_cstr = t.to_cstr +local NULL = t.NULL local garray = cimport('./src/nvim/garray.h') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua @@ -1,911 +0,0 @@ -local ffi = require('ffi') -local formatc = require('test.unit.formatc') -local Set = require('test.unit.set') -local Preprocess = require('test.unit.preprocess') -local global_helpers = require('test.helpers') -local paths = global_helpers.paths -local assert = require('luassert') -local say = require('say') - -local check_cores = global_helpers.check_cores -local dedent = global_helpers.dedent -local neq = global_helpers.neq -local map = vim.tbl_map -local eq = global_helpers.eq -local trim = vim.trim - --- add some standard header locations -for _, p in ipairs(paths.include_paths) do - Preprocess.add_to_include_path(p) -end - -local child_pid = nil --- @type integer? ---- @generic F: function ---- @param func F ---- @return F -local function only_separate(func) - return function(...) - if child_pid ~= 0 then - error('This function must be run in a separate process only') - end - return func(...) - end -end - ---- @class ChildCall ---- @field func function ---- @field args any[] - ---- @class ChildCallLog ---- @field func string ---- @field args any[] ---- @field ret any? - -local child_calls_init = {} --- @type ChildCall[] -local child_calls_mod = nil --- @type ChildCall[] -local child_calls_mod_once = nil --- @type ChildCall[]? - -local function child_call(func, ret) - return function(...) - local child_calls = child_calls_mod or child_calls_init - if child_pid ~= 0 then - child_calls[#child_calls + 1] = { func = func, args = { ... } } - return ret - else - return func(...) - end - end -end - --- Run some code at the start of the child process, before running the test --- itself. Is supposed to be run in `before_each`. ---- @param func function -local function child_call_once(func, ...) - if child_pid ~= 0 then - child_calls_mod_once[#child_calls_mod_once + 1] = { func = func, args = { ... } } - else - func(...) - end -end - -local child_cleanups_mod_once = nil --- @type ChildCall[]? - --- Run some code at the end of the child process, before exiting. Is supposed to --- be run in `before_each` because `after_each` is run after child has exited. -local function child_cleanup_once(func, ...) - local child_cleanups = child_cleanups_mod_once - if child_pid ~= 0 then - child_cleanups[#child_cleanups + 1] = { func = func, args = { ... } } - else - func(...) - end -end - --- Unittests are run from debug nvim binary in lua interpreter mode. -local libnvim = ffi.C - -local lib = setmetatable({}, { - __index = only_separate(function(_, idx) - return libnvim[idx] - end), - __newindex = child_call(function(_, idx, val) - libnvim[idx] = val - end), -}) - -local init = only_separate(function() - for _, c in ipairs(child_calls_init) do - c.func(unpack(c.args)) - end - libnvim.event_init() - libnvim.early_init(nil) - if child_calls_mod then - for _, c in ipairs(child_calls_mod) do - c.func(unpack(c.args)) - end - end - if child_calls_mod_once then - for _, c in ipairs(child_calls_mod_once) do - c.func(unpack(c.args)) - end - child_calls_mod_once = nil - end -end) - -local deinit = only_separate(function() - if child_cleanups_mod_once then - for _, c in ipairs(child_cleanups_mod_once) do - c.func(unpack(c.args)) - end - child_cleanups_mod_once = nil - end -end) - --- a Set that keeps around the lines we've already seen -local cdefs_init = Set:new() -local cdefs_mod = nil -local imported = Set:new() -local pragma_pack_id = 1 - --- some things are just too complex for the LuaJIT C parser to digest. We --- usually don't need them anyway. ---- @param body string -local function filter_complex_blocks(body) - local result = {} --- @type string[] - - for line in body:gmatch('[^\r\n]+') do - if - not ( - string.find(line, '(^)', 1, true) ~= nil - or string.find(line, '_ISwupper', 1, true) - or string.find(line, '_Float') - or string.find(line, '__s128') - or string.find(line, '__u128') - or string.find(line, 'msgpack_zone_push_finalizer') - or string.find(line, 'msgpack_unpacker_reserve_buffer') - or string.find(line, 'value_init_') - or string.find(line, 'UUID_NULL') -- static const uuid_t UUID_NULL = {...} - or string.find(line, 'inline _Bool') - ) - then - result[#result + 1] = line - end - end - - return table.concat(result, '\n') -end - -local cdef = ffi.cdef - -local cimportstr - -local previous_defines_init = [[ -typedef struct { char bytes[16]; } __attribute__((aligned(16))) __uint128_t; -typedef struct { char bytes[16]; } __attribute__((aligned(16))) __float128; -]] - -local preprocess_cache_init = {} --- @type table<string,string> -local previous_defines_mod = '' -local preprocess_cache_mod = nil --- @type table<string,string> - -local function is_child_cdefs() - return os.getenv('NVIM_TEST_MAIN_CDEFS') ~= '1' -end - --- use this helper to import C files, you can pass multiple paths at once, --- this helper will return the C namespace of the nvim library. -local function cimport(...) - local previous_defines --- @type string - local preprocess_cache --- @type table<string,string> - local cdefs - if is_child_cdefs() and preprocess_cache_mod then - preprocess_cache = preprocess_cache_mod - previous_defines = previous_defines_mod - cdefs = cdefs_mod - else - preprocess_cache = preprocess_cache_init - previous_defines = previous_defines_init - cdefs = cdefs_init - end - for _, path in ipairs({ ... }) do - if not (path:sub(1, 1) == '/' or path:sub(1, 1) == '.' or path:sub(2, 2) == ':') then - path = './' .. path - end - if not preprocess_cache[path] then - local body --- @type string - body, previous_defines = Preprocess.preprocess(previous_defines, path) - -- format it (so that the lines are "unique" statements), also filter out - -- Objective-C blocks - if os.getenv('NVIM_TEST_PRINT_I') == '1' then - local lnum = 0 - for line in body:gmatch('[^\n]+') do - lnum = lnum + 1 - print(lnum, line) - end - end - body = formatc(body) - body = filter_complex_blocks(body) - -- add the formatted lines to a set - local new_cdefs = Set:new() - for line in body:gmatch('[^\r\n]+') do - line = trim(line) - -- give each #pragma pack a unique id, so that they don't get removed - -- if they are inserted into the set - -- (they are needed in the right order with the struct definitions, - -- otherwise luajit has wrong memory layouts for the structs) - if line:match('#pragma%s+pack') then - --- @type string - line = line .. ' // ' .. pragma_pack_id - pragma_pack_id = pragma_pack_id + 1 - end - new_cdefs:add(line) - end - - -- subtract the lines we've already imported from the new lines, then add - -- the new unique lines to the old lines (so they won't be imported again) - new_cdefs:diff(cdefs) - cdefs:union(new_cdefs) - -- request a sorted version of the new lines (same relative order as the - -- original preprocessed file) and feed that to the LuaJIT ffi - local new_lines = new_cdefs:to_table() - if os.getenv('NVIM_TEST_PRINT_CDEF') == '1' then - for lnum, line in ipairs(new_lines) do - print(lnum, line) - end - end - body = table.concat(new_lines, '\n') - - preprocess_cache[path] = body - end - cimportstr(preprocess_cache, path) - end - return lib -end - -local function cimport_immediate(...) - local saved_pid = child_pid - child_pid = 0 - local err, emsg = pcall(cimport, ...) - child_pid = saved_pid - if not err then - io.stderr:write(tostring(emsg) .. '\n') - assert(false) - else - return lib - end -end - ---- @param preprocess_cache table<string,string[]> ---- @param path string -local function _cimportstr(preprocess_cache, path) - if imported:contains(path) then - return lib - end - local body = preprocess_cache[path] - if body == '' then - return lib - end - cdef(body) - imported:add(path) - - return lib -end - -if is_child_cdefs() then - cimportstr = child_call(_cimportstr, lib) -else - cimportstr = _cimportstr -end - -local function alloc_log_new() - local log = { - log = {}, --- @type ChildCallLog[] - lib = cimport('./src/nvim/memory.h'), --- @type table<string,function> - original_functions = {}, --- @type table<string,function> - null = { ['\0:is_null'] = true }, - } - - local allocator_functions = { 'malloc', 'free', 'calloc', 'realloc' } - - function log:save_original_functions() - for _, funcname in ipairs(allocator_functions) do - if not self.original_functions[funcname] then - self.original_functions[funcname] = self.lib['mem_' .. funcname] - end - end - end - - log.save_original_functions = child_call(log.save_original_functions) - - function log:set_mocks() - for _, k in ipairs(allocator_functions) do - do - local kk = k - self.lib['mem_' .. k] = function(...) - --- @type ChildCallLog - local log_entry = { func = kk, args = { ... } } - self.log[#self.log + 1] = log_entry - if kk == 'free' then - self.original_functions[kk](...) - else - log_entry.ret = self.original_functions[kk](...) - end - for i, v in ipairs(log_entry.args) do - if v == nil then - -- XXX This thing thinks that {NULL} ~= {NULL}. - log_entry.args[i] = self.null - end - end - if self.hook then - self:hook(log_entry) - end - if log_entry.ret then - return log_entry.ret - end - end - end - end - end - - log.set_mocks = child_call(log.set_mocks) - - function log:clear() - self.log = {} - end - - function log:check(exp) - eq(exp, self.log) - self:clear() - end - - function log:clear_tmp_allocs(clear_null_frees) - local toremove = {} --- @type integer[] - local allocs = {} --- @type table<string,integer> - for i, v in ipairs(self.log) do - if v.func == 'malloc' or v.func == 'calloc' then - allocs[tostring(v.ret)] = i - elseif v.func == 'realloc' or v.func == 'free' then - if allocs[tostring(v.args[1])] then - toremove[#toremove + 1] = allocs[tostring(v.args[1])] - if v.func == 'free' then - toremove[#toremove + 1] = i - end - elseif clear_null_frees and v.args[1] == self.null then - toremove[#toremove + 1] = i - end - if v.func == 'realloc' then - allocs[tostring(v.ret)] = i - end - end - end - table.sort(toremove) - for i = #toremove, 1, -1 do - table.remove(self.log, toremove[i]) - end - end - - function log:setup() - log:save_original_functions() - log:set_mocks() - end - - function log:before_each() end - - function log:after_each() end - - log:setup() - - return log -end - --- take a pointer to a C-allocated string and return an interned --- version while also freeing the memory -local function internalize(cdata, len) - ffi.gc(cdata, ffi.C.free) - return ffi.string(cdata, len) -end - -local cstr = ffi.typeof('char[?]') -local function to_cstr(string) - return cstr(#string + 1, string) -end - -cimport_immediate('./test/unit/fixtures/posix.h') - -local sc = {} - -function sc.fork() - return tonumber(ffi.C.fork()) -end - -function sc.pipe() - local ret = ffi.new('int[2]', { -1, -1 }) - ffi.errno(0) - local res = ffi.C.pipe(ret) - if res ~= 0 then - local err = ffi.errno(0) - assert(res == 0, ('pipe() error: %u: %s'):format(err, ffi.string(ffi.C.strerror(err)))) - end - assert(ret[0] ~= -1 and ret[1] ~= -1) - return ret[0], ret[1] -end - ---- @return string -function sc.read(rd, len) - local ret = ffi.new('char[?]', len, { 0 }) - local total_bytes_read = 0 - ffi.errno(0) - while total_bytes_read < len do - local bytes_read = - tonumber(ffi.C.read(rd, ffi.cast('void*', ret + total_bytes_read), len - total_bytes_read)) - if bytes_read == -1 then - local err = ffi.errno(0) - if err ~= ffi.C.kPOSIXErrnoEINTR then - assert(false, ('read() error: %u: %s'):format(err, ffi.string(ffi.C.strerror(err)))) - end - elseif bytes_read == 0 then - break - else - total_bytes_read = total_bytes_read + bytes_read - end - end - return ffi.string(ret, total_bytes_read) -end - -function sc.write(wr, s) - local wbuf = to_cstr(s) - local total_bytes_written = 0 - ffi.errno(0) - while total_bytes_written < #s do - local bytes_written = tonumber( - ffi.C.write(wr, ffi.cast('void*', wbuf + total_bytes_written), #s - total_bytes_written) - ) - if bytes_written == -1 then - local err = ffi.errno(0) - if err ~= ffi.C.kPOSIXErrnoEINTR then - assert( - false, - ("write() error: %u: %s ('%s')"):format(err, ffi.string(ffi.C.strerror(err)), s) - ) - end - elseif bytes_written == 0 then - break - else - total_bytes_written = total_bytes_written + bytes_written - end - end - return total_bytes_written -end - -sc.close = ffi.C.close - ---- @param pid integer ---- @return integer -function sc.wait(pid) - ffi.errno(0) - local stat_loc = ffi.new('int[1]', { 0 }) - while true do - local r = ffi.C.waitpid(pid, stat_loc, ffi.C.kPOSIXWaitWUNTRACED) - if r == -1 then - local err = ffi.errno(0) - if err == ffi.C.kPOSIXErrnoECHILD then - break - elseif err ~= ffi.C.kPOSIXErrnoEINTR then - assert(false, ('waitpid() error: %u: %s'):format(err, ffi.string(ffi.C.strerror(err)))) - end - else - assert(r == pid) - end - end - return stat_loc[0] -end - -sc.exit = ffi.C._exit - ---- @param lst string[] ---- @return string -local function format_list(lst) - local ret = {} --- @type string[] - for _, v in ipairs(lst) do - ret[#ret + 1] = assert:format({ v, n = 1 })[1] - end - return table.concat(ret, ', ') -end - -if os.getenv('NVIM_TEST_PRINT_SYSCALLS') == '1' then - for k_, v_ in pairs(sc) do - (function(k, v) - sc[k] = function(...) - local rets = { v(...) } - io.stderr:write(('%s(%s) = %s\n'):format(k, format_list({ ... }), format_list(rets))) - return unpack(rets) - end - end)(k_, v_) - end -end - -local function just_fail(_) - return false -end -say:set('assertion.just_fail.positive', '%s') -say:set('assertion.just_fail.negative', '%s') -assert:register( - 'assertion', - 'just_fail', - just_fail, - 'assertion.just_fail.positive', - 'assertion.just_fail.negative' -) - -local hook_fnamelen = 30 -local hook_sfnamelen = 30 -local hook_numlen = 5 -local hook_msglen = 1 + 1 + 1 + (1 + hook_fnamelen) + (1 + hook_sfnamelen) + (1 + hook_numlen) + 1 - -local tracehelp = dedent([[ - Trace: either in the format described below or custom debug output starting - with `>`. Latter lines still have the same width in byte. - - ┌ Trace type: _r_eturn from function , function _c_all, _l_ine executed, - │ _t_ail return, _C_ount (should not actually appear), - │ _s_aved from previous run for reference, _>_ for custom debug - │ output. - │┏ Function type: _L_ua function, _C_ function, _m_ain part of chunk, - │┃ function that did _t_ail call. - │┃┌ Function name type: _g_lobal, _l_ocal, _m_ethod, _f_ield, _u_pvalue, - │┃│ space for unknown. - │┃│ ┏ Source file name ┌ Function name ┏ Line - │┃│ ┃ (trunc to 30 bytes, no .lua) │ (truncated to last 30 bytes) ┃ number - CWN SSSSSSSSSSSSSSSSSSSSSSSSSSSSSS:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:LLLLL\n -]]) - -local function child_sethook(wr) - local trace_level_str = os.getenv('NVIM_TEST_TRACE_LEVEL') - local trace_level = 0 - if trace_level_str and trace_level_str ~= '' then - --- @type number - trace_level = assert(tonumber(trace_level_str)) - end - - if trace_level <= 0 then - return - end - - local trace_only_c = trace_level <= 1 - --- @type debuginfo?, string?, integer - local prev_info, prev_reason, prev_lnum - - --- @param reason string - --- @param lnum integer - --- @param use_prev boolean - local function hook(reason, lnum, use_prev) - local info = nil --- @type debuginfo? - if use_prev then - info = prev_info - elseif reason ~= 'tail return' then -- tail return - info = debug.getinfo(2, 'nSl') - end - - if trace_only_c and (not info or info.what ~= 'C') and not use_prev then - --- @cast info -nil - if info.source:sub(-9) == '_spec.lua' then - prev_info = info - prev_reason = 'saved' - prev_lnum = lnum - end - return - end - if trace_only_c and not use_prev and prev_reason then - hook(prev_reason, prev_lnum, true) - prev_reason = nil - end - - local whatchar = ' ' - local namewhatchar = ' ' - local funcname = '' - local source = '' - local msgchar = reason:sub(1, 1) - - if reason == 'count' then - msgchar = 'C' - end - - if info then - funcname = (info.name or ''):sub(1, hook_fnamelen) - whatchar = info.what:sub(1, 1) - namewhatchar = info.namewhat:sub(1, 1) - if namewhatchar == '' then - namewhatchar = ' ' - end - source = info.source - if source:sub(1, 1) == '@' then - if source:sub(-4, -1) == '.lua' then - source = source:sub(1, -5) - end - source = source:sub(-hook_sfnamelen, -1) - end - lnum = lnum or info.currentline - end - - -- assert(-1 <= lnum and lnum <= 99999) - local lnum_s = lnum == -1 and 'nknwn' or ('%u'):format(lnum) - --- @type string - local msg = ( -- lua does not support %* - '' - .. msgchar - .. whatchar - .. namewhatchar - .. ' ' - .. source - .. (' '):rep(hook_sfnamelen - #source) - .. ':' - .. funcname - .. (' '):rep(hook_fnamelen - #funcname) - .. ':' - .. ('0'):rep(hook_numlen - #lnum_s) - .. lnum_s - .. '\n' - ) - -- eq(hook_msglen, #msg) - sc.write(wr, msg) - end - debug.sethook(hook, 'crl') -end - -local trace_end_msg = ('E%s\n'):format((' '):rep(hook_msglen - 2)) - ---- @type function -local _debug_log - -local debug_log = only_separate(function(...) - return _debug_log(...) -end) - -local function itp_child(wr, func) - --- @param s string - _debug_log = function(s) - s = s:sub(1, hook_msglen - 2) - sc.write(wr, '>' .. s .. (' '):rep(hook_msglen - 2 - #s) .. '\n') - end - local status, result = pcall(init) - if status then - collectgarbage('stop') - child_sethook(wr) - status, result = pcall(func) - debug.sethook() - end - sc.write(wr, trace_end_msg) - if not status then - local emsg = tostring(result) - if #emsg > 99999 then - emsg = emsg:sub(1, 99999) - end - sc.write(wr, ('-\n%05u\n%s'):format(#emsg, emsg)) - deinit() - else - sc.write(wr, '+\n') - deinit() - end - collectgarbage('restart') - collectgarbage() - sc.write(wr, '$\n') - sc.close(wr) - sc.exit(status and 0 or 1) -end - -local function check_child_err(rd) - local trace = {} --- @type string[] - local did_traceline = false - local maxtrace = tonumber(os.getenv('NVIM_TEST_MAXTRACE')) or 1024 - while true do - local traceline = sc.read(rd, hook_msglen) - if #traceline ~= hook_msglen then - if #traceline == 0 then - break - else - trace[#trace + 1] = 'Partial read: <' .. trace .. '>\n' - end - end - if traceline == trace_end_msg then - did_traceline = true - break - end - trace[#trace + 1] = traceline - if #trace > maxtrace then - table.remove(trace, 1) - end - end - local res = sc.read(rd, 2) - if #res == 2 then - local err = '' - if res ~= '+\n' then - eq('-\n', res) - local len_s = sc.read(rd, 5) - local len = tonumber(len_s) - neq(0, len) - if os.getenv('NVIM_TEST_TRACE_ON_ERROR') == '1' and #trace ~= 0 then - --- @type string - err = '\nTest failed, trace:\n' .. tracehelp - for _, traceline in ipairs(trace) do - --- @type string - err = err .. traceline - end - end - --- @type string - err = err .. sc.read(rd, len + 1) - end - local eres = sc.read(rd, 2) - if eres ~= '$\n' then - if #trace == 0 then - err = '\nTest crashed, no trace available (check NVIM_TEST_TRACE_LEVEL)\n' - else - err = '\nTest crashed, trace:\n' .. tracehelp - for i = 1, #trace do - err = err .. trace[i] - end - end - if not did_traceline then - --- @type string - err = err .. '\nNo end of trace occurred' - end - local cc_err, cc_emsg = pcall(check_cores, paths.test_luajit_prg, true) - if not cc_err then - --- @type string - err = err .. '\ncheck_cores failed: ' .. cc_emsg - end - end - if err ~= '' then - assert.just_fail(err) - end - end -end - -local function itp_parent(rd, pid, allow_failure, location) - local ok, emsg = pcall(check_child_err, rd) - local status = sc.wait(pid) - sc.close(rd) - if not ok then - if allow_failure then - io.stderr:write('Errorred out (' .. status .. '):\n' .. tostring(emsg) .. '\n') - os.execute([[ - sh -c "source ci/common/test.sh - check_core_dumps --delete \"]] .. paths.test_luajit_prg .. [[\""]]) - else - error(tostring(emsg) .. '\nexit code: ' .. status) - end - elseif status ~= 0 then - if not allow_failure then - error('child process errored out with status ' .. status .. '!\n\n' .. location) - end - end -end - -local function gen_itp(it) - child_calls_mod = {} - child_calls_mod_once = {} - child_cleanups_mod_once = {} - preprocess_cache_mod = map(function(v) - return v - end, preprocess_cache_init) - previous_defines_mod = previous_defines_init - cdefs_mod = cdefs_init:copy() - local function itp(name, func, allow_failure) - if allow_failure and os.getenv('NVIM_TEST_RUN_FAILING_TESTS') ~= '1' then - -- FIXME Fix tests with this true - return - end - - -- Pre-emptively calculating error location, wasteful, ugh! - -- But the way this code messes around with busted implies the real location is strictly - -- not available in the parent when an actual error occurs. so we have to do this here. - local location = debug.traceback() - it(name, function() - local rd, wr = sc.pipe() - child_pid = sc.fork() - if child_pid == 0 then - sc.close(rd) - itp_child(wr, func) - else - sc.close(wr) - local saved_child_pid = child_pid - child_pid = nil - itp_parent(rd, saved_child_pid, allow_failure, location) - end - end) - end - return itp -end - -local function cppimport(path) - return cimport(paths.test_source_path .. '/test/includes/pre/' .. path) -end - -cimport( - './src/nvim/types_defs.h', - './src/nvim/main.h', - './src/nvim/os/time.h', - './src/nvim/os/fs.h' -) - -local function conv_enum(etab, eval) - local n = tonumber(eval) - return etab[n] or n -end - -local function array_size(arr) - return ffi.sizeof(arr) / ffi.sizeof(arr[0]) -end - -local function kvi_size(kvi) - return array_size(kvi.init_array) -end - -local function kvi_init(kvi) - kvi.capacity = kvi_size(kvi) - kvi.items = kvi.init_array - return kvi -end - -local function kvi_destroy(kvi) - if kvi.items ~= kvi.init_array then - lib.xfree(kvi.items) - end -end - -local function kvi_new(ct) - return kvi_init(ffi.new(ct)) -end - -local function make_enum_conv_tab(m, values, skip_pref, set_cb) - child_call_once(function() - local ret = {} - for _, v in ipairs(values) do - local str_v = v - if v:sub(1, #skip_pref) == skip_pref then - str_v = v:sub(#skip_pref + 1) - end - ret[tonumber(m[v])] = str_v - end - set_cb(ret) - end) -end - -local function ptr2addr(ptr) - return tonumber(ffi.cast('intptr_t', ffi.cast('void *', ptr))) -end - -local s = ffi.new('char[64]', { 0 }) - -local function ptr2key(ptr) - ffi.C.snprintf(s, ffi.sizeof(s), '%p', ffi.cast('void *', ptr)) - return ffi.string(s) -end - -local function is_asan() - cimport('./src/nvim/version.h') - local status, res = pcall(function() - return lib.version_cflags - end) - if status then - return ffi.string(res):match('-fsanitize=[a-z,]*address') - else - return false - end -end - ---- @class test.unit.helpers.module -local module = { - cimport = cimport, - cppimport = cppimport, - internalize = internalize, - ffi = ffi, - lib = lib, - cstr = cstr, - to_cstr = to_cstr, - NULL = ffi.cast('void*', 0), - OK = 1, - FAIL = 0, - alloc_log_new = alloc_log_new, - gen_itp = gen_itp, - only_separate = only_separate, - child_call_once = child_call_once, - child_cleanup_once = child_cleanup_once, - sc = sc, - conv_enum = conv_enum, - array_size = array_size, - kvi_destroy = kvi_destroy, - kvi_size = kvi_size, - kvi_init = kvi_init, - kvi_new = kvi_new, - make_enum_conv_tab = make_enum_conv_tab, - ptr2addr = ptr2addr, - ptr2key = ptr2key, - debug_log = debug_log, - is_asan = is_asan, -} ---- @class test.unit.helpers: test.unit.helpers.module, test.helpers -module = vim.tbl_extend('error', module, global_helpers) - -return function() - return module -end diff --git a/test/unit/indent_spec.lua b/test/unit/indent_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local to_cstr = helpers.to_cstr -local ffi = helpers.ffi -local eq = helpers.eq +local to_cstr = t.to_cstr +local ffi = t.ffi +local eq = t.eq -local indent = helpers.cimport('./src/nvim/indent.h') -local globals = helpers.cimport('./src/nvim/globals.h') +local indent = t.cimport('./src/nvim/indent.h') +local globals = t.cimport('./src/nvim/globals.h') describe('get_sts_value', function() itp([[returns 'softtabstop' when it is non-negative]], function() diff --git a/test/unit/keycodes_spec.lua b/test/unit/keycodes_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local ffi = helpers.ffi -local eq = helpers.eq -local neq = helpers.neq +local ffi = t.ffi +local eq = t.eq +local neq = t.neq -local keycodes = helpers.cimport('./src/nvim/keycodes.h') -local NULL = helpers.NULL +local keycodes = t.cimport('./src/nvim/keycodes.h') +local NULL = t.NULL describe('keycodes.c', function() describe('find_special_key()', function() diff --git a/test/unit/marktree_spec.lua b/test/unit/marktree_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local ffi = helpers.ffi -local eq = helpers.eq -local ok = helpers.ok +local ffi = t.ffi +local eq = t.eq +local ok = t.ok -local lib = helpers.cimport('./src/nvim/marktree.h') +local lib = t.cimport('./src/nvim/marktree.h') -local function tablelength(t) +local function tablelength(tbl) local count = 0 - for _ in pairs(t) do + for _ in pairs(tbl) do count = count + 1 end return count @@ -460,7 +460,7 @@ describe('marktree', function() local ids = {} -- too much overhead on ASAN - local size_factor = helpers.is_asan() and 3 or 10 + local size_factor = t.is_asan() and 3 or 10 local at_row = {} for i = 1, 10 do @@ -528,7 +528,7 @@ describe('marktree', function() local tree = ffi.new('MarkTree[1]') -- zero initialized by luajit -- too much overhead on ASAN - local size_factor = helpers.is_asan() and 3 or 10 + local size_factor = t.is_asan() and 3 or 10 local at_row = {} for i = 1, 10 do diff --git a/test/unit/mbyte_spec.lua b/test/unit/mbyte_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local ffi = helpers.ffi -local eq = helpers.eq +local ffi = t.ffi +local eq = t.eq -local lib = helpers.cimport('./src/nvim/mbyte.h', './src/nvim/charset.h', './src/nvim/grid.h') +local lib = t.cimport('./src/nvim/mbyte.h', './src/nvim/charset.h', './src/nvim/grid.h') describe('mbyte', function() -- Convert from bytes to string @@ -205,7 +205,7 @@ describe('mbyte', function() end) describe('utf_cp_bounds_len', function() - local to_cstr = helpers.to_cstr + local to_cstr = t.to_cstr local tests = { { diff --git a/test/unit/memory_spec.lua b/test/unit/memory_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local cimport = helpers.cimport -local cstr = helpers.cstr -local eq = helpers.eq -local ffi = helpers.ffi -local to_cstr = helpers.to_cstr +local cimport = t.cimport +local cstr = t.cstr +local eq = t.eq +local ffi = t.ffi +local to_cstr = t.to_cstr local cimp = cimport('stdlib.h', './src/nvim/memory.h') diff --git a/test/unit/message_spec.lua b/test/unit/message_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local ffi = helpers.ffi -local eq = helpers.eq -local to_cstr = helpers.to_cstr +local ffi = t.ffi +local eq = t.eq +local to_cstr = t.to_cstr -local cimp = helpers.cimport('./src/nvim/message.h', './src/nvim/memory.h', './src/nvim/strings.h') +local cimp = t.cimport('./src/nvim/message.h', './src/nvim/memory.h', './src/nvim/strings.h') describe('trunc_string', function() local buflen = 40 @@ -33,26 +33,26 @@ describe('trunc_string', function() { ['desc'] = 'by copy', ['func'] = test_copy }, } - for _, t in ipairs(permutations) do - describe('populates buf ' .. t.desc, function() + for _, q in ipairs(permutations) do + describe('populates buf ' .. q.desc, function() itp('with a small string', function() - t.func('text', 'text') + q.func('text', 'text') end) itp('with a medium string', function() - t.func('a short text', 'a short text') + q.func('a short text', 'a short text') end) itp('with a string of length == 1/2 room', function() - t.func('a text that fits', 'a text that fits', 34) + q.func('a text that fits', 'a text that fits', 34) end) itp('with a string exactly the truncate size', function() - t.func('a text tha just fits', 'a text tha just fits') + q.func('a text tha just fits', 'a text tha just fits') end) itp('with a string that must be truncated', function() - t.func('a text that nott fits', 'a text t...nott fits') + q.func('a text that nott fits', 'a text t...nott fits') end) end) end diff --git a/test/unit/msgpack_spec.lua b/test/unit/msgpack_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.unit.helpers')(after_each) -local cimport = helpers.cimport -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local cimport = t.cimport +local itp = t.gen_itp(it) local lib = cimport('./src/nvim/msgpack_rpc/unpacker.h', './src/nvim/memory.h') -local ffi = helpers.ffi -local eq = helpers.eq -local to_cstr = helpers.to_cstr +local ffi = t.ffi +local eq = t.eq +local to_cstr = t.to_cstr --- @class Unpacker --- @field read_ptr ffi.cdata* diff --git a/test/unit/multiqueue_spec.lua b/test/unit/multiqueue_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local child_call_once = helpers.child_call_once -local cimport = helpers.cimport -local ffi = helpers.ffi -local eq = helpers.eq +local child_call_once = t.child_call_once +local cimport = t.cimport +local ffi = t.ffi +local eq = t.eq local multiqueue = cimport('./test/unit/fixtures/multiqueue.h') diff --git a/test/unit/optionstr_spec.lua b/test/unit/optionstr_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local to_cstr = helpers.to_cstr -local eq = helpers.eq +local to_cstr = t.to_cstr +local eq = t.eq -local optionstr = helpers.cimport('./src/nvim/optionstr.h') +local optionstr = t.cimport('./src/nvim/optionstr.h') local check_ff_value = function(ff) return optionstr.check_ff_value(to_cstr(ff)) diff --git a/test/unit/os/env_spec.lua b/test/unit/os/env_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) - -local cimport = helpers.cimport -local eq = helpers.eq -local neq = helpers.neq -local ffi = helpers.ffi -local cstr = helpers.cstr -local to_cstr = helpers.to_cstr -local NULL = helpers.NULL +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) + +local cimport = t.cimport +local eq = t.eq +local neq = t.neq +local ffi = t.ffi +local cstr = t.cstr +local to_cstr = t.to_cstr +local NULL = t.NULL local OK = 0 local cimp = cimport('./src/nvim/os/os.h') diff --git a/test/unit/os/fileio_spec.lua b/test/unit/os/fileio_spec.lua @@ -1,13 +1,13 @@ local uv = vim.uv -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) - -local eq = helpers.eq -local ffi = helpers.ffi -local cimport = helpers.cimport -local cppimport = helpers.cppimport -local mkdir = helpers.mkdir +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) + +local eq = t.eq +local ffi = t.ffi +local cimport = t.cimport +local cppimport = t.cppimport +local mkdir = t.mkdir local m = cimport('./src/nvim/os/os.h', './src/nvim/os/fileio.h') cppimport('fcntl.h') diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua @@ -1,22 +1,22 @@ local uv = vim.uv local bit = require('bit') -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) - -local cimport = helpers.cimport -local cppimport = helpers.cppimport -local internalize = helpers.internalize -local ok = helpers.ok -local eq = helpers.eq -local neq = helpers.neq -local ffi = helpers.ffi -local cstr = helpers.cstr -local to_cstr = helpers.to_cstr -local OK = helpers.OK -local FAIL = helpers.FAIL -local NULL = helpers.NULL -local mkdir = helpers.mkdir +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) + +local cimport = t.cimport +local cppimport = t.cppimport +local internalize = t.internalize +local ok = t.ok +local eq = t.eq +local neq = t.neq +local ffi = t.ffi +local cstr = t.cstr +local to_cstr = t.to_cstr +local OK = t.OK +local FAIL = t.FAIL +local NULL = t.NULL +local mkdir = t.mkdir local endswith = vim.endswith local NODE_NORMAL = 0 diff --git a/test/unit/os/shell_spec.lua b/test/unit/os/shell_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) -local cimported = helpers.cimport( +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) +local cimported = t.cimport( './src/nvim/os/shell.h', './src/nvim/option_vars.h', './src/nvim/main.h', './src/nvim/memory.h' ) -local ffi, eq = helpers.ffi, helpers.eq -local intern = helpers.internalize -local to_cstr = helpers.to_cstr +local ffi, eq = t.ffi, t.eq +local intern = t.internalize +local to_cstr = t.to_cstr local NULL = ffi.cast('void *', 0) describe('shell functions', function() diff --git a/test/unit/os/users_spec.lua b/test/unit/os/users_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local cimport = helpers.cimport -local eq = helpers.eq -local ffi = helpers.ffi -local lib = helpers.lib -local NULL = helpers.NULL -local OK = helpers.OK -local FAIL = helpers.FAIL +local cimport = t.cimport +local eq = t.eq +local ffi = t.ffi +local lib = t.lib +local NULL = t.NULL +local OK = t.OK +local FAIL = t.FAIL local users = cimport('./src/nvim/os/os.h', 'unistd.h') diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua @@ -1,17 +1,17 @@ local uv = vim.uv -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) - -local cimport = helpers.cimport -local eq = helpers.eq -local neq = helpers.neq -local ffi = helpers.ffi -local cstr = helpers.cstr -local to_cstr = helpers.to_cstr -local NULL = helpers.NULL -local OK = helpers.OK -local FAIL = helpers.FAIL -local mkdir = helpers.mkdir +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) + +local cimport = t.cimport +local eq = t.eq +local neq = t.neq +local ffi = t.ffi +local cstr = t.cstr +local to_cstr = t.to_cstr +local NULL = t.NULL +local OK = t.OK +local FAIL = t.FAIL +local mkdir = t.mkdir cimport('string.h') local cimp = cimport('./src/nvim/os/os.h', './src/nvim/path.h') @@ -380,8 +380,8 @@ describe('path.c', function() return buf, result end - local function get_buf_len(s, t) - return math.max(string.len(s), string.len(t)) + 1 + local function get_buf_len(s, q) + return math.max(string.len(s), string.len(q)) + 1 end itp('fails if given filename is NULL', function() diff --git a/test/unit/preload.lua b/test/unit/preload.lua @@ -2,5 +2,5 @@ -- Busted started doing this to help provide more isolation. See issue #62 -- for more information about this. local ffi = require('ffi') -local helpers = require('test.unit.helpers')(nil) +local t = require('test.unit.testutil')(nil) local preprocess = require('test.unit.preprocess') diff --git a/test/unit/preprocess.lua b/test/unit/preprocess.lua @@ -2,10 +2,10 @@ -- windows, will probably need quite a bit of adjustment to run there. local ffi = require('ffi') -local global_helpers = require('test.helpers') +local global_t = require('test.testutil') -local argss_to_cmd = global_helpers.argss_to_cmd -local repeated_read_cmd = global_helpers.repeated_read_cmd +local argss_to_cmd = global_t.argss_to_cmd +local repeated_read_cmd = global_t.repeated_read_cmd --- @alias Compiler {path: string[], type: string} diff --git a/test/unit/profile_spec.lua b/test/unit/profile_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local cimport = helpers.cimport -local ffi = helpers.ffi -local eq = helpers.eq -local neq = helpers.neq +local cimport = t.cimport +local ffi = t.ffi +local eq = t.eq +local neq = t.neq local prof = cimport('./src/nvim/profile.h') @@ -13,13 +13,13 @@ local function split(inputstr, sep) sep = '%s' end - local t, i = {}, 1 + local q, i = {}, 1 for str in string.gmatch(inputstr, '([^' .. sep .. ']+)') do - t[i] = str + q[i] = str i = i + 1 end - return t + return q end local function trim(s) @@ -72,8 +72,8 @@ describe('profiling related functions', function() local function profile_start() return prof.profile_start() end - local function profile_end(t) - return prof.profile_end(t) + local function profile_end(q) + return prof.profile_end(q) end local function profile_zero() return prof.profile_zero() @@ -81,8 +81,8 @@ describe('profiling related functions', function() local function profile_setlimit(ms) return prof.profile_setlimit(ms) end - local function profile_passed_limit(t) - return prof.profile_passed_limit(t) + local function profile_passed_limit(q) + return prof.profile_passed_limit(q) end local function profile_add(t1, t2) return prof.profile_add(t1, t2) @@ -90,8 +90,8 @@ describe('profiling related functions', function() local function profile_sub(t1, t2) return prof.profile_sub(t1, t2) end - local function profile_divide(t, cnt) - return prof.profile_divide(t, cnt) + local function profile_divide(q, cnt) + return prof.profile_divide(q, cnt) end local function profile_cmp(t1, t2) return prof.profile_cmp(t1, t2) @@ -99,12 +99,12 @@ describe('profiling related functions', function() local function profile_equal(t1, t2) return prof.profile_equal(t1, t2) end - local function profile_msg(t) - return ffi.string(prof.profile_msg(t)) + local function profile_msg(q) + return ffi.string(prof.profile_msg(q)) end - local function toseconds(t) -- luacheck: ignore - local str = trim(profile_msg(t)) + local function toseconds(q) -- luacheck: ignore + local str = trim(profile_msg(q)) local spl = split(str, '.') local s, us = spl[1], spl[2] return tonumber(s) + tonumber(us) / 1000000 diff --git a/test/unit/rbuffer_spec.lua b/test/unit/rbuffer_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local eq = helpers.eq -local ffi = helpers.ffi -local cstr = helpers.cstr -local to_cstr = helpers.to_cstr -local child_call_once = helpers.child_call_once +local eq = t.eq +local ffi = t.ffi +local cstr = t.cstr +local to_cstr = t.to_cstr +local child_call_once = t.child_call_once -local rbuffer = helpers.cimport('./test/unit/fixtures/rbuffer.h') +local rbuffer = t.cimport('./test/unit/fixtures/rbuffer.h') describe('rbuffer functions', function() local capacity = 16 diff --git a/test/unit/search_spec.lua b/test/unit/search_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local to_cstr = helpers.to_cstr -local eq = helpers.eq +local to_cstr = t.to_cstr +local eq = t.eq -local search = helpers.cimport('./src/nvim/search.h') -local globals = helpers.cimport('./src/nvim/globals.h') -local ffi = helpers.ffi +local search = t.cimport('./src/nvim/search.h') +local globals = t.cimport('./src/nvim/globals.h') +local ffi = t.ffi itp('pat_has_uppercase', function() -- works on empty string @@ -42,7 +42,7 @@ describe('search_regcomp', function() end local get_search_pat = function() - return helpers.internalize(search.get_search_pat()) + return t.internalize(search.get_search_pat()) end itp('accepts regexp pattern with invalid utf', function() diff --git a/test/unit/statusline_spec.lua b/test/unit/statusline_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local to_cstr = helpers.to_cstr -local get_str = helpers.ffi.string -local eq = helpers.eq -local NULL = helpers.NULL +local to_cstr = t.to_cstr +local get_str = t.ffi.string +local eq = t.eq +local NULL = t.NULL -local buffer = helpers.cimport('./src/nvim/buffer.h') -local globals = helpers.cimport('./src/nvim/globals.h') -local stl = helpers.cimport('./src/nvim/statusline.h') -local grid = helpers.cimport('./src/nvim/grid.h') +local buffer = t.cimport('./src/nvim/buffer.h') +local globals = t.cimport('./src/nvim/globals.h') +local stl = t.cimport('./src/nvim/statusline.h') +local grid = t.cimport('./src/nvim/grid.h') describe('build_stl_str_hl', function() local buffer_byte_size = 100 diff --git a/test/unit/strings_spec.lua b/test/unit/strings_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local cimport = helpers.cimport -local eq = helpers.eq -local ffi = helpers.ffi -local to_cstr = helpers.to_cstr +local cimport = t.cimport +local eq = t.eq +local ffi = t.ffi +local to_cstr = t.to_cstr local strings = cimport('stdlib.h', './src/nvim/strings.h', './src/nvim/memory.h') @@ -261,7 +261,7 @@ end) describe('reverse_text', function() local reverse_text = function(str) - return helpers.internalize(strings.reverse_text(to_cstr(str))) + return t.internalize(strings.reverse_text(to_cstr(str))) end itp('handles empty string', function() diff --git a/test/unit/tempfile_spec.lua b/test/unit/tempfile_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) -local eq = helpers.eq -local neq = helpers.neq -local cimport = helpers.cimport -local child_call_once = helpers.child_call_once -local child_cleanup_once = helpers.child_cleanup_once +local eq = t.eq +local neq = t.neq +local cimport = t.cimport +local child_call_once = t.child_call_once +local child_cleanup_once = t.child_cleanup_once local lib = cimport('./src/nvim/os/os.h', './src/nvim/fileio.h') @@ -19,7 +19,7 @@ describe('tempfile related functions', function() end) local vim_gettempdir = function() - return helpers.ffi.string(lib.vim_gettempdir()) + return t.ffi.string(lib.vim_gettempdir()) end describe('vim_gettempdir', function() @@ -28,7 +28,7 @@ describe('tempfile related functions', function() assert.True(dir ~= nil and dir:len() > 0) -- os_file_is_writable returns 2 for a directory which we have rights -- to write into. - eq(2, lib.os_file_is_writable(helpers.to_cstr(dir))) + eq(2, lib.os_file_is_writable(t.to_cstr(dir))) for entry in vim.fs.dir(dir) do assert.True(entry == '.' or entry == '..') end @@ -41,7 +41,7 @@ describe('tempfile related functions', function() describe('vim_tempname', function() local vim_tempname = function() - return helpers.ffi.string(lib.vim_tempname()) + return t.ffi.string(lib.vim_tempname()) end itp('generate name of non-existing file', function() diff --git a/test/unit/testtest_spec.lua b/test/unit/testtest_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.unit.helpers')(after_each) +local t = require('test.unit.testutil')(after_each) local assert = require('luassert') -local itp = helpers.gen_itp(it) +local itp = t.gen_itp(it) -local sc = helpers.sc +local sc = t.sc -- All of the below tests must fail. Check how exactly they fail. if os.getenv('NVIM_TEST_RUN_TESTTEST') ~= '1' then diff --git a/test/unit/testutil.lua b/test/unit/testutil.lua @@ -0,0 +1,911 @@ +local ffi = require('ffi') +local formatc = require('test.unit.formatc') +local Set = require('test.unit.set') +local Preprocess = require('test.unit.preprocess') +local t_global = require('test.testutil') +local paths = t_global.paths +local assert = require('luassert') +local say = require('say') + +local check_cores = t_global.check_cores +local dedent = t_global.dedent +local neq = t_global.neq +local map = vim.tbl_map +local eq = t_global.eq +local trim = vim.trim + +-- add some standard header locations +for _, p in ipairs(paths.include_paths) do + Preprocess.add_to_include_path(p) +end + +local child_pid = nil --- @type integer? +--- @generic F: function +--- @param func F +--- @return F +local function only_separate(func) + return function(...) + if child_pid ~= 0 then + error('This function must be run in a separate process only') + end + return func(...) + end +end + +--- @class ChildCall +--- @field func function +--- @field args any[] + +--- @class ChildCallLog +--- @field func string +--- @field args any[] +--- @field ret any? + +local child_calls_init = {} --- @type ChildCall[] +local child_calls_mod = nil --- @type ChildCall[] +local child_calls_mod_once = nil --- @type ChildCall[]? + +local function child_call(func, ret) + return function(...) + local child_calls = child_calls_mod or child_calls_init + if child_pid ~= 0 then + child_calls[#child_calls + 1] = { func = func, args = { ... } } + return ret + else + return func(...) + end + end +end + +-- Run some code at the start of the child process, before running the test +-- itself. Is supposed to be run in `before_each`. +--- @param func function +local function child_call_once(func, ...) + if child_pid ~= 0 then + child_calls_mod_once[#child_calls_mod_once + 1] = { func = func, args = { ... } } + else + func(...) + end +end + +local child_cleanups_mod_once = nil --- @type ChildCall[]? + +-- Run some code at the end of the child process, before exiting. Is supposed to +-- be run in `before_each` because `after_each` is run after child has exited. +local function child_cleanup_once(func, ...) + local child_cleanups = child_cleanups_mod_once + if child_pid ~= 0 then + child_cleanups[#child_cleanups + 1] = { func = func, args = { ... } } + else + func(...) + end +end + +-- Unittests are run from debug nvim binary in lua interpreter mode. +local libnvim = ffi.C + +local lib = setmetatable({}, { + __index = only_separate(function(_, idx) + return libnvim[idx] + end), + __newindex = child_call(function(_, idx, val) + libnvim[idx] = val + end), +}) + +local init = only_separate(function() + for _, c in ipairs(child_calls_init) do + c.func(unpack(c.args)) + end + libnvim.event_init() + libnvim.early_init(nil) + if child_calls_mod then + for _, c in ipairs(child_calls_mod) do + c.func(unpack(c.args)) + end + end + if child_calls_mod_once then + for _, c in ipairs(child_calls_mod_once) do + c.func(unpack(c.args)) + end + child_calls_mod_once = nil + end +end) + +local deinit = only_separate(function() + if child_cleanups_mod_once then + for _, c in ipairs(child_cleanups_mod_once) do + c.func(unpack(c.args)) + end + child_cleanups_mod_once = nil + end +end) + +-- a Set that keeps around the lines we've already seen +local cdefs_init = Set:new() +local cdefs_mod = nil +local imported = Set:new() +local pragma_pack_id = 1 + +-- some things are just too complex for the LuaJIT C parser to digest. We +-- usually don't need them anyway. +--- @param body string +local function filter_complex_blocks(body) + local result = {} --- @type string[] + + for line in body:gmatch('[^\r\n]+') do + if + not ( + string.find(line, '(^)', 1, true) ~= nil + or string.find(line, '_ISwupper', 1, true) + or string.find(line, '_Float') + or string.find(line, '__s128') + or string.find(line, '__u128') + or string.find(line, 'msgpack_zone_push_finalizer') + or string.find(line, 'msgpack_unpacker_reserve_buffer') + or string.find(line, 'value_init_') + or string.find(line, 'UUID_NULL') -- static const uuid_t UUID_NULL = {...} + or string.find(line, 'inline _Bool') + ) + then + result[#result + 1] = line + end + end + + return table.concat(result, '\n') +end + +local cdef = ffi.cdef + +local cimportstr + +local previous_defines_init = [[ +typedef struct { char bytes[16]; } __attribute__((aligned(16))) __uint128_t; +typedef struct { char bytes[16]; } __attribute__((aligned(16))) __float128; +]] + +local preprocess_cache_init = {} --- @type table<string,string> +local previous_defines_mod = '' +local preprocess_cache_mod = nil --- @type table<string,string> + +local function is_child_cdefs() + return os.getenv('NVIM_TEST_MAIN_CDEFS') ~= '1' +end + +-- use this helper to import C files, you can pass multiple paths at once, +-- this helper will return the C namespace of the nvim library. +local function cimport(...) + local previous_defines --- @type string + local preprocess_cache --- @type table<string,string> + local cdefs + if is_child_cdefs() and preprocess_cache_mod then + preprocess_cache = preprocess_cache_mod + previous_defines = previous_defines_mod + cdefs = cdefs_mod + else + preprocess_cache = preprocess_cache_init + previous_defines = previous_defines_init + cdefs = cdefs_init + end + for _, path in ipairs({ ... }) do + if not (path:sub(1, 1) == '/' or path:sub(1, 1) == '.' or path:sub(2, 2) == ':') then + path = './' .. path + end + if not preprocess_cache[path] then + local body --- @type string + body, previous_defines = Preprocess.preprocess(previous_defines, path) + -- format it (so that the lines are "unique" statements), also filter out + -- Objective-C blocks + if os.getenv('NVIM_TEST_PRINT_I') == '1' then + local lnum = 0 + for line in body:gmatch('[^\n]+') do + lnum = lnum + 1 + print(lnum, line) + end + end + body = formatc(body) + body = filter_complex_blocks(body) + -- add the formatted lines to a set + local new_cdefs = Set:new() + for line in body:gmatch('[^\r\n]+') do + line = trim(line) + -- give each #pragma pack a unique id, so that they don't get removed + -- if they are inserted into the set + -- (they are needed in the right order with the struct definitions, + -- otherwise luajit has wrong memory layouts for the structs) + if line:match('#pragma%s+pack') then + --- @type string + line = line .. ' // ' .. pragma_pack_id + pragma_pack_id = pragma_pack_id + 1 + end + new_cdefs:add(line) + end + + -- subtract the lines we've already imported from the new lines, then add + -- the new unique lines to the old lines (so they won't be imported again) + new_cdefs:diff(cdefs) + cdefs:union(new_cdefs) + -- request a sorted version of the new lines (same relative order as the + -- original preprocessed file) and feed that to the LuaJIT ffi + local new_lines = new_cdefs:to_table() + if os.getenv('NVIM_TEST_PRINT_CDEF') == '1' then + for lnum, line in ipairs(new_lines) do + print(lnum, line) + end + end + body = table.concat(new_lines, '\n') + + preprocess_cache[path] = body + end + cimportstr(preprocess_cache, path) + end + return lib +end + +local function cimport_immediate(...) + local saved_pid = child_pid + child_pid = 0 + local err, emsg = pcall(cimport, ...) + child_pid = saved_pid + if not err then + io.stderr:write(tostring(emsg) .. '\n') + assert(false) + else + return lib + end +end + +--- @param preprocess_cache table<string,string[]> +--- @param path string +local function _cimportstr(preprocess_cache, path) + if imported:contains(path) then + return lib + end + local body = preprocess_cache[path] + if body == '' then + return lib + end + cdef(body) + imported:add(path) + + return lib +end + +if is_child_cdefs() then + cimportstr = child_call(_cimportstr, lib) +else + cimportstr = _cimportstr +end + +local function alloc_log_new() + local log = { + log = {}, --- @type ChildCallLog[] + lib = cimport('./src/nvim/memory.h'), --- @type table<string,function> + original_functions = {}, --- @type table<string,function> + null = { ['\0:is_null'] = true }, + } + + local allocator_functions = { 'malloc', 'free', 'calloc', 'realloc' } + + function log:save_original_functions() + for _, funcname in ipairs(allocator_functions) do + if not self.original_functions[funcname] then + self.original_functions[funcname] = self.lib['mem_' .. funcname] + end + end + end + + log.save_original_functions = child_call(log.save_original_functions) + + function log:set_mocks() + for _, k in ipairs(allocator_functions) do + do + local kk = k + self.lib['mem_' .. k] = function(...) + --- @type ChildCallLog + local log_entry = { func = kk, args = { ... } } + self.log[#self.log + 1] = log_entry + if kk == 'free' then + self.original_functions[kk](...) + else + log_entry.ret = self.original_functions[kk](...) + end + for i, v in ipairs(log_entry.args) do + if v == nil then + -- XXX This thing thinks that {NULL} ~= {NULL}. + log_entry.args[i] = self.null + end + end + if self.hook then + self:hook(log_entry) + end + if log_entry.ret then + return log_entry.ret + end + end + end + end + end + + log.set_mocks = child_call(log.set_mocks) + + function log:clear() + self.log = {} + end + + function log:check(exp) + eq(exp, self.log) + self:clear() + end + + function log:clear_tmp_allocs(clear_null_frees) + local toremove = {} --- @type integer[] + local allocs = {} --- @type table<string,integer> + for i, v in ipairs(self.log) do + if v.func == 'malloc' or v.func == 'calloc' then + allocs[tostring(v.ret)] = i + elseif v.func == 'realloc' or v.func == 'free' then + if allocs[tostring(v.args[1])] then + toremove[#toremove + 1] = allocs[tostring(v.args[1])] + if v.func == 'free' then + toremove[#toremove + 1] = i + end + elseif clear_null_frees and v.args[1] == self.null then + toremove[#toremove + 1] = i + end + if v.func == 'realloc' then + allocs[tostring(v.ret)] = i + end + end + end + table.sort(toremove) + for i = #toremove, 1, -1 do + table.remove(self.log, toremove[i]) + end + end + + function log:setup() + log:save_original_functions() + log:set_mocks() + end + + function log:before_each() end + + function log:after_each() end + + log:setup() + + return log +end + +-- take a pointer to a C-allocated string and return an interned +-- version while also freeing the memory +local function internalize(cdata, len) + ffi.gc(cdata, ffi.C.free) + return ffi.string(cdata, len) +end + +local cstr = ffi.typeof('char[?]') +local function to_cstr(string) + return cstr(#string + 1, string) +end + +cimport_immediate('./test/unit/fixtures/posix.h') + +local sc = {} + +function sc.fork() + return tonumber(ffi.C.fork()) +end + +function sc.pipe() + local ret = ffi.new('int[2]', { -1, -1 }) + ffi.errno(0) + local res = ffi.C.pipe(ret) + if res ~= 0 then + local err = ffi.errno(0) + assert(res == 0, ('pipe() error: %u: %s'):format(err, ffi.string(ffi.C.strerror(err)))) + end + assert(ret[0] ~= -1 and ret[1] ~= -1) + return ret[0], ret[1] +end + +--- @return string +function sc.read(rd, len) + local ret = ffi.new('char[?]', len, { 0 }) + local total_bytes_read = 0 + ffi.errno(0) + while total_bytes_read < len do + local bytes_read = + tonumber(ffi.C.read(rd, ffi.cast('void*', ret + total_bytes_read), len - total_bytes_read)) + if bytes_read == -1 then + local err = ffi.errno(0) + if err ~= ffi.C.kPOSIXErrnoEINTR then + assert(false, ('read() error: %u: %s'):format(err, ffi.string(ffi.C.strerror(err)))) + end + elseif bytes_read == 0 then + break + else + total_bytes_read = total_bytes_read + bytes_read + end + end + return ffi.string(ret, total_bytes_read) +end + +function sc.write(wr, s) + local wbuf = to_cstr(s) + local total_bytes_written = 0 + ffi.errno(0) + while total_bytes_written < #s do + local bytes_written = tonumber( + ffi.C.write(wr, ffi.cast('void*', wbuf + total_bytes_written), #s - total_bytes_written) + ) + if bytes_written == -1 then + local err = ffi.errno(0) + if err ~= ffi.C.kPOSIXErrnoEINTR then + assert( + false, + ("write() error: %u: %s ('%s')"):format(err, ffi.string(ffi.C.strerror(err)), s) + ) + end + elseif bytes_written == 0 then + break + else + total_bytes_written = total_bytes_written + bytes_written + end + end + return total_bytes_written +end + +sc.close = ffi.C.close + +--- @param pid integer +--- @return integer +function sc.wait(pid) + ffi.errno(0) + local stat_loc = ffi.new('int[1]', { 0 }) + while true do + local r = ffi.C.waitpid(pid, stat_loc, ffi.C.kPOSIXWaitWUNTRACED) + if r == -1 then + local err = ffi.errno(0) + if err == ffi.C.kPOSIXErrnoECHILD then + break + elseif err ~= ffi.C.kPOSIXErrnoEINTR then + assert(false, ('waitpid() error: %u: %s'):format(err, ffi.string(ffi.C.strerror(err)))) + end + else + assert(r == pid) + end + end + return stat_loc[0] +end + +sc.exit = ffi.C._exit + +--- @param lst string[] +--- @return string +local function format_list(lst) + local ret = {} --- @type string[] + for _, v in ipairs(lst) do + ret[#ret + 1] = assert:format({ v, n = 1 })[1] + end + return table.concat(ret, ', ') +end + +if os.getenv('NVIM_TEST_PRINT_SYSCALLS') == '1' then + for k_, v_ in pairs(sc) do + (function(k, v) + sc[k] = function(...) + local rets = { v(...) } + io.stderr:write(('%s(%s) = %s\n'):format(k, format_list({ ... }), format_list(rets))) + return unpack(rets) + end + end)(k_, v_) + end +end + +local function just_fail(_) + return false +end +say:set('assertion.just_fail.positive', '%s') +say:set('assertion.just_fail.negative', '%s') +assert:register( + 'assertion', + 'just_fail', + just_fail, + 'assertion.just_fail.positive', + 'assertion.just_fail.negative' +) + +local hook_fnamelen = 30 +local hook_sfnamelen = 30 +local hook_numlen = 5 +local hook_msglen = 1 + 1 + 1 + (1 + hook_fnamelen) + (1 + hook_sfnamelen) + (1 + hook_numlen) + 1 + +local tracehelp = dedent([[ + Trace: either in the format described below or custom debug output starting + with `>`. Latter lines still have the same width in byte. + + ┌ Trace type: _r_eturn from function , function _c_all, _l_ine executed, + │ _t_ail return, _C_ount (should not actually appear), + │ _s_aved from previous run for reference, _>_ for custom debug + │ output. + │┏ Function type: _L_ua function, _C_ function, _m_ain part of chunk, + │┃ function that did _t_ail call. + │┃┌ Function name type: _g_lobal, _l_ocal, _m_ethod, _f_ield, _u_pvalue, + │┃│ space for unknown. + │┃│ ┏ Source file name ┌ Function name ┏ Line + │┃│ ┃ (trunc to 30 bytes, no .lua) │ (truncated to last 30 bytes) ┃ number + CWN SSSSSSSSSSSSSSSSSSSSSSSSSSSSSS:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:LLLLL\n +]]) + +local function child_sethook(wr) + local trace_level_str = os.getenv('NVIM_TEST_TRACE_LEVEL') + local trace_level = 0 + if trace_level_str and trace_level_str ~= '' then + --- @type number + trace_level = assert(tonumber(trace_level_str)) + end + + if trace_level <= 0 then + return + end + + local trace_only_c = trace_level <= 1 + --- @type debuginfo?, string?, integer + local prev_info, prev_reason, prev_lnum + + --- @param reason string + --- @param lnum integer + --- @param use_prev boolean + local function hook(reason, lnum, use_prev) + local info = nil --- @type debuginfo? + if use_prev then + info = prev_info + elseif reason ~= 'tail return' then -- tail return + info = debug.getinfo(2, 'nSl') + end + + if trace_only_c and (not info or info.what ~= 'C') and not use_prev then + --- @cast info -nil + if info.source:sub(-9) == '_spec.lua' then + prev_info = info + prev_reason = 'saved' + prev_lnum = lnum + end + return + end + if trace_only_c and not use_prev and prev_reason then + hook(prev_reason, prev_lnum, true) + prev_reason = nil + end + + local whatchar = ' ' + local namewhatchar = ' ' + local funcname = '' + local source = '' + local msgchar = reason:sub(1, 1) + + if reason == 'count' then + msgchar = 'C' + end + + if info then + funcname = (info.name or ''):sub(1, hook_fnamelen) + whatchar = info.what:sub(1, 1) + namewhatchar = info.namewhat:sub(1, 1) + if namewhatchar == '' then + namewhatchar = ' ' + end + source = info.source + if source:sub(1, 1) == '@' then + if source:sub(-4, -1) == '.lua' then + source = source:sub(1, -5) + end + source = source:sub(-hook_sfnamelen, -1) + end + lnum = lnum or info.currentline + end + + -- assert(-1 <= lnum and lnum <= 99999) + local lnum_s = lnum == -1 and 'nknwn' or ('%u'):format(lnum) + --- @type string + local msg = ( -- lua does not support %* + '' + .. msgchar + .. whatchar + .. namewhatchar + .. ' ' + .. source + .. (' '):rep(hook_sfnamelen - #source) + .. ':' + .. funcname + .. (' '):rep(hook_fnamelen - #funcname) + .. ':' + .. ('0'):rep(hook_numlen - #lnum_s) + .. lnum_s + .. '\n' + ) + -- eq(hook_msglen, #msg) + sc.write(wr, msg) + end + debug.sethook(hook, 'crl') +end + +local trace_end_msg = ('E%s\n'):format((' '):rep(hook_msglen - 2)) + +--- @type function +local _debug_log + +local debug_log = only_separate(function(...) + return _debug_log(...) +end) + +local function itp_child(wr, func) + --- @param s string + _debug_log = function(s) + s = s:sub(1, hook_msglen - 2) + sc.write(wr, '>' .. s .. (' '):rep(hook_msglen - 2 - #s) .. '\n') + end + local status, result = pcall(init) + if status then + collectgarbage('stop') + child_sethook(wr) + status, result = pcall(func) + debug.sethook() + end + sc.write(wr, trace_end_msg) + if not status then + local emsg = tostring(result) + if #emsg > 99999 then + emsg = emsg:sub(1, 99999) + end + sc.write(wr, ('-\n%05u\n%s'):format(#emsg, emsg)) + deinit() + else + sc.write(wr, '+\n') + deinit() + end + collectgarbage('restart') + collectgarbage() + sc.write(wr, '$\n') + sc.close(wr) + sc.exit(status and 0 or 1) +end + +local function check_child_err(rd) + local trace = {} --- @type string[] + local did_traceline = false + local maxtrace = tonumber(os.getenv('NVIM_TEST_MAXTRACE')) or 1024 + while true do + local traceline = sc.read(rd, hook_msglen) + if #traceline ~= hook_msglen then + if #traceline == 0 then + break + else + trace[#trace + 1] = 'Partial read: <' .. trace .. '>\n' + end + end + if traceline == trace_end_msg then + did_traceline = true + break + end + trace[#trace + 1] = traceline + if #trace > maxtrace then + table.remove(trace, 1) + end + end + local res = sc.read(rd, 2) + if #res == 2 then + local err = '' + if res ~= '+\n' then + eq('-\n', res) + local len_s = sc.read(rd, 5) + local len = tonumber(len_s) + neq(0, len) + if os.getenv('NVIM_TEST_TRACE_ON_ERROR') == '1' and #trace ~= 0 then + --- @type string + err = '\nTest failed, trace:\n' .. tracehelp + for _, traceline in ipairs(trace) do + --- @type string + err = err .. traceline + end + end + --- @type string + err = err .. sc.read(rd, len + 1) + end + local eres = sc.read(rd, 2) + if eres ~= '$\n' then + if #trace == 0 then + err = '\nTest crashed, no trace available (check NVIM_TEST_TRACE_LEVEL)\n' + else + err = '\nTest crashed, trace:\n' .. tracehelp + for i = 1, #trace do + err = err .. trace[i] + end + end + if not did_traceline then + --- @type string + err = err .. '\nNo end of trace occurred' + end + local cc_err, cc_emsg = pcall(check_cores, paths.test_luajit_prg, true) + if not cc_err then + --- @type string + err = err .. '\ncheck_cores failed: ' .. cc_emsg + end + end + if err ~= '' then + assert.just_fail(err) + end + end +end + +local function itp_parent(rd, pid, allow_failure, location) + local ok, emsg = pcall(check_child_err, rd) + local status = sc.wait(pid) + sc.close(rd) + if not ok then + if allow_failure then + io.stderr:write('Errorred out (' .. status .. '):\n' .. tostring(emsg) .. '\n') + os.execute([[ + sh -c "source ci/common/test.sh + check_core_dumps --delete \"]] .. paths.test_luajit_prg .. [[\""]]) + else + error(tostring(emsg) .. '\nexit code: ' .. status) + end + elseif status ~= 0 then + if not allow_failure then + error('child process errored out with status ' .. status .. '!\n\n' .. location) + end + end +end + +local function gen_itp(it) + child_calls_mod = {} + child_calls_mod_once = {} + child_cleanups_mod_once = {} + preprocess_cache_mod = map(function(v) + return v + end, preprocess_cache_init) + previous_defines_mod = previous_defines_init + cdefs_mod = cdefs_init:copy() + local function itp(name, func, allow_failure) + if allow_failure and os.getenv('NVIM_TEST_RUN_FAILING_TESTS') ~= '1' then + -- FIXME Fix tests with this true + return + end + + -- Pre-emptively calculating error location, wasteful, ugh! + -- But the way this code messes around with busted implies the real location is strictly + -- not available in the parent when an actual error occurs. so we have to do this here. + local location = debug.traceback() + it(name, function() + local rd, wr = sc.pipe() + child_pid = sc.fork() + if child_pid == 0 then + sc.close(rd) + itp_child(wr, func) + else + sc.close(wr) + local saved_child_pid = child_pid + child_pid = nil + itp_parent(rd, saved_child_pid, allow_failure, location) + end + end) + end + return itp +end + +local function cppimport(path) + return cimport(paths.test_source_path .. '/test/includes/pre/' .. path) +end + +cimport( + './src/nvim/types_defs.h', + './src/nvim/main.h', + './src/nvim/os/time.h', + './src/nvim/os/fs.h' +) + +local function conv_enum(etab, eval) + local n = tonumber(eval) + return etab[n] or n +end + +local function array_size(arr) + return ffi.sizeof(arr) / ffi.sizeof(arr[0]) +end + +local function kvi_size(kvi) + return array_size(kvi.init_array) +end + +local function kvi_init(kvi) + kvi.capacity = kvi_size(kvi) + kvi.items = kvi.init_array + return kvi +end + +local function kvi_destroy(kvi) + if kvi.items ~= kvi.init_array then + lib.xfree(kvi.items) + end +end + +local function kvi_new(ct) + return kvi_init(ffi.new(ct)) +end + +local function make_enum_conv_tab(m, values, skip_pref, set_cb) + child_call_once(function() + local ret = {} + for _, v in ipairs(values) do + local str_v = v + if v:sub(1, #skip_pref) == skip_pref then + str_v = v:sub(#skip_pref + 1) + end + ret[tonumber(m[v])] = str_v + end + set_cb(ret) + end) +end + +local function ptr2addr(ptr) + return tonumber(ffi.cast('intptr_t', ffi.cast('void *', ptr))) +end + +local s = ffi.new('char[64]', { 0 }) + +local function ptr2key(ptr) + ffi.C.snprintf(s, ffi.sizeof(s), '%p', ffi.cast('void *', ptr)) + return ffi.string(s) +end + +local function is_asan() + cimport('./src/nvim/version.h') + local status, res = pcall(function() + return lib.version_cflags + end) + if status then + return ffi.string(res):match('-fsanitize=[a-z,]*address') + else + return false + end +end + +--- @class test.unit.testutil.module +local module = { + cimport = cimport, + cppimport = cppimport, + internalize = internalize, + ffi = ffi, + lib = lib, + cstr = cstr, + to_cstr = to_cstr, + NULL = ffi.cast('void*', 0), + OK = 1, + FAIL = 0, + alloc_log_new = alloc_log_new, + gen_itp = gen_itp, + only_separate = only_separate, + child_call_once = child_call_once, + child_cleanup_once = child_cleanup_once, + sc = sc, + conv_enum = conv_enum, + array_size = array_size, + kvi_destroy = kvi_destroy, + kvi_size = kvi_size, + kvi_init = kvi_init, + kvi_new = kvi_new, + make_enum_conv_tab = make_enum_conv_tab, + ptr2addr = ptr2addr, + ptr2key = ptr2key, + debug_log = debug_log, + is_asan = is_asan, +} +--- @class test.unit.testutil: test.unit.testutil.module, test.testutil +module = vim.tbl_extend('error', module, t_global) + +return function() + return module +end diff --git a/test/unit/undo_spec.lua b/test/unit/undo_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) local uv = vim.uv -local child_call_once = helpers.child_call_once +local child_call_once = t.child_call_once local sleep = uv.sleep -local ffi = helpers.ffi -local cimport = helpers.cimport -local to_cstr = helpers.to_cstr -local neq = helpers.neq -local eq = helpers.eq -local mkdir = helpers.mkdir +local ffi = t.ffi +local cimport = t.cimport +local to_cstr = t.to_cstr +local neq = t.neq +local eq = t.eq +local mkdir = t.mkdir local options = cimport('./src/nvim/option_vars.h') local undo = cimport('./src/nvim/undo.h') @@ -151,12 +151,12 @@ describe('u_write_undo', function() local file_contents = 'testing permissions' -- Write a text file where the undofile should go local correct_name = ffi.string(undo.u_get_undo_file_name(file_buffer.b_ffname, false)) - helpers.write_file(correct_name, file_contents, true, false) + t.write_file(correct_name, file_contents, true, false) -- Call with `forceit`. u_write_undo(correct_name, true, file_buffer, buffer_hash) - local undo_file_contents = helpers.read_file(correct_name) + local undo_file_contents = t.read_file(correct_name) neq(file_contents, undo_file_contents) local success, deletion_err = os.remove(correct_name) -- delete the file now that we're done with it. diff --git a/test/unit/viml/expressions/lexer_spec.lua b/test/unit/viml/expressions/lexer_spec.lua @@ -1,20 +1,20 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) -local viml_helpers = require('test.unit.viml.helpers') - -local child_call_once = helpers.child_call_once -local conv_enum = helpers.conv_enum -local cimport = helpers.cimport -local ffi = helpers.ffi -local eq = helpers.eq -local shallowcopy = helpers.shallowcopy -local intchar2lua = helpers.intchar2lua - -local conv_ccs = viml_helpers.conv_ccs -local new_pstate = viml_helpers.new_pstate -local conv_cmp_type = viml_helpers.conv_cmp_type -local pstate_set_str = viml_helpers.pstate_set_str -local conv_expr_asgn_type = viml_helpers.conv_expr_asgn_type +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) +local t_viml = require('test.unit.viml.testutil') + +local child_call_once = t.child_call_once +local conv_enum = t.conv_enum +local cimport = t.cimport +local ffi = t.ffi +local eq = t.eq +local shallowcopy = t.shallowcopy +local intchar2lua = t.intchar2lua + +local conv_ccs = t_viml.conv_ccs +local new_pstate = t_viml.new_pstate +local conv_cmp_type = t_viml.conv_cmp_type +local pstate_set_str = t_viml.pstate_set_str +local conv_expr_asgn_type = t_viml.conv_expr_asgn_type local lib = cimport('./src/nvim/viml/parser/expressions.h') diff --git a/test/unit/viml/expressions/parser_spec.lua b/test/unit/viml/expressions/parser_spec.lua @@ -1,29 +1,29 @@ -local helpers = require('test.unit.helpers')(after_each) -local itp = helpers.gen_itp(it) -local viml_helpers = require('test.unit.viml.helpers') +local t = require('test.unit.testutil')(after_each) +local itp = t.gen_itp(it) +local t_viml = require('test.unit.viml.testutil') -local make_enum_conv_tab = helpers.make_enum_conv_tab -local child_call_once = helpers.child_call_once -local alloc_log_new = helpers.alloc_log_new -local kvi_destroy = helpers.kvi_destroy -local conv_enum = helpers.conv_enum -local debug_log = helpers.debug_log -local ptr2key = helpers.ptr2key -local cimport = helpers.cimport -local ffi = helpers.ffi -local neq = helpers.neq -local eq = helpers.eq -local mergedicts_copy = helpers.mergedicts_copy +local make_enum_conv_tab = t.make_enum_conv_tab +local child_call_once = t.child_call_once +local alloc_log_new = t.alloc_log_new +local kvi_destroy = t.kvi_destroy +local conv_enum = t.conv_enum +local debug_log = t.debug_log +local ptr2key = t.ptr2key +local cimport = t.cimport +local ffi = t.ffi +local neq = t.neq +local eq = t.eq +local mergedicts_copy = t.mergedicts_copy local format_string = require('test.format_string').format_string local format_luav = require('test.format_string').format_luav -local intchar2lua = helpers.intchar2lua -local dictdiff = helpers.dictdiff +local intchar2lua = t.intchar2lua +local dictdiff = t.dictdiff -local conv_ccs = viml_helpers.conv_ccs -local new_pstate = viml_helpers.new_pstate -local conv_cmp_type = viml_helpers.conv_cmp_type -local pstate_set_str = viml_helpers.pstate_set_str -local conv_expr_asgn_type = viml_helpers.conv_expr_asgn_type +local conv_ccs = t_viml.conv_ccs +local new_pstate = t_viml.new_pstate +local conv_cmp_type = t_viml.conv_cmp_type +local pstate_set_str = t_viml.pstate_set_str +local conv_expr_asgn_type = t_viml.conv_expr_asgn_type local lib = cimport('./src/nvim/viml/parser/expressions.h', './src/nvim/syntax.h') diff --git a/test/unit/viml/helpers.lua b/test/unit/viml/helpers.lua @@ -1,151 +0,0 @@ -local helpers = require('test.unit.helpers')(nil) - -local ffi = helpers.ffi -local cimport = helpers.cimport -local kvi_new = helpers.kvi_new -local kvi_init = helpers.kvi_init -local conv_enum = helpers.conv_enum -local make_enum_conv_tab = helpers.make_enum_conv_tab - -local lib = cimport('./src/nvim/viml/parser/expressions.h') - -local function new_pstate(strings) - local strings_idx = 0 - local function get_line(_, ret_pline) - strings_idx = strings_idx + 1 - local str = strings[strings_idx] - local data, size - if type(str) == 'string' then - data = str - size = #str - elseif type(str) == 'nil' then - data = nil - size = 0 - elseif type(str) == 'table' then - data = str.data - size = str.size - elseif type(str) == 'function' then - data, size = str() - size = size or 0 - end - ret_pline.data = data - ret_pline.size = size - ret_pline.allocated = false - end - local state = { - reader = { - get_line = get_line, - cookie = nil, - conv = { - vc_type = 0, - vc_factor = 1, - vc_fail = false, - }, - }, - pos = { line = 0, col = 0 }, - colors = kvi_new('ParserHighlight'), - can_continuate = false, - } - local ret = ffi.new('ParserState', state) - kvi_init(ret.reader.lines) - kvi_init(ret.stack) - return ret -end - -local function pline2lua(pline) - return ffi.string(pline.data, pline.size) -end - -local function pstate_str(pstate, start, len) - local str = nil - local err = nil - if start.line < pstate.reader.lines.size then - local pstr = pline2lua(pstate.reader.lines.items[start.line]) - if start.col >= #pstr then - err = 'start.col >= #pstr' - else - str = pstr:sub(tonumber(start.col) + 1, tonumber(start.col + len)) - end - else - err = 'start.line >= pstate.reader.lines.size' - end - return str, err -end - -local function pstate_set_str(pstate, start, len, ret) - ret = ret or {} - ret.start = { - line = tonumber(start.line), - col = tonumber(start.col), - } - ret.len = tonumber(len) - ret.str, ret.error = pstate_str(pstate, start, len) - return ret -end - -local eltkn_cmp_type_tab -make_enum_conv_tab( - lib, - { - 'kExprCmpEqual', - 'kExprCmpMatches', - 'kExprCmpGreater', - 'kExprCmpGreaterOrEqual', - 'kExprCmpIdentical', - }, - 'kExprCmp', - function(ret) - eltkn_cmp_type_tab = ret - end -) - -local function conv_cmp_type(typ) - return conv_enum(eltkn_cmp_type_tab, typ) -end - -local ccs_tab -make_enum_conv_tab( - lib, - { - 'kCCStrategyUseOption', - 'kCCStrategyMatchCase', - 'kCCStrategyIgnoreCase', - }, - 'kCCStrategy', - function(ret) - ccs_tab = ret - end -) - -local function conv_ccs(ccs) - return conv_enum(ccs_tab, ccs) -end - -local expr_asgn_type_tab -make_enum_conv_tab( - lib, - { - 'kExprAsgnPlain', - 'kExprAsgnAdd', - 'kExprAsgnSubtract', - 'kExprAsgnConcat', - }, - 'kExprAsgn', - function(ret) - expr_asgn_type_tab = ret - end -) - -local function conv_expr_asgn_type(expr_asgn_type) - return conv_enum(expr_asgn_type_tab, expr_asgn_type) -end - -return { - conv_ccs = conv_ccs, - pline2lua = pline2lua, - pstate_str = pstate_str, - new_pstate = new_pstate, - conv_cmp_type = conv_cmp_type, - pstate_set_str = pstate_set_str, - conv_expr_asgn_type = conv_expr_asgn_type, -} diff --git a/test/unit/viml/testutil.lua b/test/unit/viml/testutil.lua @@ -0,0 +1,151 @@ +local t = require('test.unit.testutil')(nil) + +local ffi = t.ffi +local cimport = t.cimport +local kvi_new = t.kvi_new +local kvi_init = t.kvi_init +local conv_enum = t.conv_enum +local make_enum_conv_tab = t.make_enum_conv_tab + +local lib = cimport('./src/nvim/viml/parser/expressions.h') + +local function new_pstate(strings) + local strings_idx = 0 + local function get_line(_, ret_pline) + strings_idx = strings_idx + 1 + local str = strings[strings_idx] + local data, size + if type(str) == 'string' then + data = str + size = #str + elseif type(str) == 'nil' then + data = nil + size = 0 + elseif type(str) == 'table' then + data = str.data + size = str.size + elseif type(str) == 'function' then + data, size = str() + size = size or 0 + end + ret_pline.data = data + ret_pline.size = size + ret_pline.allocated = false + end + local state = { + reader = { + get_line = get_line, + cookie = nil, + conv = { + vc_type = 0, + vc_factor = 1, + vc_fail = false, + }, + }, + pos = { line = 0, col = 0 }, + colors = kvi_new('ParserHighlight'), + can_continuate = false, + } + local ret = ffi.new('ParserState', state) + kvi_init(ret.reader.lines) + kvi_init(ret.stack) + return ret +end + +local function pline2lua(pline) + return ffi.string(pline.data, pline.size) +end + +local function pstate_str(pstate, start, len) + local str = nil + local err = nil + if start.line < pstate.reader.lines.size then + local pstr = pline2lua(pstate.reader.lines.items[start.line]) + if start.col >= #pstr then + err = 'start.col >= #pstr' + else + str = pstr:sub(tonumber(start.col) + 1, tonumber(start.col + len)) + end + else + err = 'start.line >= pstate.reader.lines.size' + end + return str, err +end + +local function pstate_set_str(pstate, start, len, ret) + ret = ret or {} + ret.start = { + line = tonumber(start.line), + col = tonumber(start.col), + } + ret.len = tonumber(len) + ret.str, ret.error = pstate_str(pstate, start, len) + return ret +end + +local eltkn_cmp_type_tab +make_enum_conv_tab( + lib, + { + 'kExprCmpEqual', + 'kExprCmpMatches', + 'kExprCmpGreater', + 'kExprCmpGreaterOrEqual', + 'kExprCmpIdentical', + }, + 'kExprCmp', + function(ret) + eltkn_cmp_type_tab = ret + end +) + +local function conv_cmp_type(typ) + return conv_enum(eltkn_cmp_type_tab, typ) +end + +local ccs_tab +make_enum_conv_tab( + lib, + { + 'kCCStrategyUseOption', + 'kCCStrategyMatchCase', + 'kCCStrategyIgnoreCase', + }, + 'kCCStrategy', + function(ret) + ccs_tab = ret + end +) + +local function conv_ccs(ccs) + return conv_enum(ccs_tab, ccs) +end + +local expr_asgn_type_tab +make_enum_conv_tab( + lib, + { + 'kExprAsgnPlain', + 'kExprAsgnAdd', + 'kExprAsgnSubtract', + 'kExprAsgnConcat', + }, + 'kExprAsgn', + function(ret) + expr_asgn_type_tab = ret + end +) + +local function conv_expr_asgn_type(expr_asgn_type) + return conv_enum(expr_asgn_type_tab, expr_asgn_type) +end + +return { + conv_ccs = conv_ccs, + pline2lua = pline2lua, + pstate_str = pstate_str, + new_pstate = new_pstate, + conv_cmp_type = conv_cmp_type, + pstate_set_str = pstate_set_str, + conv_expr_asgn_type = conv_expr_asgn_type, +}