Mercurial > vim
annotate src/testdir/test_environ.vim @ 28871:18604231a1d1 v8.2.4958
patch 8.2.4958: a couple conditions are always true
Commit: https://github.com/vim/vim/commit/dd41037552c1be3548d2ce34bb1c889f14edb553
Author: =?UTF-8?q?Dundar=20G=C3=B6c?= <gocdundar@gmail.com>
Date: Sun May 15 13:59:11 2022 +0100
patch 8.2.4958: a couple conditions are always true
Problem: A couple conditions are always true.
Solution: Remove the conditions. (Goc Dundar, closes https://github.com/vim/vim/issues/10428)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 15 May 2022 15:00:02 +0200 |
parents | 52ef65c0637f |
children | e3ab1d0f2ef9 |
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 |
28459
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
31 func Test_special_env() |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
32 " The value for $HOME is cached internally by Vim, ensure the value is up to |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
33 " date. |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
34 let orig_ENV = $HOME |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
35 |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
36 let $HOME = 'foo' |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
37 call assert_equal('foo', expand('~')) |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
38 " old $HOME value is kept until a new one is set |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
39 unlet $HOME |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
40 call assert_equal('foo', expand('~')) |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
41 |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
42 call setenv('HOME', 'bar') |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
43 call assert_equal('bar', expand('~')) |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
44 " old $HOME value is kept until a new one is set |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
45 call setenv('HOME', v:null) |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
46 call assert_equal('bar', expand('~')) |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
47 |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
48 let $HOME = orig_ENV |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
49 endfunc |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
22417
diff
changeset
|
50 |
16604
1e0a5f09fdf1
patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 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
|
52 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
|
53 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
|
54 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
|
55 else |
1e0a5f09fdf1
patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 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
|
57 endif |
1e0a5f09fdf1
patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 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
|
59 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
|
60 |
1e0a5f09fdf1
patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 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
|
62 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
|
63 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
|
64 else |
1e0a5f09fdf1
patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 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
|
66 endif |
1e0a5f09fdf1
patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 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
|
68 endfunc |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
17994
diff
changeset
|
69 |
22417
68115baaf9e4
patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
70 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
|
71 CheckFeature osxdarwin |
68115baaf9e4
patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
72 |
68115baaf9e4
patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
73 " 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
|
74 " 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
|
75 " output of :lang. |
68115baaf9e4
patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
76 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
|
77 \ shellescape(v:progpath) .. |
68115baaf9e4
patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
78 \ " --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
|
79 |
68115baaf9e4
patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
80 " Check that: |
68115baaf9e4
patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
81 " 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
|
82 " 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
|
83 " 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
|
84 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
|
85 \ lang_results, |
68115baaf9e4
patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
86 \ "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
|
87 endfunc |
68115baaf9e4
patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
88 |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
17994
diff
changeset
|
89 " vim: shiftwidth=2 sts=2 expandtab |