1# Copyright (C) 2021 Free Software Foundation, Inc. 2# 3# This file is part of DejaGnu. 4# 5# DejaGnu is free software; you can redistribute it and/or modify it 6# under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 3 of the License, or 8# (at your option) any later version. 9# 10# DejaGnu is distributed in the hope that it will be useful, but 11# WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13# General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with DejaGnu; if not, write to the Free Software Foundation, 17# Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 18 19# This file is a regression test for PR48155, where running with the 20# environment variable SHELL set to a C shell could cause an error running 21# config.guess that would not be properly detected. 22 23load_lib util-defs.exp 24 25runtest_setup_nested_testsuite 26 27# We need a modified local init file for this test; the regular 28# nested-init.exp will set host_triplet, which will cause runtest to assume 29# that that is the build_triplet and avoid attempting to run config.guess. 30exec sed -e /_triplet/d < nested-init.exp > pr48155-init.exp 31 32proc test_pr48155_setup {} { 33 upvar 1 envlist envlist 34 upvar 1 save_env save_env 35 upvar 1 unset_env unset_env 36 37 set unset_env [list] 38 foreach {name value} $envlist { 39 if { [info exists ::env($name)] } { 40 set save_env($name) $::env($name) 41 } else { 42 lappend unset_env $name 43 } 44 } 45 foreach name {CONFIG_SHELL SHELL} { 46 if { [info exists ::env($name)] } { 47 set save_env($name) $::env($name) 48 unset ::env($name) 49 } 50 } 51 array set ::env $envlist 52} 53proc test_pr48155_cleanup {} { 54 upvar 1 save_env save_env 55 upvar 1 unset_env unset_env 56 57 foreach name $unset_env { unset ::env($name) } 58 unset -nocomplain ::env(CONFIG_SHELL) ::env(SHELL) 59 array set ::env [array get save_env] 60} 61 62proc test_pr48155_error { name envlist output } { 63 global RUNTEST 64 65 test_pr48155_setup 66 67 if { [util_test $RUNTEST \ 68 "--local_init pr48155-init.exp --tool null" \ 69 "" \ 70 $output] } { 71 fail $name 72 } else { 73 pass $name 74 } 75 76 test_pr48155_cleanup 77} 78 79test_pr48155_error "bogus CONFIG_SHELL as false" \ 80 [list CONFIG_SHELL [which false]] \ 81 "exited on code .*produced bogus build triplet:" 82test_pr48155_error "bogus CONFIG_SHELL as true" \ 83 [list CONFIG_SHELL [which true]] \ 84 "produced bogus build triplet:" 85test_pr48155_error "bogus CONFIG_SHELL as simulated C shell" \ 86 [list CONFIG_SHELL [testsuite file -source -test pr48155-csh.sh]] \ 87 "exited on code 1.*produced bogus build triplet:" 88 89# The following tests may change if planned future enhancements to reject 90# unusable values of SHELL are implemented. 91 92test_pr48155_error "bogus SHELL as false" \ 93 [list SHELL [which false]] \ 94 "exited on code .*produced bogus build triplet:" 95test_pr48155_error "bogus SHELL as true" \ 96 [list SHELL [which true]] \ 97 "produced bogus build triplet:" 98test_pr48155_error "bogus SHELL as simulated C shell" \ 99 [list SHELL [testsuite file -source -test pr48155-csh.sh]] \ 100 "exited on code 1.*produced bogus build triplet:" 101 102runtest_cleanup_nested_testsuite 103