[Swift-commit] r3644 - in trunk: libexec src/org/griphyn/vdl/engine src/org/griphyn/vdl/karajan src/org/griphyn/vdl/karajan/lib/swiftscript tests tests/functions

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Mon Sep 27 11:30:59 CDT 2010


Author: wozniak
Date: 2010-09-27 11:30:59 -0500 (Mon, 27 Sep 2010)
New Revision: 3644

Added:
   trunk/src/org/griphyn/vdl/karajan/AssertFailedException.java
   trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Assert.java
   trunk/tests/functions/100-assert-bool.check.sh
   trunk/tests/functions/100-assert-bool.swift
   trunk/tests/functions/100-assert-int.check.sh
   trunk/tests/functions/100-assert-int.swift
Modified:
   trunk/libexec/vdl-lib.xml
   trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
   trunk/tests/nightly.sh
Log:
New assert() function and tests


Modified: trunk/libexec/vdl-lib.xml
===================================================================
--- trunk/libexec/vdl-lib.xml	2010-09-27 16:28:24 UTC (rev 3643)
+++ trunk/libexec/vdl-lib.xml	2010-09-27 16:30:59 UTC (rev 3644)
@@ -16,6 +16,7 @@
 	<export name="format"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
 	<export name="pad"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
 	<export name="tostring"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
+	<export name="assert"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Assert"/></export>
 	<export name="trace"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
 	<export name="tracef"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Tracef"/></export>
 	<export name="java"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Java"/></export>

Modified: trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java	2010-09-27 16:28:24 UTC (rev 3643)
+++ trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java	2010-09-27 16:30:59 UTC (rev 3644)
@@ -143,6 +143,11 @@
 		tracef.setInvocationMode(INVOCATION_INTERNAL);
 		proceduresMap.put("tracef", tracef);
 		
+		ProcedureSignature assrt = new ProcedureSignature("assert");
+		assrt.setAnyNumOfInputArgs();
+		assrt.setInvocationMode(INVOCATION_INTERNAL);
+		proceduresMap.put("assert", assrt);
+		
 		ProcedureSignature writeData = new ProcedureSignature("writeData");
 		FormalArgumentSignature wdInputArg = new FormalArgumentSignature(true);
 		writeData.addInputArg(wdInputArg);

Added: trunk/src/org/griphyn/vdl/karajan/AssertFailedException.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/AssertFailedException.java	                        (rev 0)
+++ trunk/src/org/griphyn/vdl/karajan/AssertFailedException.java	2010-09-27 16:30:59 UTC (rev 3644)
@@ -0,0 +1,19 @@
+
+package org.griphyn.vdl.karajan;
+
+/** 
+ * Generated only by SwiftScript @assert(). 
+ * 
+ * Created on September 27, 2010
+ * @author wozniak
+ */
+public class AssertFailedException extends RuntimeException {
+
+    private static final long serialVersionUID = 1L;
+   
+    String message = null;
+    
+	public AssertFailedException(String message) {
+		super(message);
+	}
+}

Added: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Assert.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Assert.java	                        (rev 0)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Assert.java	2010-09-27 16:30:59 UTC (rev 3644)
@@ -0,0 +1,69 @@
+package org.griphyn.vdl.karajan.lib.swiftscript;
+
+import org.apache.log4j.Logger;
+import org.globus.cog.karajan.arguments.Arg;
+import org.globus.cog.karajan.stack.VariableStack;
+import org.globus.cog.karajan.workflow.ExecutionException;
+import org.griphyn.vdl.karajan.AssertFailedException;
+import org.griphyn.vdl.karajan.lib.SwiftArg;
+import org.griphyn.vdl.karajan.lib.VDLFunction;
+import org.griphyn.vdl.mapping.DSHandle;
+import org.griphyn.vdl.type.Types;
+
+/**
+    Throw AssertionException if input is false or 0. 
+ */
+public class Assert extends VDLFunction {
+
+    private static final Logger logger = 
+        Logger.getLogger(Assert.class);
+    
+    static {
+        setArguments(Assert.class, new Arg[] { Arg.VARGS });
+    }
+    
+    @Override
+    protected Object function(VariableStack stack) 
+    throws ExecutionException {
+        DSHandle[] args = SwiftArg.VARGS.asDSHandleArray(stack);
+        String message = "";
+        
+        for (int i = 0; i < args.length; i++) {
+            DSHandle handle = args[i];
+            VDLFunction.waitFor(stack, handle);
+        }
+        
+        logger.debug("check: ");
+        
+        if (args.length == 2)
+            if (args[1].getType() == Types.STRING)
+                message = args[1].toString();
+            else
+                throw new ExecutionException
+                ("Second argument to assert() must be a String!");
+         
+        checkAssert(args[0], message);
+        
+        return null;
+    }
+
+    private void checkAssert(DSHandle value, String message) 
+    throws ExecutionException
+    {
+        boolean success = true; 
+        if (value.getType() == Types.BOOLEAN) { 
+            if (! (Boolean) value.getValue())
+                success = false;
+        }
+        else if (value.getType() == Types.INT) {
+            double d = ((Double) value.getValue()).doubleValue();
+            if (d == 0.0)
+                success = false;
+        } 
+        else 
+            throw new ExecutionException
+            ("First argument to assert() must be boolean or int!");
+        if (! success)
+            throw new AssertFailedException(message);
+    }
+}

Added: trunk/tests/functions/100-assert-bool.check.sh
===================================================================
--- trunk/tests/functions/100-assert-bool.check.sh	                        (rev 0)
+++ trunk/tests/functions/100-assert-bool.check.sh	2010-09-27 16:30:59 UTC (rev 3644)
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+set -x
+
+grep ASSERT_MESSAGE stdout.txt || exit 1
+
+exit 0


Property changes on: trunk/tests/functions/100-assert-bool.check.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/tests/functions/100-assert-bool.swift
===================================================================
--- trunk/tests/functions/100-assert-bool.swift	                        (rev 0)
+++ trunk/tests/functions/100-assert-bool.swift	2010-09-27 16:30:59 UTC (rev 3644)
@@ -0,0 +1,4 @@
+
+// THIS-SCRIPT-SHOULD-FAIL
+
+assert(false, "ASSERT_MESSAGE");

Added: trunk/tests/functions/100-assert-int.check.sh
===================================================================
--- trunk/tests/functions/100-assert-int.check.sh	                        (rev 0)
+++ trunk/tests/functions/100-assert-int.check.sh	2010-09-27 16:30:59 UTC (rev 3644)
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+set -x
+
+grep AssertFailedException stdout.txt || exit 1
+
+exit 0


Property changes on: trunk/tests/functions/100-assert-int.check.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/tests/functions/100-assert-int.swift
===================================================================
--- trunk/tests/functions/100-assert-int.swift	                        (rev 0)
+++ trunk/tests/functions/100-assert-int.swift	2010-09-27 16:30:59 UTC (rev 3644)
@@ -0,0 +1,4 @@
+
+// THIS-SCRIPT-SHOULD-FAIL
+
+assert(2-2);

Modified: trunk/tests/nightly.sh
===================================================================
--- trunk/tests/nightly.sh	2010-09-27 16:28:24 UTC (rev 3643)
+++ trunk/tests/nightly.sh	2010-09-27 16:30:59 UTC (rev 3644)
@@ -56,6 +56,12 @@
 #   +-bin/swift
 #     +-java
 
+# FAILURE CASES
+# Some cases are designed to cause Swift to crash.  These
+# SwiftScripts contain the token THIS-SCRIPT-SHOULD-FAIL somewhere.
+# The response of nightly.sh to the exit code of these Swift
+# executions is reversed.
+
 printhelp() {
   echo "nightly.sh <options> <output>"
   echo ""
@@ -486,6 +492,7 @@
   if [ -f $OUTPUT ]; then
     cat $OUTPUT >> $LOG
   fi
+  (( $TEST_SHOULD_FAIL )) && EXITCODE=$(( ! $EXITCODE ))
   return $EXITCODE
 }
 
@@ -619,6 +626,8 @@
   CHECKSCRIPT=${SWIFTSCRIPT%.swift}.check.sh
   CLEANSCRIPT=${SWIFTSCRIPT%.swift}.clean.sh
   TIMEOUTFILE=${SWIFTSCRIPT%.swift}.timeout
+
+  TEST_SHOULD_FAIL=0
   if [ -x $GROUP/$SETUPSCRIPT ]; then
     script_exec $GROUP/$SETUPSCRIPT "S"
   fi
@@ -630,6 +639,9 @@
 
   TIMEOUT=$( gettimeout $GROUP/$TIMEOUTFILE )
 
+  grep THIS-SCRIPT-SHOULD-FAIL $SWIFTSCRIPT > /dev/null
+  TEST_SHOULD_FAIL=$(( ! $?  ))
+
   monitored_exec $TIMEOUT swift                         \
                        -wrapperlog.always.transfer true \
                        -config swift.properties         \
@@ -637,6 +649,7 @@
                        -tc.file tc.data                 \
                        $CDM $SWIFTSCRIPT
 
+  TEST_SHOULD_FAIL=0
   if [ -x $GROUP/$CHECKSCRIPT ]; then
     script_exec $GROUP/$CHECKSCRIPT "√"
   fi
@@ -819,15 +832,15 @@
 
 SKIP_COUNTER=0
 
-# GROUPLIST=( $TESTDIR/local $TESTDIR/cdm $TESTDIR/cdm/ps $TESTDIR/cdm/ps/pinned )
+GROUPLIST=( $TESTDIR/functions $TESTDIR/local $TESTDIR/cdm $TESTDIR/cdm/ps $TESTDIR/cdm/ps/pinned )
 
-GROUPLIST=( $TESTDIR/language-behaviour
-            $TESTDIR/language/working \
-            $TESTDIR/local \
-            $TESTDIR/language/should-not-work \
-            $TESTDIR/cdm \
-            $TESTDIR/cdm/ps \
-            $TESTDIR/cdm/ps/pinned )
+# GROUPLIST=( $TESTDIR/language-behaviour
+#             $TESTDIR/language/working \
+#             $TESTDIR/local \
+#             $TESTDIR/language/should-not-work \
+#             $TESTDIR/cdm \
+#             $TESTDIR/cdm/ps \
+#             $TESTDIR/cdm/ps/pinned )
 
 GROUPCOUNT=1
 for G in ${GROUPLIST[@]}; do




More information about the Swift-commit mailing list