Closed Bug 580620 Opened 15 years ago Closed 15 years ago

Implement a general assert function (to replace assertJS in nearly all cases)

Categories

(Testing Graveyard :: Mozmill, defect)

defect
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: whimboo, Assigned: whimboo)

References

Details

(Whiteboard: [mozmill-1.4.2+][mozmill-doc-complete])

Attachments

(1 file, 1 obsolete file)

Similar to bug 579943 it would helpful to also have a general assert function available which also gives us the chance to specify a closure function for the evaluation and to remove the eval expression. Patch is upcoming in a minute...
Comment on attachment 459005 [details] [diff] [review] Patch to introduce assert >diff --git a/mozmill/mozmill/extension/resource/modules/controller.js b/mozmill/mozmill/extension/resource/modules/controller.js >index e0b1e56..02cdacd 100644 >--- a/mozmill/mozmill/extension/resource/modules/controller.js >+++ b/mozmill/mozmill/extension/resource/modules/controller.js >@@ -55,6 +55,7 @@ var aConsoleService = Components.classes["@mozilla.org/consoleservice;1"]. > > // Declare most used utils functions in the controller namespace > var sleep = utils.sleep; >+var assert = utils.assert; > var waitFor = utils.waitFor; > var waitForEval = utils.waitForEval; > >@@ -685,18 +686,24 @@ MozMillController.prototype.assertValue = function (el, value) { > return false; > }; > >+/** >+ * Check if the callback function evaluates to true >+ */ >+MozMillController.prototype.assert = function(callback) >+{ <snip/> > //Assert that a provided value is selected in a select element >diff --git a/mozmill/mozmill/extension/resource/modules/utils.js b/mozmill/mozmill/extension/resource/modules/utils.js >index f3f3ce8..9cc9a71 100644 >--- a/mozmill/mozmill/extension/resource/modules/utils.js >+++ b/mozmill/mozmill/extension/resource/modules/utils.js >@@ -403,6 +403,19 @@ function sleep(milliseconds) { > } > > /** >+ * Check if the callback function evaluates to true >+ */ >+MozMillController.prototype.assert = function(callback) { Why is this also MozMillController.prototype.assert? Should it just be `function assert()` >+ var result = callback(); >+ >+ if (!result) { >+ throw new Error(arguments.callee.name + ": Failed for '" + callback + "'"); I'd prefer if this was a new error type, AssertionError, but its not that important
Comment on attachment 459005 [details] [diff] [review] Patch to introduce assert need clarification as to why you define MozMillController.prototype.assert twice (once in utils and once in controller)
Attachment #459005 - Flags: review?(jhammel) → review-
We should look into implementing (stealing code from node/narwhal) the commonJS assert module for mozmill 2.0 http://wiki.commonjs.org/wiki/Unit_Testing/1.0#Assert.
Whiteboard: [mozmill-1.4.2?] → [mozmill-1.4.2+]
Attached patch Patch v2Splinter Review
Attachment #459005 - Attachment is obsolete: true
Attachment #460862 - Flags: review?(jhammel)
Comment on attachment 460862 [details] [diff] [review] Patch v2 looks good
Attachment #460862 - Flags: review?(jhammel) → review+
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Whiteboard: [mozmill-1.4.2+] → [mozmill-1.4.2+][mozmill-doc-needed]
Verified via running sample code for pass and fail
Status: RESOLVED → VERIFIED
Whiteboard: [mozmill-1.4.2+][mozmill-doc-needed] → [mozmill-1.4.2+][mozmill-doc-complete]
Product: Testing → Testing Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: