From: Ian Jackson Subject: Re: [PATCH OSSTEST] sg-run-job: Only consider $OSSTEST_SIMULATE > 0 Date: Tue, 31 Mar 2015 14:47:10 +0100 Message-ID: <21786.42334.676040.885960@mariner.uk.xensource.com> References: <1427201828-22462-1-git-send-email-ian.campbell@citrix.com> <1427276701-7274-1-git-send-email-ian.campbell@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1427276701-7274-1-git-send-email-ian.campbell@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org Ian Campbell writes ("[PATCH OSSTEST] sg-run-job: Only consider $OSSTEST_SIMULATE > 0"): > This matches the semantics implemented in cri-args-hostlists and is > compatible with the recent change to the standalone wrapper > ("standalone: Add --dry-run option for run-job.") which sets it to 0 > or 1. Oops! This patch should be inserted before that one, then. > set xprefix {} > - if {[info exists env(OSSTEST_SIMULATE)]} { set xprefix echo } > + if {[info exists env(OSSTEST_SIMULATE)] && > + [expr $env(OSSTEST_SIMULATE) > 0]} { Not enclosing the expression with { } is very poor style, although here it happens to work. Also: there is another occurrence of the same pattern, in JobDB-Executive.tcl: proc db-execute-debug {stmt} { if {[info exists env(OSSTEST_TCL_JOBDB_DEBUG)]} { I suggest something like this: diff --git a/tcl/osstestlib.tcl b/tcl/osstestlib.tcl index a0413c4..61a6a09 100644 --- a/tcl/osstestlib.tcl +++ b/tcl/osstestlib.tcl @@ -74,3 +74,9 @@ proc lshift {listvar} { set list [lrange $list 1 end] return $head } + +proc var-or-default {varname {default {}}} { + upvar 1 $varname var + if {[info exists var]} { return $var } + return $default +} (Signed-off-by: Ian Jackson ) and then we can write if {[var-or-default env(OSSTEST_SIMULATE) 0]} { ... And if you set OSSTEST_SIMULATE to "wombat" you get a backtrace, with a message from the Tcl interpreter saying: expected boolean value but got "wombat" Ian.