patch 9.1.0391: Vim9: could improve testing

Problem:  Vim9: could improve testing
          (Ernie Rael)
Solution: Support defcompile for test_override() to
          improve testing (Yegappan Lakshmanan)

fixes: #14553
closes: #14712

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/globals.h b/src/globals.h
index 2c00e5f..fb5c7b3 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -1936,6 +1936,7 @@
 EXTERN int  disable_vterm_title_for_testing INIT(= FALSE);
 EXTERN long override_sysinfo_uptime INIT(= -1);
 EXTERN int  override_autoload INIT(= FALSE);
+EXTERN int  override_defcompile INIT(= FALSE);
 EXTERN int  ml_get_alloc_lines INIT(= FALSE);
 EXTERN int  ignore_unreachable_code_for_testing INIT(= FALSE);
 
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index b008929..d07bbfb 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
Binary files differ
diff --git a/src/testing.c b/src/testing.c
index 33de3a5..3e9e077 100644
--- a/src/testing.c
+++ b/src/testing.c
@@ -1051,6 +1051,8 @@
 	ml_get_alloc_lines = val;
     else if (STRCMP(name, (char_u *)"autoload") == 0)
 	override_autoload = val;
+    else if (STRCMP(name, (char_u *)"defcompile") == 0)
+	override_defcompile = val;
     else if (STRCMP(name, (char_u *)"ALL") == 0)
     {
 	disable_char_avail_for_testing = FALSE;
diff --git a/src/userfunc.c b/src/userfunc.c
index 71b3983..7536234 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -5452,6 +5452,10 @@
 	// :func does not use Vim9 script syntax, even in a Vim9 script file
 	fp->uf_script_ctx.sc_version = SCRIPT_VERSION_MAX;
 
+    // If test_override('defcompile' 1) is used, then compile the function now
+    if (eap->cmdidx == CMD_def && override_defcompile)
+	defcompile_function(fp, NULL);
+
     goto ret_free;
 
 erret:
diff --git a/src/version.c b/src/version.c
index 46d9c1a..a3bc3f9 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    391,
+/**/
     390,
 /**/
     389,