From 9ee7b0a5010eaf406ad3f9277b29e8fd06c3d628 Mon Sep 17 00:00:00 2001 From: Jan Kanis Date: Sat, 29 Dec 2012 19:25:00 +0100 Subject: [PATCH] really fix bug in export status of universal vars; add tests for that bug --- env.cpp | 6 ++-- tests/test3.in | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/test3.out | 5 +++ 3 files changed, 92 insertions(+), 3 deletions(-) diff --git a/env.cpp b/env.cpp index 370a636ac..4787827e9 100644 --- a/env.cpp +++ b/env.cpp @@ -811,7 +811,7 @@ int env_set(const wcstring &key, const wchar_t *val, int var_mode) if (var_mode & ENV_UNIVERSAL) { - int exportv = 0; + int exportv; if (!(var_mode & ENV_EXPORT) && !(var_mode & ENV_UNEXPORT)) @@ -868,12 +868,12 @@ int env_set(const wcstring &key, const wchar_t *val, int var_mode) if (env_universal_get(key)) { - int exportv = 0; + int exportv; if (!(var_mode & ENV_EXPORT) && !(var_mode & ENV_UNEXPORT)) { - env_universal_get_export(key); + exportv = env_universal_get_export(key); } else { diff --git a/tests/test3.in b/tests/test3.in index e15946834..92cc1c86c 100644 --- a/tests/test3.in +++ b/tests/test3.in @@ -134,3 +134,87 @@ if test $foo '=' def else echo Test 11 fail end + +# Test combinations of export and scope + +set -ge foo + +set -Ue foo +set -Ux foo bar +set foo baz +if test (/bin/sh -c 'echo $foo') = baz -a (../fish -c 'echo $foo') = baz + echo Test 12 pass +else + echo Test 12 fail +end + +set -Ue foo +set -Ux foo bar +set -U foo baz +if test (/bin/sh -c 'echo $foo') = baz -a (../fish -c 'echo $foo') = baz + echo Test 13 pass +else + echo Test 13 fail +end + +set -Ux foo bar +set -u foo bar +if test (/bin/sh -c 'echo $foo') = '' -a (../fish -c 'echo $foo') = bar + echo Test 14 pass +else + echo Test 14 fail +end + +set -Ux foo bar +set -Uu foo baz +if test (/bin/sh -c 'echo $foo') = '' -a (../fish -c 'echo $foo') = baz + echo Test 15 pass +else + echo Test 15 fail +end + +set -eU foo + +# test erasing variables without a specified scope + +set -g test16res + +set -U foo universal +set -g foo global +begin + set -l foo blocklocal + function test16 + set -l foo function + begin + set -l foo functionblock + + set test16res $test16res (echo $foo) + set -e foo + set test16res $test16res (echo $foo) + set -e foo + set test16res $test16res (echo $foo) + set -e foo + set test16res $test16res (echo $foo) + set -e foo + set test16res $test16res (echo $foo) + end + set test16res $test16res (echo $foo) + set -e foo + end + test16 + set test16res $test16res (echo $foo) +end +set test16res $test16res (echo $foo) + +#echo count: (count $test16res) "content:[$test16res]" + +if test (count $test16res) = 8 -a "$test16res" = "functionblock function global universal blocklocal " + echo Test 16 pass +else + echo Test 16 fail +end + + +# clear foo for other shells +set -eU foo +true diff --git a/tests/test3.out b/tests/test3.out index a0c33cec7..5b4e3d112 100644 --- a/tests/test3.out +++ b/tests/test3.out @@ -9,3 +9,8 @@ Test 8 pass Test 9 pass Test 10 pass Test 11 pass +Test 12 pass +Test 13 pass +Test 14 pass +Test 15 pass +Test 16 pass