[rkward-cvs] SF.net SVN: rkward:[2558] trunk/rkward/tests

tfry at users.sourceforge.net tfry at users.sourceforge.net
Tue Jun 30 13:48:09 UTC 2009


Revision: 2558
          http://rkward.svn.sourceforge.net/rkward/?rev=2558&view=rev
Author:   tfry
Date:     2009-06-30 13:48:09 +0000 (Tue, 30 Jun 2009)

Log Message:
-----------
Add tests for correct handling of promises and active bindings in .GlobalEnv

Modified Paths:
--------------
    trunk/rkward/tests/all_tests.R

Added Paths:
-----------
    trunk/rkward/tests/rkward_application_tests/
    trunk/rkward/tests/rkward_application_tests/RKTestStandard.active_binding.messages.txt
    trunk/rkward/tests/rkward_application_tests/RKTestStandard.promise_in_globalenv.messages.txt
    trunk/rkward/tests/rkward_application_tests.R

Modified: trunk/rkward/tests/all_tests.R
===================================================================
--- trunk/rkward/tests/all_tests.R	2009-06-30 13:04:41 UTC (rev 2557)
+++ trunk/rkward/tests/all_tests.R	2009-06-30 13:48:09 UTC (rev 2558)
@@ -1,7 +1,7 @@
 if (!isClass ("RKTestSuite")) source ("test_framework.R")
 
 ## add your test suite files, to this vector:
-testsuites <- c ("import_export_plugins.R")
+testsuites <- c ("rkward_application_tests.R", "import_export_plugins.R")
 
 allresults <- new ("RKTestResult")
 for (testsuite in testsuites) {

Added: trunk/rkward/tests/rkward_application_tests/RKTestStandard.active_binding.messages.txt
===================================================================
--- trunk/rkward/tests/rkward_application_tests/RKTestStandard.active_binding.messages.txt	                        (rev 0)
+++ trunk/rkward/tests/rkward_application_tests/RKTestStandard.active_binding.messages.txt	2009-06-30 13:48:09 UTC (rev 2558)
@@ -0,0 +1,4 @@
+active.binding
+after sync
+active.binding
+active.binding

Added: trunk/rkward/tests/rkward_application_tests/RKTestStandard.promise_in_globalenv.messages.txt
===================================================================
--- trunk/rkward/tests/rkward_application_tests/RKTestStandard.promise_in_globalenv.messages.txt	                        (rev 0)
+++ trunk/rkward/tests/rkward_application_tests/RKTestStandard.promise_in_globalenv.messages.txt	2009-06-30 13:48:09 UTC (rev 2558)
@@ -0,0 +1,3 @@
+delayed assign
+after sync
+delayed assign

Added: trunk/rkward/tests/rkward_application_tests.R
===================================================================
--- trunk/rkward/tests/rkward_application_tests.R	                        (rev 0)
+++ trunk/rkward/tests/rkward_application_tests.R	2009-06-30 13:48:09 UTC (rev 2558)
@@ -0,0 +1,56 @@
+## intro
+# This should be the first line in each test suite file: Include the
+# test framework, unless already included (multiple inclusion would not
+# really do any harm either, though
+if (!isClass ("RKTestSuite")) source ("test_framework.R")
+
+## definition of the test suite
+suite <- new ("RKTestSuite", id="rkward_application_tests",
+	# initCalls are run *before* any tests. Use this to set up the environment
+	initCalls = list (
+		function () {
+			library ("R2HTML")
+		}
+	## the tests
+	), tests = list (
+		new ("RKTest", id="active_binding", call=function () {
+			.GlobalEnv$active.binding.value <- 1
+			makeActiveBinding ("active.binding", function () { message ("active.binding"); .GlobalEnv$active.binding.value }, .GlobalEnv)
+
+			rk.sync.global ()
+			message ("after sync")
+
+			stopifnot (.GlobalEnv$active.binding == .GlobalEnv$active.binding.value)
+
+			.GlobalEnv$active.binding.value <- 123
+			stopifnot (.GlobalEnv$active.binding == 123)
+
+			stopifnot (bindingIsActive ("active.binding", rkward::.rk.watched.symbols))
+
+			# NOTE: the message "active.binding" should be displayed in the message output
+		}),
+		new ("RKTest", id="promise_in_globalenv", call=function () {
+			.GlobalEnv$promised.value <- 1
+			delayedAssign ("promise.symbol", { message ("delayed assign"); promised.value }, eval.env=.GlobalEnv, assign.env=.GlobalEnv)
+
+			rk.sync.global () # should evaluate the promise, but not force it permanently
+			message ("after sync")
+
+			.GlobalEnv$promised.value <- 123
+			# promise should be permanently forced at this point:
+			stopifnot (.GlobalEnv$promise.symbol == .GlobalEnv$promised.value)
+
+			# promise should not be evaluated again
+			.GlobalEnv$promised.value <- 245
+			stopifnot (.GlobalEnv$promise.symbol == 123)
+		})
+	# postCalls are run *after* all tests. Use this to clean up
+	), postCalls = list (
+		function () {
+		}
+	)
+)
+
+## always store the result in "results" and print it
+results <- rktest.runRKTestSuite (suite)
+print (results)


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list