envtest.t revision 171195
1#!/bin/sh 2# 3# Copyright (c) 2007 Sean C. Farley <scf@FreeBSD.org> 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer, 11# without modification, immediately at the beginning of the file. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# 27# $FreeBSD: head/tools/regression/environ/envtest.t 171195 2007-07-04 00:00:41Z scf $ 28 29 30# Initialization. 31testndx=0 32 33 34# Testing function. 35run_test() 36{ 37 lasttest="${@}" 38 result=`./envctl -t "${@}"` 39 40 if [ ${?} -ne 0 ] 41 then 42 echo "Test program failed" >&2 43 exit 1 44 fi 45 46 return 47} 48 49 50# Perform test on results. 51check_result() 52{ 53 testndx=$((testndx + 1)) 54 55 echo "${result}" | sed 's/[ \t]*$//' | grep -q "^${@}$" 56 if [ ${?} -eq 0 ] 57 then 58 echo "ok ${testndx}" 59 else 60 echo "not ok ${testndx} - '${lasttest}'" 61 fi 62 63 return 64} 65 66 67# 68# Regression tests 69# 70 71# Setup environment for tests. 72readonly BAR="bar" 73readonly NEWBAR="newbar" 74export FOO=${BAR} 75 76 77# Gets from environ. 78run_test -g FOO 79check_result "${FOO}" 80 81run_test -c -g FOO 82check_result "" 83 84run_test -g FOOBAR 85check_result "" 86 87run_test -c -g FOOBAR 88check_result "" 89 90run_test -G 91check_result "" 92 93 94# Sets. 95run_test -s FOO ${NEWBAR} 0 -g FOO 96check_result "0 0 ${BAR}" 97 98run_test -s FOO ${NEWBAR} 1 -g FOO 99check_result "0 0 ${NEWBAR}" 100 101run_test -c -s FOO ${NEWBAR} 0 -g FOO 102check_result "0 0 ${NEWBAR}" 103 104run_test -c -s FOO ${NEWBAR} 1 -g FOO 105check_result "0 0 ${NEWBAR}" 106 107run_test -s "FOO=" ${NEWBAR} 1 -g FOO 108check_result "-1 22 ${BAR}" 109 110run_test -s "=FOO" ${NEWBAR} 1 111check_result "-1 22" 112 113run_test -s "=" ${NEWBAR} 1 114check_result "-1 22" 115 116run_test -s "" ${NEWBAR} 1 117check_result "-1 22" 118 119run_test -S ${NEWBAR} 1 120check_result "-1 22" 121 122run_test -s FOO ${NEWBAR} 1 -s FOO ${BAR} 1 -g FOO 123check_result "0 0 0 0 ${BAR}" 124 125run_test -c -s FOO ${NEWBAR} 1 -s FOO ${BAR} 1 -g FOO 126check_result "0 0 0 0 ${BAR}" 127 128run_test -s FOO ${NEWBAR} 1 -s FOO ${BAR} 1 -s FOO ${NEWBAR} 1 -g FOO 129check_result "0 0 0 0 0 0 ${NEWBAR}" 130 131run_test -s FOO ${NEWBAR} 1 -s FOO ${BAR} 1 -s FOO ${NEWBAR} 1 -s FOO ${BAR} 1\ 132 -g FOO 133check_result "0 0 0 0 0 0 0 0 ${BAR}" 134 135 136# Unsets. 137run_test -u FOO -g FOO 138check_result "0 0" 139 140run_test -c -u FOO -g FOO 141check_result "0 0" 142 143run_test -U 144check_result "-1 22" 145 146run_test -u "" 147check_result "-1 22" 148 149run_test -u "=${BAR}" 150check_result "-1 22" 151 152run_test -c -s FOO ${NEWBAR} 1 -g FOO -u FOO -g FOO 153check_result "0 0 ${NEWBAR} 0 0" 154 155 156# Puts. 157run_test -p FOO=${NEWBAR} -g FOO 158check_result "0 0 ${NEWBAR}" 159 160run_test -c -p FOO=${NEWBAR} -g FOO 161check_result "0 0 ${NEWBAR}" 162 163run_test -p FOO -g FOO 164check_result "-1 22 ${BAR}" 165 166run_test -p FOO=${BAR} -p FOO=${NEWBAR} -g FOO 167check_result "0 0 0 0 ${NEWBAR}" 168 169run_test -p FOO=${BAR} -s FOO ${NEWBAR} 1 -g FOO 170check_result "0 0 0 0 ${NEWBAR}" 171 172run_test -s FOO ${NEWBAR} 1 -p FOO=${BAR} -g FOO 173check_result "0 0 0 0 ${BAR}" 174 175run_test -p FOO=${BAR} -u FOO 176check_result "0 0 0 0" 177 178run_test -p FOO=${BAR} -s FOO ${NEWBAR} 1 -u FOO 179check_result "0 0 0 0 0 0" 180 181run_test -s FOO ${NEWBAR} 1 -p FOO=${BAR} -u FOO 182check_result "0 0 0 0 0 0" 183