annotate src/testdir/test_environ.vim @ 22602:2c77ec32deeb v8.2.1849

patch 8.2.1849: Vim9: garbage collection frees block-local variables Commit: https://github.com/vim/vim/commit/ed234f24f3a6d697ba9b786d0bc74d4682bfdf47 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Oct 15 20:42:20 2020 +0200 patch 8.2.1849: Vim9: garbage collection frees block-local variables Problem: Vim9: garbage collection frees block-local variables. Solution: Mark all script variables as used.
author Bram Moolenaar <Bram@vim.org>
date Thu, 15 Oct 2020 20:45:05 +0200
parents 68115baaf9e4
children 52ef65c0637f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 17994
diff changeset
1 " Test for environment variables.
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 17994
diff changeset
2
16604
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 scriptencoding utf-8
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4
22417
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
5 source check.vim
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
6
16604
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 func Test_environ()
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 unlet! $TESTENV
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 call assert_equal(0, has_key(environ(), 'TESTENV'))
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 let $TESTENV = 'foo'
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 call assert_equal(1, has_key(environ(), 'TESTENV'))
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 let $TESTENV = 'こんにちわ'
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 call assert_equal('こんにちわ', environ()['TESTENV'])
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 endfunc
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 func Test_getenv()
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 unlet! $TESTENV
17857
4935244c1128 patch 8.1.1925: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 16922
diff changeset
18 call assert_equal(v:null, 'TESTENV'->getenv())
16604
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 let $TESTENV = 'foo'
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 call assert_equal('foo', getenv('TESTENV'))
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 endfunc
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 func Test_setenv()
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 unlet! $TESTENV
17994
0dcc2ee838dd patch 8.1.1993: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17857
diff changeset
25 eval 'foo'->setenv('TEST ENV')
16604
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 call assert_equal('foo', getenv('TEST ENV'))
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 call setenv('TEST ENV', v:null)
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 call assert_equal(v:null, getenv('TEST ENV'))
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 endfunc
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 func Test_external_env()
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 call setenv('FOO', 'HelloWorld')
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 if has('win32')
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 let result = system('echo %FOO%')
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 else
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 let result = system('echo $FOO')
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 endif
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 let result = substitute(result, '[ \r\n]', '', 'g')
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 call assert_equal('HelloWorld', result)
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 call setenv('FOO', v:null)
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 if has('win32')
16922
4ba323df874a patch 8.1.1462: MS-Windows: using special character requires quoting
Bram Moolenaar <Bram@vim.org>
parents: 16920
diff changeset
43 let result = system('set | findstr "^FOO="')
16604
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 else
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 let result = system('env | grep ^FOO=')
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 endif
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 call assert_equal('', result)
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 endfunc
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 17994
diff changeset
49
22417
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
50 func Test_mac_locale()
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
51 CheckFeature osxdarwin
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
52
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
53 " If $LANG is not set then the system locale will be used.
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
54 " Run Vim after unsetting all the locale environmental vars, and capture the
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
55 " output of :lang.
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
56 let lang_results = system("unset LANG; unset LC_MESSAGES; " ..
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
57 \ shellescape(v:progpath) ..
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
58 \ " --clean -esX -c 'redir @a' -c 'lang' -c 'put a' -c 'print' -c 'qa!' ")
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
59
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
60 " Check that:
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
61 " 1. The locale is the form of <locale>.UTF-8.
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
62 " 2. Check that fourth item (LC_NUMERIC) is properly set to "C".
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
63 " Example match: "en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8"
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
64 call assert_match('"\([a-zA-Z_]\+\.UTF-8/\)\{3}C\(/[a-zA-Z_]\+\.UTF-8\)\{2}"',
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
65 \ lang_results,
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
66 \ "Default locale should have UTF-8 encoding set, and LC_NUMERIC set to 'C'")
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
67 endfunc
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
68
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 17994
diff changeset
69 " vim: shiftwidth=2 sts=2 expandtab