Patch 8.2.4087
Problem:    Cannot test items from an autoload script easily.
Solution:   Add the "autoload" value for test_override().
Files:      runtime/doc/testing.txt, src/testing.c, src/globals.h,
            src/vim9script.c, src/testdir/test_vim9_import.vim


*** ../vim-8.2.4086/runtime/doc/testing.txt     2021-06-23 19:46:46.914256853 
+0100
--- runtime/doc/testing.txt     2022-01-13 21:33:15.023812449 +0000
***************
*** 190,212 ****
                to run tests. Only to be used for testing Vim!
                The override is enabled when {val} is non-zero and removed
                when {val} is zero.
!               Current supported values for name are:
  
!               name         effect when {val} is non-zero ~
!               redraw       disable the redrawing() function
!               redraw_flag  ignore the RedrawingDisabled flag
                char_avail   disable the char_avail() function
-               starting     reset the "starting" variable, see below
                nfa_fail     makes the NFA regexp engine fail to force a
                             fallback to the old engine
                no_query_mouse  do not query the mouse position for "dec"
                                terminals
                no_wait_return  set the "no_wait_return" flag.  Not restored
                                with "ALL".
!               ui_delay     time in msec to use in ui_delay(); overrules a
!                            wait time of up to 3 seconds for messages
                term_props   reset all terminal properties when the version
                             string is detected
                uptime       overrules sysinfo.uptime
                ALL          clear all overrides ({val} is not used)
  
--- 188,212 ----
                to run tests. Only to be used for testing Vim!
                The override is enabled when {val} is non-zero and removed
                when {val} is zero.
!               Current supported values for {name} are:
  
!               {name}       effect when {val} is non-zero ~
!               autoload     `import autoload` will load the script right
!                            away, not postponed until an item is used
                char_avail   disable the char_avail() function
                nfa_fail     makes the NFA regexp engine fail to force a
                             fallback to the old engine
                no_query_mouse  do not query the mouse position for "dec"
                                terminals
                no_wait_return  set the "no_wait_return" flag.  Not restored
                                with "ALL".
!               redraw       disable the redrawing() function
!               redraw_flag  ignore the RedrawingDisabled flag
!               starting     reset the "starting" variable, see below
                term_props   reset all terminal properties when the version
                             string is detected
+               ui_delay     time in msec to use in ui_delay(); overrules a
+                            wait time of up to 3 seconds for messages
                uptime       overrules sysinfo.uptime
                ALL          clear all overrides ({val} is not used)
  
*** ../vim-8.2.4086/src/testing.c       2022-01-13 21:15:17.237958552 +0000
--- src/testing.c       2022-01-13 21:33:54.799753145 +0000
***************
*** 1055,1060 ****
--- 1055,1062 ----
            reset_term_props_on_termresponse = val;
        else if (STRCMP(name, (char_u *)"uptime") == 0)
            override_sysinfo_uptime = val;
+       else if (STRCMP(name, (char_u *)"autoload") == 0)
+           override_autoload = val;
        else if (STRCMP(name, (char_u *)"ALL") == 0)
        {
            disable_char_avail_for_testing = FALSE;
*** ../vim-8.2.4086/src/globals.h       2022-01-08 12:41:12.204795554 +0000
--- src/globals.h       2022-01-13 21:34:26.799705858 +0000
***************
*** 1643,1648 ****
--- 1643,1649 ----
  EXTERN int  ui_delay_for_testing INIT(= 0);
  EXTERN int  reset_term_props_on_termresponse INIT(= FALSE);
  EXTERN long override_sysinfo_uptime INIT(= -1);
+ EXTERN int  override_autoload INIT(= FALSE);
  
  EXTERN int  in_free_unref_items INIT(= FALSE);
  #endif
*** ../vim-8.2.4086/src/vim9script.c    2022-01-13 21:15:17.241958539 +0000
--- src/vim9script.c    2022-01-13 21:47:54.258588118 +0000
***************
*** 496,501 ****
--- 496,504 ----
            if (si->sn_autoload_prefix == NULL)
                si->sn_autoload_prefix = get_autoload_prefix(si);
            res = OK;
+           if (override_autoload && si->sn_state == SN_STATE_NOT_LOADED)
+               // testing override: load autoload script right away
+               (void)do_source(si->sn_name, FALSE, DOSO_NONE, NULL);
        }
        else
            res = FAIL;
*** ../vim-8.2.4086/src/testdir/test_vim9_import.vim    2022-01-13 
20:51:51.202887526 +0000
--- src/testdir/test_vim9_import.vim    2022-01-13 21:57:28.228323710 +0000
***************
*** 1288,1293 ****
--- 1288,1329 ----
    &rtp = save_rtp
  enddef
  
+ def Test_import_autoload_override()
+   mkdir('Xdir/autoload', 'p')
+   var save_rtp = &rtp
+   exe 'set rtp^=' .. getcwd() .. '/Xdir'
+   test_override('autoload', 1)
+ 
+   var lines =<< trim END
+       vim9script autoload
+ 
+       g:loaded_override = 'true'
+       export var variable = 'bla'
+       export def Function(): string
+         return 'bla'
+       enddef
+   END
+   writefile(lines, 'Xdir/autoload/override.vim')
+ 
+   lines =<< trim END
+       vim9script
+ 
+       import autoload 'override.vim'
+       assert_equal('true', g:loaded_override)
+ 
+       def Tryit()
+         echo override.doesNotExist
+       enddef
+       defcompile
+   END
+   CheckScriptFailure(lines, 'E1048: Item not found in script: doesNotExist', 
1)
+ 
+   test_override('autoload', 0)
+   unlet g:loaded_override
+   delete('Xdir', 'rf')
+   &rtp = save_rtp
+ enddef
+ 
  def Test_autoload_mapping()
    mkdir('Xdir/autoload', 'p')
    var save_rtp = &rtp
*** ../vim-8.2.4086/src/version.c       2022-01-13 21:15:17.241958539 +0000
--- src/version.c       2022-01-13 21:53:06.929247687 +0000
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4087,
  /**/

-- 
Luxury. We used to have to get out of the lake at three o'clock in the 
morning, clean the lake, eat a handful of hot gravel, go to work at the 
mill every day for tuppence a month, come home, and Dad would beat us 
around the head and neck with a broken bottle, if we were LUCKY!

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220113220543.0D0CA1C226C%40moolenaar.net.

Raspunde prin e-mail lui