From d943d5b1b95f64715e5834e5b9e5b4d78e541a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20N=C3=A9h=C3=A9mie?= Date: Thu, 11 Jul 2013 15:56:36 +0200 Subject: [PATCH 01/19] Add support for deep nested context As it was until now both the console and html reporters was only reporting and counting tests in describes defined at the top level. The assertions messages are also printed in console when the test failed. --- core-packages/testing/lib/index.jsx | 102 ++++++++++++++++++++++------ 1 file changed, 81 insertions(+), 21 deletions(-) diff --git a/core-packages/testing/lib/index.jsx b/core-packages/testing/lib/index.jsx index 1b98897..d1ba9bb 100644 --- a/core-packages/testing/lib/index.jsx +++ b/core-packages/testing/lib/index.jsx @@ -17,29 +17,57 @@ var Template = require("templating").Template; var TestRunner = function () { this._clean_results = function (suites, results) { + var self = this var cleaned_results = suites.map(function(suite) { - var total = suite.children.length; - var passed = suite.children.filter(function(spec) { - return (results[spec.id].result == "passed"); - }).length; + + var specs = suite.children.map(function (spec) { - return {'name': spec.name, - 'result': results[spec.id].result, - 'messages': results[spec.id].messages + if(spec.type === 'suite'){ + return self._clean_results([spec], results)[0] + } + else { + + return { + 'name': spec.name, + 'result': results[spec.id].result, + 'messages': results[spec.id].messages, + 'type': 'spec' } + } }); + var total = specs.reduce(function(a,b){ + if(b.type === 'suite'){ + return a + b.total + } else { + return a + 1 + } + }, 0); + var passed = specs.reduce(function(a,b){ + if(b.type === 'suite'){ + return a + b.total + } else { + if(b.result == "passed"){ + return a + 1 + } else { + return a; + } + } + }, 0); + return { 'name': suite.name, 'passed': passed, 'failed': new Number(total - passed), 'total': total, - 'specs': specs + 'specs': specs, + 'type': 'suite' }; }); return cleaned_results; } + this.run = function () { var reporter = new jasmine.JsApiReporter(); jasmine.getEnv().addReporter(reporter); @@ -68,33 +96,65 @@ var TestRunner = function () { } + this.print_suite = function(suite){ + var self = this; + suite.specs.forEach(function(spec) { + if(spec.type == 'suite'){ + self.print_suite(spec) + } + else { + $.writeln("\t" + spec.result.toUpperCase() + "\t" + spec.name); + if(spec.result != 'passed'){ + $.writeln('\t\t'+spec.messages.join('\n\t\t')) + } + } + }); + } + this.to_console = function () { var results = this.run(); - + var self = this results.forEach(function(suite) { $.writeln("\nSuite: {} \tran {} tests, {} failure(s)".format(suite.name, suite.total, suite.failed)); - suite.specs.forEach(function(spec) { - $.writeln("\t" + spec.result.toUpperCase() + "\t" + spec.name); - }); + self.print_suite(suite) }); } + this.to_log = function () { // todo } + this.flatten = function(specs, res) { + res = res || []; + var self = this + specs.forEach(function(el){ + if(el.type === 'suite'){ + self.flatten(el.specs, res) + } else { + res.push(el) + } + }) + + return res; + } + this.to_html = function (filename) { // some background info var datetime = new Date(); var date = datetime.toDateString(); var time = "{}:{}".format(datetime.getHours(), datetime.getMinutes()); - var environment = this.get_environment(); + var environment = this.get_environment(); // run tests var results = this.run(); - + var self = this + // tidy up results results.forEach(function(suite) { + var prevSpecs = self.flatten(suite.specs); + + suite.specs = prevSpecs; suite.specs.forEach(function(spec) { if (spec.result == 'failed') { var messages = spec.messages.reject(function (message) { @@ -106,15 +166,15 @@ var TestRunner = function () { } }); }); - + var duration = ((new Date().getTime() - datetime.getTime())/1000).toFixed(2); - var template = new Template("report.html", module); + var template = new Template("report.html", module); template.render({ - 'date': date, - 'time': time, - 'duration': duration, - 'suites': results, + 'date': date, + 'time': time, + 'duration': duration, + 'suites': results, 'total': results.sum('total'), 'fails': results.sum('failed'), 'passes': results.sum('passed'), @@ -130,4 +190,4 @@ var TestRunner = function () { } } -exports.tests = new TestRunner(); \ No newline at end of file +exports.tests = new TestRunner(); From 86515b1a94a89048a2fe4e3b12809460343a3eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20N=C3=A9h=C3=A9mie?= Date: Thu, 11 Jul 2013 16:01:19 +0200 Subject: [PATCH 02/19] Fix jasmine not returning the full description in spec summary. The spec summary was only storing the spec description and not the full name with the spec groups descriptions. --- dependencies/jasmine.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dependencies/jasmine.js b/dependencies/jasmine.js index 1adab61..dd5b18e 100644 --- a/dependencies/jasmine.js +++ b/dependencies/jasmine.js @@ -1,4 +1,4 @@ -/** +/** * Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework. * * @namespace @@ -126,7 +126,7 @@ jasmine.getEnv = function() { * @returns {Boolean} */ jasmine.isArray_ = function(value) { - return jasmine.isA_("Array", value); + return jasmine.isA_("Array", value); }; /** @@ -973,7 +973,7 @@ jasmine.Block = function(env, func, spec) { this.spec = spec; }; -jasmine.Block.prototype.execute = function(onComplete) { +jasmine.Block.prototype.execute = function(onComplete) { try { this.func.apply(this.spec); } catch (e) { @@ -1009,11 +1009,11 @@ jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { var isSuite = suiteOrSpec instanceof jasmine.Suite; var summary = { id: suiteOrSpec.id, - name: suiteOrSpec.description, + name: suiteOrSpec.getFullName(), type: isSuite ? 'suite' : 'spec', children: [] }; - + if (isSuite) { var children = suiteOrSpec.children(); for (var i = 0; i < children.length; i++) { @@ -1714,7 +1714,7 @@ jasmine.Queue.prototype.next_ = function() { while (goAgain) { goAgain = false; - + if (self.index < self.blocks.length && !this.abort) { var calledSynchronously = true; var completedSynchronously = false; @@ -1752,7 +1752,7 @@ jasmine.Queue.prototype.next_ = function() { if (completedSynchronously) { onComplete(); } - + } else { self.running = false; if (self.onComplete) { @@ -2428,4 +2428,4 @@ jasmine.version_= { "minor": 0, "build": 0, "revision": 1284494074 -}; \ No newline at end of file +}; From dca8666d03484c6f1ef9d5fd8d6e61f87ec70081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20N=C3=A9h=C3=A9mie?= Date: Thu, 11 Jul 2013 16:08:22 +0200 Subject: [PATCH 03/19] Add support for the options hash in control methods The add_control method was accepting an options hash that wasn't available in the various convenience methods. --- core-packages/ui/lib/index.jsx | 116 ++++++++++++++++----------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/core-packages/ui/lib/index.jsx b/core-packages/ui/lib/index.jsx index 69c2601..7df9681 100644 --- a/core-packages/ui/lib/index.jsx +++ b/core-packages/ui/lib/index.jsx @@ -1,4 +1,4 @@ -function EventManager (control, type) { +function EventManager (control, type) { this.control = control; this.type = type; this.do = function (fn) { @@ -21,7 +21,7 @@ function ControlMixins () { } else { this[property] = mixin[property]; } - } + } } } @@ -33,22 +33,22 @@ function ControlMixins () { function UIShortcuts () { /* CONTAINER TYPES */ - + /** @desc adds a group, displayed as a row */ this.row = function (name) { - var group = this.add_group(name); + var group = this.add_group(name); group.window.orientation = 'row'; return group; } /** @desc adds a group, displayed as a column */ this.column = function (name) { - var group = this.add_group(name); - group.window.orientation = 'column'; + var group = this.add_group(name); + group.window.orientation = 'column'; return group; } /** @desc adds a group, displayed as a stack */ this.stack = function (name) { - var group = this.add_group(name); + var group = this.add_group(name); group.window.orientation = 'stack'; return group; } @@ -60,14 +60,14 @@ function UIShortcuts () { */ this.panel = function (name, properties) { var properties = properties || {}; - return this.add_container(name, 'panel', properties); + return this.add_container(name, 'panel', properties); } - /** + /** * @desc adds a list, equivalent to ``listbox`` in plain ScriptUI * @param {String} name The name this list will take on within the dialog object * @param {String[]|Number} [headers] - * Either just a number of columns, or an array with + * Either just a number of columns, or an array with * header names. Once set, you may not add list items * with more columns than available in the header. * @param {Object} [properties] any other properties you want to pass along on creation @@ -79,8 +79,8 @@ function UIShortcuts () { properties.merge({'numberOfColumns': headers}); } else { properties.merge({ - 'numberOfColumns': headers.length, - 'showHeaders': true, + 'numberOfColumns': headers.length, + 'showHeaders': true, 'columnTitles': headers }); } @@ -91,68 +91,68 @@ function UIShortcuts () { /* SIMPLE TYPES */ /** @desc adds a button */ - this.button = function (name, text) { - return this.add_control(name, 'button', text); + this.button = function (name, text, options) { + return this.add_control(name, 'button', text, options); } /** @desc adds a checkbox */ - this.checkbox = function (name, text) { - return this.add_control(name, 'checkbox', text); + this.checkbox = function (name, text, options) { + return this.add_control(name, 'checkbox', text, options); } /** @desc adds a dropdown, equivalent to ``dropdownlist`` in plain ScriptUI */ - this.dropdown = function (name, text) { - return this.add_control(name, 'dropdownlist', text); + this.dropdown = function (name, text, options) { + return this.add_control(name, 'dropdownlist', text, options); } /** @desc adds an input field, equivalent to ``edittext`` in plain ScriptUI */ - this.input = function (name, text) { - return this.add_control(name, 'edittext', text); + this.input = function (name, text, options) { + return this.add_control(name, 'edittext', text, options); } /** @desc adds an item (part of a list) */ this.item = function (name, values) { - return this.add_item(name, values); + return this.add_item(name, values); } /** @desc adds a flash element, equivalent to ``flashplayer`` in plain ScriptUI */ - this.flash = function (name, text) { - return this.add_control(name, 'flashplayer', text); + this.flash = function (name, text, options) { + return this.add_control(name, 'flashplayer', text, options); } /** @desc adds an icon button, equivalent to ``iconbutton`` in plain ScriptUI */ - this.icon = function (name, text) { - return this.add_control(name, 'iconbutton', text); + this.icon = function (name, text, options) { + return this.add_control(name, 'iconbutton', text, options); } /** @desc adds an image */ - this.image = function (name, text) { - return this.add_control(name, 'image', text); + this.image = function (name, text, options) { + return this.add_control(name, 'image', text, options); } /** @desc adds a progress bar */ - this.progressbar = function (name, text) { - return this.add_control(name, 'progressbar', text); + this.progressbar = function (name, text, options) { + return this.add_control(name, 'progressbar', text, options); } /** @desc adds a radio button, equivalent to ``radiobutton`` in plain ScriptUI */ - this.radio = function (name, text) { - return this.add_control(name, 'radiobutton', text); + this.radio = function (name, text, options) { + return this.add_control(name, 'radiobutton', text, options); } /** @desc adds a scrollbar */ - this.scrollbar = function (name, text) { - return this.add_control(name, 'scrollbar', text); + this.scrollbar = function (name, text, options) { + return this.add_control(name, 'scrollbar', text, options); } /** @desc adds a slider */ - this.slider = function (name, text) { - return this.add_control(name, 'slider', text); + this.slider = function (name, text, options) { + return this.add_control(name, 'slider', text, options); } /** @desc adds a text element, equivalent to ``statictext`` in plain ScriptUI */ - this.text = function (name, text) { - return this.add_control(name, 'statictext', text); + this.text = function (name, text, options) { + return this.add_control(name, 'statictext', text, options); } /** @desc adds a tab (part of a tabs control) */ - this.tab = function (name, text) { - return this.add_control(name, 'tab', text); + this.tab = function (name, text, options) { + return this.add_control(name, 'tab', text, options); } /** @desc adds a tabs container, equivalent to ``tabbedpanel`` in plain ScriptUI */ - this.tabs = function (name, text) { - return this.add_control(name, 'tabbedpanel', text); + this.tabs = function (name, text, options) { + return this.add_control(name, 'tabbedpanel', text, options); } /** @desc adds a tree, equivalent to ``treeview`` in plain ScriptUI */ - this.tree = function (name, text) { - return this.add_control(name, 'treeview', text); + this.tree = function (name, text, options) { + return this.add_control(name, 'treeview', text, options); } } @@ -162,16 +162,16 @@ function UIShortcuts () { * Don't instantiate this class directly. */ -function UI () { - var self = this; - +function UI () { + var self = this; + this.mixins = {}; this.merge(new UIShortcuts()); // this variable is continually updated to reflect the last added layout element this._last_added = this; - + /** * @desc To make ``UI`` methods chainable, they return the entire * ``UI`` object instead of any control element you may have just created; @@ -200,7 +200,7 @@ function UI () { */ this.using = function () { // arguments may be passed either as variable arguments or as an array - var mixin_names = arguments.to('array').flatten(); + var mixin_names = arguments.to('array').flatten(); mixin_names.forEach(function(mixin_name){ var mixin = self.mixins[mixin_name]; if (mixin == undefined) { @@ -227,15 +227,15 @@ function UI () { control.merge(new ControlMixins()); this[name] = control; self._last_added = control; - return this; + return this; } - + this.add_control = function (name, type, text, properties) { - // people can add controls to this object willy-nilly, + // people can add controls to this object willy-nilly, // so we check whether they're not overriding any existing - // methods, attributes or controls. + // methods, attributes or controls. if (this[name] != undefined) throw new Error("{} is a reserved name.".format(name)); - + var control = self.window.add(type, undefined, text, properties); control.merge(new ControlMixins()); this[name] = control; @@ -248,7 +248,7 @@ function UI () { } this.add_list = function (name, properties) { - return this.add_container(name, 'listbox', properties); + return this.add_container(name, 'listbox', properties); } this.add_container = function (name, type, properties) { @@ -257,7 +257,7 @@ function UI () { ui._last_added = ui.window; ui.mixins = this.mixins; this[name] = ui; - return ui; + return ui; } } @@ -266,12 +266,12 @@ function UI () { exports.Dialog = function (title) { var ui = new UI(); - ui.window = new Window('dialog', title); + ui.window = new Window('dialog', title); return ui; } exports.Palette = function (title) { var ui = new UI(); - ui.window = new Window('palette', title); + ui.window = new Window('palette', title); return ui; -} \ No newline at end of file +} From efcb650f3b07374e27e0f8379260019698d09603 Mon Sep 17 00:00:00 2001 From: abe33 Date: Tue, 23 Jul 2013 09:50:49 +0200 Subject: [PATCH 04/19] WIP: Starting merging back changes made in a local version --- core-packages/__future__/lib/exceptions/index.jsx | 0 core-packages/__future__/lib/ideas.txt | 0 .../__future__/lib/persistence/engines.jsx | 0 core-packages/__future__/lib/persistence/index.jsx | 0 core-packages/__future__/lib/preview/idea.txt | 0 core-packages/http/doc/readme.rst | 0 core-packages/http/lib/auth.jsx | 0 core-packages/http/lib/browser.jsx | 0 core-packages/http/lib/index.jsx | 0 core-packages/http/lib/url.jsx | 0 core-packages/http/test/http.specs | 0 core-packages/io/lib/index.jsx | 0 core-packages/io/lib/octals.jsx | 0 core-packages/io/test/io.specs | 0 core-packages/logging/doc/readme.rst | 0 core-packages/logging/lib/index.jsx | 0 core-packages/logging/test/logging.specs | 0 core-packages/persistence/lib/index.jsx | 0 core-packages/templating/doc/readme.rst | 0 core-packages/templating/lib/index.jsx | 0 core-packages/templating/test/templating.specs | 0 core-packages/testing/doc/readme.rst | 0 core-packages/testing/doc/unit-testing.png | Bin core-packages/testing/lib/index.jsx | 11 ++++++----- .../testing/templates/partial.environment.html | 0 core-packages/testing/templates/partial.suite.html | 0 core-packages/testing/templates/partial.test.html | 0 core-packages/testing/templates/report.html | 0 core-packages/ui/doc/layout.png | Bin core-packages/ui/doc/readme.rst | 0 core-packages/ui/doc/reference.rst | 0 core-packages/ui/lib/_ideas_.jsx | 0 core-packages/ui/lib/index.jsx | 2 +- core-packages/ui/test/mixins.specs | 0 core-packages/ui/test/ui.specs | 0 core-packages/utils/lib/array.jsx | 0 core-packages/utils/lib/date.jsx | 0 core-packages/utils/lib/error.jsx | 0 core-packages/utils/lib/file.jsx | 0 core-packages/utils/lib/folder.jsx | 0 core-packages/utils/lib/index.jsx | 0 core-packages/utils/lib/math.jsx | 0 core-packages/utils/lib/object.conversions.jsx | 0 core-packages/utils/lib/object.jsx | 0 core-packages/utils/lib/string.jsx | 0 45 files changed, 7 insertions(+), 6 deletions(-) mode change 100644 => 100755 core-packages/__future__/lib/exceptions/index.jsx mode change 100644 => 100755 core-packages/__future__/lib/ideas.txt mode change 100644 => 100755 core-packages/__future__/lib/persistence/engines.jsx mode change 100644 => 100755 core-packages/__future__/lib/persistence/index.jsx mode change 100644 => 100755 core-packages/__future__/lib/preview/idea.txt mode change 100644 => 100755 core-packages/http/doc/readme.rst mode change 100644 => 100755 core-packages/http/lib/auth.jsx mode change 100644 => 100755 core-packages/http/lib/browser.jsx mode change 100644 => 100755 core-packages/http/lib/index.jsx mode change 100644 => 100755 core-packages/http/lib/url.jsx mode change 100644 => 100755 core-packages/http/test/http.specs mode change 100644 => 100755 core-packages/io/lib/index.jsx mode change 100644 => 100755 core-packages/io/lib/octals.jsx mode change 100644 => 100755 core-packages/io/test/io.specs mode change 100644 => 100755 core-packages/logging/doc/readme.rst mode change 100644 => 100755 core-packages/logging/lib/index.jsx mode change 100644 => 100755 core-packages/logging/test/logging.specs mode change 100644 => 100755 core-packages/persistence/lib/index.jsx mode change 100644 => 100755 core-packages/templating/doc/readme.rst mode change 100644 => 100755 core-packages/templating/lib/index.jsx mode change 100644 => 100755 core-packages/templating/test/templating.specs mode change 100644 => 100755 core-packages/testing/doc/readme.rst mode change 100644 => 100755 core-packages/testing/doc/unit-testing.png mode change 100644 => 100755 core-packages/testing/lib/index.jsx mode change 100644 => 100755 core-packages/testing/templates/partial.environment.html mode change 100644 => 100755 core-packages/testing/templates/partial.suite.html mode change 100644 => 100755 core-packages/testing/templates/partial.test.html mode change 100644 => 100755 core-packages/testing/templates/report.html mode change 100644 => 100755 core-packages/ui/doc/layout.png mode change 100644 => 100755 core-packages/ui/doc/readme.rst mode change 100644 => 100755 core-packages/ui/doc/reference.rst mode change 100644 => 100755 core-packages/ui/lib/_ideas_.jsx mode change 100644 => 100755 core-packages/ui/lib/index.jsx mode change 100644 => 100755 core-packages/ui/test/mixins.specs mode change 100644 => 100755 core-packages/ui/test/ui.specs mode change 100644 => 100755 core-packages/utils/lib/array.jsx mode change 100644 => 100755 core-packages/utils/lib/date.jsx mode change 100644 => 100755 core-packages/utils/lib/error.jsx mode change 100644 => 100755 core-packages/utils/lib/file.jsx mode change 100644 => 100755 core-packages/utils/lib/folder.jsx mode change 100644 => 100755 core-packages/utils/lib/index.jsx mode change 100644 => 100755 core-packages/utils/lib/math.jsx mode change 100644 => 100755 core-packages/utils/lib/object.conversions.jsx mode change 100644 => 100755 core-packages/utils/lib/object.jsx mode change 100644 => 100755 core-packages/utils/lib/string.jsx diff --git a/core-packages/__future__/lib/exceptions/index.jsx b/core-packages/__future__/lib/exceptions/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/__future__/lib/ideas.txt b/core-packages/__future__/lib/ideas.txt old mode 100644 new mode 100755 diff --git a/core-packages/__future__/lib/persistence/engines.jsx b/core-packages/__future__/lib/persistence/engines.jsx old mode 100644 new mode 100755 diff --git a/core-packages/__future__/lib/persistence/index.jsx b/core-packages/__future__/lib/persistence/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/__future__/lib/preview/idea.txt b/core-packages/__future__/lib/preview/idea.txt old mode 100644 new mode 100755 diff --git a/core-packages/http/doc/readme.rst b/core-packages/http/doc/readme.rst old mode 100644 new mode 100755 diff --git a/core-packages/http/lib/auth.jsx b/core-packages/http/lib/auth.jsx old mode 100644 new mode 100755 diff --git a/core-packages/http/lib/browser.jsx b/core-packages/http/lib/browser.jsx old mode 100644 new mode 100755 diff --git a/core-packages/http/lib/index.jsx b/core-packages/http/lib/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/http/lib/url.jsx b/core-packages/http/lib/url.jsx old mode 100644 new mode 100755 diff --git a/core-packages/http/test/http.specs b/core-packages/http/test/http.specs old mode 100644 new mode 100755 diff --git a/core-packages/io/lib/index.jsx b/core-packages/io/lib/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/io/lib/octals.jsx b/core-packages/io/lib/octals.jsx old mode 100644 new mode 100755 diff --git a/core-packages/io/test/io.specs b/core-packages/io/test/io.specs old mode 100644 new mode 100755 diff --git a/core-packages/logging/doc/readme.rst b/core-packages/logging/doc/readme.rst old mode 100644 new mode 100755 diff --git a/core-packages/logging/lib/index.jsx b/core-packages/logging/lib/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/logging/test/logging.specs b/core-packages/logging/test/logging.specs old mode 100644 new mode 100755 diff --git a/core-packages/persistence/lib/index.jsx b/core-packages/persistence/lib/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/templating/doc/readme.rst b/core-packages/templating/doc/readme.rst old mode 100644 new mode 100755 diff --git a/core-packages/templating/lib/index.jsx b/core-packages/templating/lib/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/templating/test/templating.specs b/core-packages/templating/test/templating.specs old mode 100644 new mode 100755 diff --git a/core-packages/testing/doc/readme.rst b/core-packages/testing/doc/readme.rst old mode 100644 new mode 100755 diff --git a/core-packages/testing/doc/unit-testing.png b/core-packages/testing/doc/unit-testing.png old mode 100644 new mode 100755 diff --git a/core-packages/testing/lib/index.jsx b/core-packages/testing/lib/index.jsx old mode 100644 new mode 100755 index d1ba9bb..f2a1343 --- a/core-packages/testing/lib/index.jsx +++ b/core-packages/testing/lib/index.jsx @@ -67,12 +67,14 @@ var TestRunner = function () { return cleaned_results; } - this.run = function () { + if(this.results) return this.results; + var reporter = new jasmine.JsApiReporter(); jasmine.getEnv().addReporter(reporter); jasmine.getEnv().execute(); - return this._clean_results(reporter.suites_, reporter.results()); + this.results = this._clean_results(reporter.suites_, reporter.results()); + return this.results } this.get_environment = function () { @@ -90,10 +92,10 @@ var TestRunner = function () { }); } - // we'll add this into the html representation, + // we'll add this into the html representation, // so people can upload structured test reports to our central server. this.as_json = function () { - + } this.print_suite = function(suite){ @@ -120,7 +122,6 @@ var TestRunner = function () { }); } - this.to_log = function () { // todo } diff --git a/core-packages/testing/templates/partial.environment.html b/core-packages/testing/templates/partial.environment.html old mode 100644 new mode 100755 diff --git a/core-packages/testing/templates/partial.suite.html b/core-packages/testing/templates/partial.suite.html old mode 100644 new mode 100755 diff --git a/core-packages/testing/templates/partial.test.html b/core-packages/testing/templates/partial.test.html old mode 100644 new mode 100755 diff --git a/core-packages/testing/templates/report.html b/core-packages/testing/templates/report.html old mode 100644 new mode 100755 diff --git a/core-packages/ui/doc/layout.png b/core-packages/ui/doc/layout.png old mode 100644 new mode 100755 diff --git a/core-packages/ui/doc/readme.rst b/core-packages/ui/doc/readme.rst old mode 100644 new mode 100755 diff --git a/core-packages/ui/doc/reference.rst b/core-packages/ui/doc/reference.rst old mode 100644 new mode 100755 diff --git a/core-packages/ui/lib/_ideas_.jsx b/core-packages/ui/lib/_ideas_.jsx old mode 100644 new mode 100755 diff --git a/core-packages/ui/lib/index.jsx b/core-packages/ui/lib/index.jsx old mode 100644 new mode 100755 index 7df9681..cea559d --- a/core-packages/ui/lib/index.jsx +++ b/core-packages/ui/lib/index.jsx @@ -1,4 +1,4 @@ -function EventManager (control, type) { +function EventManager (control, type) { this.control = control; this.type = type; this.do = function (fn) { diff --git a/core-packages/ui/test/mixins.specs b/core-packages/ui/test/mixins.specs old mode 100644 new mode 100755 diff --git a/core-packages/ui/test/ui.specs b/core-packages/ui/test/ui.specs old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/array.jsx b/core-packages/utils/lib/array.jsx old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/date.jsx b/core-packages/utils/lib/date.jsx old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/error.jsx b/core-packages/utils/lib/error.jsx old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/file.jsx b/core-packages/utils/lib/file.jsx old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/folder.jsx b/core-packages/utils/lib/folder.jsx old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/index.jsx b/core-packages/utils/lib/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/math.jsx b/core-packages/utils/lib/math.jsx old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/object.conversions.jsx b/core-packages/utils/lib/object.conversions.jsx old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/object.jsx b/core-packages/utils/lib/object.jsx old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/string.jsx b/core-packages/utils/lib/string.jsx old mode 100644 new mode 100755 From bb7832ee293d95b8096bf1f22f3a4005ace9f0ea Mon Sep 17 00:00:00 2001 From: abe33 Date: Tue, 23 Jul 2013 09:52:51 +0200 Subject: [PATCH 05/19] Add a standalone options that can be used to exclude code when running a packaged version --- context.jsx | 0 extendables.jsx | 48 ++++++++++++++++++++++++++---------------------- loader.jsx | 0 settings.jsx | 0 4 files changed, 26 insertions(+), 22 deletions(-) mode change 100644 => 100755 context.jsx mode change 100644 => 100755 extendables.jsx mode change 100644 => 100755 loader.jsx mode change 100644 => 100755 settings.jsx diff --git a/context.jsx b/context.jsx old mode 100644 new mode 100755 diff --git a/extendables.jsx b/extendables.jsx old mode 100644 new mode 100755 index 0c0188c..cbf4544 --- a/extendables.jsx +++ b/extendables.jsx @@ -1,29 +1,33 @@ -// we need to log somethings before the log module is loaded, +// we need to log somethings before the log module is loaded, // so we buffer these messages var log_buffer = []; #include "patches/__all__.jsx"; -var default_settings = new File("settings.jsx").at(Folder.extendables); -var project_specific_settings = new File("settings.jsx").at(Folder.extendables.parent); -if (project_specific_settings.exists) { - // allows for project-specific settings, so nobody - // has to override anything within /extendables - // (this feature is currently undocumented) - log_buffer.push([4, "Loading Extendables with project-specific settings at {}", project_specific_settings]); - $.evalFile(project_specific_settings); -} else { - log_buffer.push([4, "Loading Extendables with default settings"]); - $.evalFile(default_settings); -} -#include "loader.jsx"; -load_modules(settings.package_directories); -#include "context.jsx"; -// write away buffered log messages +if(!this.standalone){ + var default_settings = new File("settings.jsx").at(Folder.extendables); + var project_specific_settings = new File("settings.jsx").at(Folder.extendables.parent); + + if (project_specific_settings.exists) { + // allows for project-specific settings, so nobody + // has to override anything within /extendables + // (this feature is currently undocumented) + log_buffer.push([4, "Loading Extendables with project-specific settings at {}", project_specific_settings]); + $.evalFile(project_specific_settings); + } else { + log_buffer.push([4, "Loading Extendables with default settings"]); + $.evalFile(default_settings); + } + #include "loader.jsx"; + load_modules(settings.package_directories); + #include "context.jsx"; -var logging = require("logging"); -var syslog = new logging.Log("extendables.log"); + // write away buffered log messages -log_buffer.forEach(function (message) { - syslog.log.apply(null, message); -}); \ No newline at end of file + var logging = require("logging"); + var syslog = new logging.Log("extendables.log"); + + log_buffer.forEach(function (message) { + syslog.log.apply(null, message); + }); +} diff --git a/loader.jsx b/loader.jsx old mode 100644 new mode 100755 diff --git a/settings.jsx b/settings.jsx old mode 100644 new mode 100755 From 1fadc3030b834d1ba1c6e68f09dcebd7ddfe0a94 Mon Sep 17 00:00:00 2001 From: abe33 Date: Tue, 23 Jul 2013 09:55:23 +0200 Subject: [PATCH 06/19] Fix creation of containers through the convenience methods --- core-packages/ui/lib/index.jsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core-packages/ui/lib/index.jsx b/core-packages/ui/lib/index.jsx index cea559d..680d618 100755 --- a/core-packages/ui/lib/index.jsx +++ b/core-packages/ui/lib/index.jsx @@ -58,9 +58,9 @@ function UIShortcuts () { * @param {String} name The name this panel will take on within the dialog object * @param {Object} [properties] any other properties you want to pass along on creation */ - this.panel = function (name, properties) { + this.panel = function (name, label, properties) { var properties = properties || {}; - return this.add_container(name, 'panel', properties); + return this.add_container(name, 'panel', label, properties); } /** @@ -144,11 +144,11 @@ function UIShortcuts () { } /** @desc adds a tab (part of a tabs control) */ this.tab = function (name, text, options) { - return this.add_control(name, 'tab', text, options); + return this.add_container(name, 'tab', text, options); } /** @desc adds a tabs container, equivalent to ``tabbedpanel`` in plain ScriptUI */ this.tabs = function (name, text, options) { - return this.add_control(name, 'tabbedpanel', text, options); + return this.add_container(name, 'tabbedpanel', text, options); } /** @desc adds a tree, equivalent to ``treeview`` in plain ScriptUI */ this.tree = function (name, text, options) { @@ -243,17 +243,17 @@ function UI () { return this; } - this.add_group = function (name, properties) { - return this.add_container(name, 'group', properties); + this.add_group = function (name, label, properties) { + return this.add_container(name, 'group', label, properties); } - this.add_list = function (name, properties) { - return this.add_container(name, 'listbox', properties); + this.add_list = function (name, label, properties) { + return this.add_container(name, 'listbox', label, properties); } - this.add_container = function (name, type, properties) { + this.add_container = function (name, type, label, properties) { var ui = new UI(); - ui.window = this.add_control(name, type, undefined, properties).el(); + ui.window = this.add_control(name, type, label, properties).el(); ui._last_added = ui.window; ui.mixins = this.mixins; this[name] = ui; From b005e329da3de1f12a7a8f10920be4c9dfde8406 Mon Sep 17 00:00:00 2001 From: abe33 Date: Tue, 23 Jul 2013 10:07:12 +0200 Subject: [PATCH 07/19] Add site-packages as ignored from git --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index eb6565c..b319ee6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ doc/_build doc/jsdoc patches/doc/jsdoc core-packages/*/doc/jsdoc +site-packages *.pyc *.old *.orig From 8e7618904c891b25561e7e7da1f934d2186f4a68 Mon Sep 17 00:00:00 2001 From: abe33 Date: Thu, 25 Jul 2013 12:38:55 +0200 Subject: [PATCH 08/19] Make sure the exports object is defined in base64 --- core-packages/ui/lib/index.jsx | 1 + core-packages/utils/lib/object.conversions.jsx | 16 ++++++++-------- dependencies/base64.js | 5 +++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/core-packages/ui/lib/index.jsx b/core-packages/ui/lib/index.jsx index 680d618..9314e3c 100755 --- a/core-packages/ui/lib/index.jsx +++ b/core-packages/ui/lib/index.jsx @@ -63,6 +63,7 @@ function UIShortcuts () { return this.add_container(name, 'panel', label, properties); } + /** * @desc adds a list, equivalent to ``listbox`` in plain ScriptUI * @param {String} name The name this list will take on within the dialog object diff --git a/core-packages/utils/lib/object.conversions.jsx b/core-packages/utils/lib/object.conversions.jsx index e4623df..7de8021 100755 --- a/core-packages/utils/lib/object.conversions.jsx +++ b/core-packages/utils/lib/object.conversions.jsx @@ -1,4 +1,4 @@ -var exports = {}; +var exports = exports || {}; var base64 = exports; #include "../dependencies/base64.js" #include "../dependencies/json2.js" @@ -31,12 +31,12 @@ keyvalue.decode = function (str, options) { pair = pair.split(separator); obj[pair[0]] = pair[1]; }); - return obj; + return obj; } /** * @desc Object serialization. - * + * * The result of serialization followed by deserialization is the original object, whereas * a conversion is not reversible. * @@ -89,11 +89,11 @@ exports.deserialize = function (self, type, options) { } /** - * @desc Provides easy shortcuts to a number of common conversions, like lowercasing a string or + * @desc Provides easy shortcuts to a number of common conversions, like lowercasing a string or * converting the ``arguments`` object to an array. - * + * * All of these conversions return a new object, they do not modify the original. - * + * * A ``slug`` is a string that's usable as a filename or in an URL: it's * a lowercased string with all non-alphanumeric characters stripped out, and spaces replaced by * hyphens. @@ -115,7 +115,7 @@ exports.deserialize = function (self, type, options) { exports.to = function (self, type) { // never, ever modify the original object var result = object.clone(self); - + var conversions = { /* types */ // REFACTOR: 'int' should be 'number', to correspond to the class name! @@ -137,4 +137,4 @@ exports.to = function (self, type) { } else { throw RangeError(string.format("This method cannot convert from {} to {}", self.prototype.name, type)); } -} \ No newline at end of file +} diff --git a/dependencies/base64.js b/dependencies/base64.js index b21bd59..68271da 100644 --- a/dependencies/base64.js +++ b/dependencies/base64.js @@ -1,4 +1,5 @@ -exports.encode64 = encoder('+/'); +exports = exports || {} +exports.encode64 = encoder('+/'); exports.decode64 = decoder('+/'); exports.urlsafeEncode64 = encoder('-_'); exports.urlsafeDecode64 = decoder('-_'); @@ -78,4 +79,4 @@ function alphabet(extra) { function regexp_escape(expr) { return expr.replace(/([\^\$\/\.\*\-\+\?\|\(\)\[\]\{\}\\])/, '\\$1'); -} \ No newline at end of file +} From 607ababb40addb12fd1f3da8c442c01651769a9b Mon Sep 17 00:00:00 2001 From: abe33 Date: Thu, 25 Jul 2013 12:39:49 +0200 Subject: [PATCH 09/19] Update gitignore with sublime text files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b319ee6..8d1e25c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ site-packages *.old *.orig *(Autosaved)* +*.sublime-* From d2905f30f35aecf86dabbebc35af24fe4941431b Mon Sep 17 00:00:00 2001 From: abe33 Date: Mon, 29 Jul 2013 09:06:10 +0200 Subject: [PATCH 10/19] Change the tree helper to be a container helper instead of a simple control --- core-packages/ui/lib/index.jsx | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/core-packages/ui/lib/index.jsx b/core-packages/ui/lib/index.jsx index 9314e3c..7d0792c 100755 --- a/core-packages/ui/lib/index.jsx +++ b/core-packages/ui/lib/index.jsx @@ -89,6 +89,16 @@ function UIShortcuts () { return this.add_list(name, properties); } + /** @desc adds a tree, equivalent to ``treeview`` in plain ScriptUI */ + // this.tree = function (name, text, options) { + // return this.add_control(name, 'treeview', text, options); + // } + + this.tree = function(name, properties) { + var properties = properties || {}; + return this.add_tree(name, properties); + } + /* SIMPLE TYPES */ /** @desc adds a button */ @@ -151,10 +161,6 @@ function UIShortcuts () { this.tabs = function (name, text, options) { return this.add_container(name, 'tabbedpanel', text, options); } - /** @desc adds a tree, equivalent to ``treeview`` in plain ScriptUI */ - this.tree = function (name, text, options) { - return this.add_control(name, 'treeview', text, options); - } } /** @@ -218,7 +224,7 @@ function UI () { } this.add_item = function (name, values) { - if (this[name] != undefined) throw new Error("{} is a reserved name.".format(name)); + //if (this[name] != undefined) throw new Error("{} is a reserved name.".format(name)); if (!values.is(Array)) throw new TypeError("A list item expects an array of text labels, not a string"); var control = self.window.add('item', values.shift()); values.forEach(function (value, i) { @@ -248,8 +254,12 @@ function UI () { return this.add_container(name, 'group', label, properties); } - this.add_list = function (name, label, properties) { - return this.add_container(name, 'listbox', label, properties); + this.add_list = function (name, properties) { + return this.add_container(name, 'listbox', null, properties); + } + + this.add_tree = function (name, properties) { + return this.add_container(name, 'treeview', null, properties); } this.add_container = function (name, type, label, properties) { From 4efa36028bdf77986f77be776999417d5dffd4e5 Mon Sep 17 00:00:00 2001 From: abe33 Date: Mon, 29 Jul 2013 11:01:46 +0200 Subject: [PATCH 11/19] Implements module caching like commonjs modules --- loader.jsx | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/loader.jsx b/loader.jsx index 53a9992..4fdadd2 100755 --- a/loader.jsx +++ b/loader.jsx @@ -4,15 +4,16 @@ */ var __modules__ = {}; +var __cache__ = {} function require (module_id) { // CommonJS: A module identifier is a String of "terms" var terms = module_id.split('/'); var module = terms.shift(); if (__modules__.hasOwnProperty(module)) { if (terms.length) { - return __modules__[module].get_submodule(terms).load().exports; + return __cache__[module_id] = __cache__[module_id] || __modules__[module].get_submodule(terms).load().exports; } else { - return __modules__[module].load().exports; + return __cache__[module] = __cache__[module] || __modules__[module].load().exports; } } else { throw Error("No package named " + module_id); @@ -32,9 +33,9 @@ function _is_valid_module (file_or_folder) { return file_or_folder.is(Folder) || file_or_folder.name.endswith(".jsx"); } -function Module (file_or_folder, is_package) { +function Module (file_or_folder, is_package) { var self = this; - + this.eval = function (file) { var exports = {}; var module = { @@ -45,9 +46,9 @@ function Module (file_or_folder, is_package) { try { $.evalFile(file); } catch (error) { - log_buffer.push([3, "Could not fully load " + module.id + "\n" + error]); + log_buffer.push([3, "Could not fully load " + module.id + "\n" + error]); } - return exports; + return exports; }; this.extract_submodules = function () { @@ -56,7 +57,7 @@ function Module (file_or_folder, is_package) { base.changePath("./lib"); } var submodule_files = base.getFiles(_is_valid_module); - + submodule_files.forEach(function(submodule) { var submodule = new Module(submodule); self.submodules[submodule.id] = submodule; @@ -99,7 +100,7 @@ function Module (file_or_folder, is_package) { } return self } - + /* init */ this.id = file_or_folder.displayName.split('.')[0]; this.uri = file_or_folder.absoluteURI; @@ -118,13 +119,13 @@ function load_modules (packagefolders) { var folder = packagefolder; } var packages = folder.getFiles(_is_valid_module); - + packages.forEach(function(file_or_folder) { // An alias regists as a file in ExtendScript, even if it refers to a folder. // Check if the file is an alias and, if so, resolve it. if (file_or_folder.alias) file_or_folder = file_or_folder.resolve(); var module = new Module(file_or_folder, true); __modules__[module.id] = module; - }); + }); }); -} \ No newline at end of file +} From bf3a817d0dc5630d6f4f1904004e1e34008b0e39 Mon Sep 17 00:00:00 2001 From: abe33 Date: Thu, 1 Aug 2013 10:30:20 +0200 Subject: [PATCH 12/19] Add an option to set the state of the checkbox at creation --- core-packages/ui/lib/index.jsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core-packages/ui/lib/index.jsx b/core-packages/ui/lib/index.jsx index 7d0792c..bc5fd7a 100755 --- a/core-packages/ui/lib/index.jsx +++ b/core-packages/ui/lib/index.jsx @@ -106,8 +106,17 @@ function UIShortcuts () { return this.add_control(name, 'button', text, options); } /** @desc adds a checkbox */ - this.checkbox = function (name, text, options) { - return this.add_control(name, 'checkbox', text, options); + this.checkbox = function (name, text, value, options) { + if(typeof value === 'object') { + options = value; + value = false; + } + var checkbox = this.add_control(name, 'checkbox', text, options); + $.writeln(value) + $.writeln(checkbox) + this[name].value = value + return checkbox + } /** @desc adds a dropdown, equivalent to ``dropdownlist`` in plain ScriptUI */ this.dropdown = function (name, text, options) { From a7f9e93c64363ab7bba55ce80e8a3daf1a7bbc67 Mon Sep 17 00:00:00 2001 From: abe33 Date: Mon, 6 Oct 2014 17:11:34 +0200 Subject: [PATCH 13/19] :fire: Remove log --- core-packages/ui/lib/index.jsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/core-packages/ui/lib/index.jsx b/core-packages/ui/lib/index.jsx index bc5fd7a..fbd8c6c 100755 --- a/core-packages/ui/lib/index.jsx +++ b/core-packages/ui/lib/index.jsx @@ -112,8 +112,6 @@ function UIShortcuts () { value = false; } var checkbox = this.add_control(name, 'checkbox', text, options); - $.writeln(value) - $.writeln(checkbox) this[name].value = value return checkbox From 8cfea0e44990eeed93ffe432c67043ad16642da8 Mon Sep 17 00:00:00 2001 From: abe33 Date: Mon, 6 Oct 2014 17:11:53 +0200 Subject: [PATCH 14/19] :lipstick: Whitespace --- core-packages/utils/lib/error.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-packages/utils/lib/error.jsx b/core-packages/utils/lib/error.jsx index 9627e4b..ba0934c 100755 --- a/core-packages/utils/lib/error.jsx +++ b/core-packages/utils/lib/error.jsx @@ -1,7 +1,7 @@ /** * @desc This method overloads :func:`Object#is` to combat a problem with some versions of ExtendScript * that leads to all error types being considered the base class Error. This problem makes it impossible to - * do simple comparisons on errors, for example ``new EvalError() instanceof SyntaxError``. The previous + * do simple comparisons on errors, for example ``new EvalError() instanceof SyntaxError``. The previous * expression should return false but will return true. * * When testing whether you're dealing with a specific kind of error, use this method, and refrain @@ -167,4 +167,4 @@ if (is_indesign) { * @name ValidationError */ ValidationError.prototype._type = ValidationError; -} \ No newline at end of file +} From 0c0ac84d9b0be08212022015afc1efd472255bd3 Mon Sep 17 00:00:00 2001 From: abe33 Date: Mon, 6 Oct 2014 17:12:20 +0200 Subject: [PATCH 15/19] Handle wrap_methods_with_try_catch in module load --- loader.jsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/loader.jsx b/loader.jsx index 4fdadd2..4ed7280 100755 --- a/loader.jsx +++ b/loader.jsx @@ -48,6 +48,24 @@ function Module (file_or_folder, is_package) { } catch (error) { log_buffer.push([3, "Could not fully load " + module.id + "\n" + error]); } + if(exports.wrap_methods_with_try_catch){ + var props = exports.keys() + props.forEach(function(k){ + + if(typeof exports[k] === 'function' && k[0].toLowerCase() === k[0]){ + var original = exports[k] + + exports[k] = function(){ + try { + return original.apply(this, arguments) + } + catch(e){ + throw e + } + } + } + }) + } return exports; }; From 5b32c29d967a540588af4e01396f5ede1fd672bf Mon Sep 17 00:00:00 2001 From: abe33 Date: Mon, 6 Oct 2014 17:12:45 +0200 Subject: [PATCH 16/19] Extend Error with a toString method for nice logging --- patches/error.jsx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/patches/error.jsx b/patches/error.jsx index 84772d3..80b2126 100644 --- a/patches/error.jsx +++ b/patches/error.jsx @@ -1,7 +1,7 @@ /** * @desc This method overloads :func:`Object#is` to combat a problem with some versions of ExtendScript * that leads to all error types being considered the base class Error. This problem makes it impossible to - * do simple comparisons on errors, for example ``new EvalError() instanceof SyntaxError``. The previous + * do simple comparisons on errors, for example ``new EvalError() instanceof SyntaxError``. The previous * expression should return false but will return true. * * When testing whether you're dealing with a specific kind of error, use this method, and refrain @@ -35,6 +35,23 @@ Error.prototype.is = function (type) { } } +Error.prototype.toString = function() { + if (typeof this.stack === "undefined" || this.stack === null) { + this.stack = []; + // The previous line is needed because the next line may indirectly call this method. + this.stack = $.stack; + } + return this.formatErrorMessage(); +} + +Error.prototype.formatErrorMessage = function() { + var res = '' + res += this.message + '\n' + res += 'line: ' + this.line + ', file: ' + this.fileName + '\n' + res += this.stack ? this.stack : '' + return res; +} + /** * @desc Use this classmethod to make sure your custom error types work * just like the built-in ones. @@ -165,4 +182,4 @@ if (app.name.to('lower').contains("indesign")) { * @name ValidationError */ ValidationError.prototype._type = ValidationError; -} \ No newline at end of file +} From c8e7baa2d8a6c6d54f6103a5bcbffaece34f7eee Mon Sep 17 00:00:00 2001 From: abe33 Date: Tue, 7 Oct 2014 09:53:55 +0200 Subject: [PATCH 17/19] :bug: Fix bad failures count report in console --- core-packages/testing/lib/index.jsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core-packages/testing/lib/index.jsx b/core-packages/testing/lib/index.jsx index f2a1343..780900a 100755 --- a/core-packages/testing/lib/index.jsx +++ b/core-packages/testing/lib/index.jsx @@ -117,7 +117,9 @@ var TestRunner = function () { var results = this.run(); var self = this results.forEach(function(suite) { - $.writeln("\nSuite: {} \tran {} tests, {} failure(s)".format(suite.name, suite.total, suite.failed)); + var passed = suite.specs.filter(function(s){ return s.result == 'passed' }).length + var failed = suite.specs.filter(function(s){ return s.result != 'passed' }).length + $.writeln("\nSuite: {} \tran {} tests, {} failure(s)".format(suite.name, suite.total, failed)); self.print_suite(suite) }); } From 20fd55f3bcf89168baeea05e3cb82788345ccdda Mon Sep 17 00:00:00 2001 From: abe33 Date: Tue, 7 Oct 2014 10:44:19 +0200 Subject: [PATCH 18/19] :bug: Fix missing counter when value is 0 --- core-packages/testing/lib/index.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core-packages/testing/lib/index.jsx b/core-packages/testing/lib/index.jsx index 780900a..6b8a75e 100755 --- a/core-packages/testing/lib/index.jsx +++ b/core-packages/testing/lib/index.jsx @@ -117,9 +117,9 @@ var TestRunner = function () { var results = this.run(); var self = this results.forEach(function(suite) { - var passed = suite.specs.filter(function(s){ return s.result == 'passed' }).length - var failed = suite.specs.filter(function(s){ return s.result != 'passed' }).length - $.writeln("\nSuite: {} \tran {} tests, {} failure(s)".format(suite.name, suite.total, failed)); + var passed = suite.specs.filter(function(s){ return s.result == 'passed' }).length || '0'; + var failed = suite.specs.filter(function(s){ return s.result != 'passed' }).length || '0'; + $.writeln("\nSuite: {} \tran {} tests, {} success, {} failure(s)".format(suite.name, suite.total, passed, failed)); self.print_suite(suite) }); } From 2171d7d1f46a330f0da46c2d95de243c0f5428e2 Mon Sep 17 00:00:00 2001 From: abe33 Date: Tue, 7 Oct 2014 15:07:01 +0200 Subject: [PATCH 19/19] Add inspect method on Object and Array --- core-packages/utils/lib/array.jsx | 36 ++++++++++++++----------- core-packages/utils/lib/object.jsx | 27 +++++++++++-------- patches/array.jsx | 42 ++++++++++++++++++------------ patches/object.jsx | 39 ++++++++++++++++++++------- 4 files changed, 92 insertions(+), 52 deletions(-) diff --git a/core-packages/utils/lib/array.jsx b/core-packages/utils/lib/array.jsx index 4837a51..ede1818 100755 --- a/core-packages/utils/lib/array.jsx +++ b/core-packages/utils/lib/array.jsx @@ -8,7 +8,7 @@ var utils = require("utils/object"); * @desc Returns the first index at which a given element can be found in the selfay, or -1 if it is not present. * * @param {Object} element - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf */ @@ -47,12 +47,12 @@ exports.indexAfter = function (obj, element) { } /** - * @desc Returns the last index at which a given element can be found in the selfay, + * @desc Returns the last index at which a given element can be found in the selfay, * or -1 if it is not present. The selfay is searched backwards, starting at from_index. * * @param {Object} element * @param {Number} from_index - * + * * @see https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/lastIndexOf */ @@ -89,7 +89,7 @@ exports.lastIndexOf = function(self, elt /*, from*/) * @desc Tests whether all elements in the selfay pass the test implemented by the provided function. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every */ @@ -111,7 +111,7 @@ exports.every = function(self, fun /*, thisp*/) { /** * @desc Creates a new selfay with all elements that pass the test implemented by the provided function. - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter */ @@ -140,7 +140,7 @@ exports.filter = function(self, fun /*, thisp*/) * @desc Executes a provided function once per selfay element. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach */ @@ -162,7 +162,7 @@ exports.filter = function(self, fun /*, thisp*/) * @desc Creates a new selfay with the results of calling a provided function on every element in this selfay. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map */ @@ -186,7 +186,7 @@ exports.map = function(self, fun /*, thisp*/) { * @desc Tests whether some element in the selfay passes the test implemented by the provided function. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some */ @@ -212,11 +212,11 @@ exports.some = function(self, fun /*, thisp*/) /* Javascript 1.8 Array extras, courtesy of Mozilla */ /** - * @desc Apply a function against an accumulator and + * @desc Apply a function against an accumulator and * each value of the selfay (from left-to-right) as to reduce it to a single value. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/Reduce */ @@ -266,7 +266,7 @@ exports.some = function(self, fun /*, thisp*/) * as to reduce it to a single value. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/ReduceRight */ @@ -353,7 +353,7 @@ exports.max = function (self, salient) { } else { var mapper = salient || function (obj) { return obj; } } - + function fn (a, b) { return mapper(a) > mapper(b); } @@ -374,7 +374,7 @@ exports.min = function (self, salient) { } else { var mapper = salient || function (obj) { return obj; } } - + function fn (a, b) { return mapper(a) > mapper(b); } @@ -406,7 +406,7 @@ exports.sum = function (self, salient) { } var features = exports.map(self, mapper); - return exports.reduce(features, function (a, b) { return a + b; }); + return exports.reduce(features, function (a, b) { return a + b; }); } /** @@ -478,4 +478,10 @@ exports.last = function (self) { exports.contains = function (self, obj) { return exports.indexOf(self, obj) != -1; -} \ No newline at end of file +} + +exports.log = function(self, dump) { + return '[' + exports.map(self, function(item) { + item.log ? item.inspect(dump) : item.toString() + }).join(', ') + ']' +} diff --git a/core-packages/utils/lib/object.jsx b/core-packages/utils/lib/object.jsx index db4323c..6b051b2 100755 --- a/core-packages/utils/lib/object.jsx +++ b/core-packages/utils/lib/object.jsx @@ -1,12 +1,12 @@ -/* - * Patches for functional programming. - * Inspired by and sometimes copied from underscore.js +/* + * Patches for functional programming. + * Inspired by and sometimes copied from underscore.js */ /** * @desc Merge two objects together. This modifies the original object. * First use :func:`Object#clone` on the object if you want to keep the original object intact. - * + * * @param {Object} obj The object to merge into this one. * * @returns {Object} Returns the merged object (``this``); @@ -14,7 +14,7 @@ exports.merge = function (self, obj) { if (!obj) return; - + var merged_obj = self; for (var name in obj) { merged_obj[name] = obj[name]; @@ -46,7 +46,7 @@ exports.clone = function (self) { /** * @desc * Returns only the keys (also known as 'names') of an object or associative array. - * Will filter out any functions, as these are presumed to be object methods. + * Will filter out any functions, as these are presumed to be object methods. * @returns {Array} An array with all the keys. */ @@ -74,7 +74,7 @@ exports.values = function (self) { for (var i = 0; i < keys.length; i++) { values.push(self[keys[i]]); } - + return values; } @@ -98,8 +98,8 @@ exports.is = function(self, type) { exports.has = function (self, key) { // could be just null or an invalid object // either way, has() should return false - if (self == null || self[key] == null) return false; - + if (self == null || self[key] == null) return false; + if (key in self) { return new Boolean(self[key]) != false; } else { @@ -125,6 +125,11 @@ exports.has_own = function (self, key) { */ exports.log = function (self, dump) { + var out = exports.inspect(self, dump); + return $.writeln(out); +} + +exports.inspect = function(self, dump) { if (dump) { var props = exports.keys(self.reflect.properties); for (var i = 0; i < props.length; i++) { @@ -135,5 +140,5 @@ exports.log = function (self, dump) { } else { var out = self.toString(); } - return $.writeln(out); -} \ No newline at end of file + return out; +} diff --git a/patches/array.jsx b/patches/array.jsx index b467bf7..7e3e23b 100644 --- a/patches/array.jsx +++ b/patches/array.jsx @@ -6,7 +6,7 @@ * @desc Returns the first index at which a given element can be found in the array, or -1 if it is not present. * * @param {Object} element - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf */ @@ -45,12 +45,12 @@ Array.prototype.indexAfter = function (element) { } /** - * @desc Returns the last index at which a given element can be found in the array, + * @desc Returns the last index at which a given element can be found in the array, * or -1 if it is not present. The array is searched backwards, starting at from_index. * * @param {Object} element * @param {Number} from_index - * + * * @see https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/lastIndexOf */ @@ -87,7 +87,7 @@ Array.prototype.indexAfter = function (element) { * @desc Tests whether all elements in the array pass the test implemented by the provided function. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every */ @@ -110,7 +110,7 @@ Array.prototype.indexAfter = function (element) { /** * @desc Creates a new array with all elements that pass the test implemented by the provided function. - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter */ @@ -139,7 +139,7 @@ Array.prototype.indexAfter = function (element) { * @desc Executes a provided function once per array element. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach */ @@ -161,7 +161,7 @@ Array.prototype.indexAfter = function (element) { * @desc Creates a new array with the results of calling a provided function on every element in this array. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map */ @@ -186,7 +186,7 @@ Array.prototype.indexAfter = function (element) { * @desc Tests whether some element in the array passes the test implemented by the provided function. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some */ @@ -212,11 +212,11 @@ Array.prototype.indexAfter = function (element) { /* Javascript 1.8 Array extras, courtesy of Mozilla */ /** - * @desc Apply a function against an accumulator and + * @desc Apply a function against an accumulator and * each value of the array (from left-to-right) as to reduce it to a single value. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/Reduce */ @@ -266,7 +266,7 @@ Array.prototype.indexAfter = function (element) { * as to reduce it to a single value. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/ReduceRight */ @@ -353,7 +353,7 @@ Array.prototype.max = function (salient) { } else { var mapper = salient || function (obj) { return obj; } } - + function fn (a, b) { return mapper(a) > mapper(b); } @@ -374,7 +374,7 @@ Array.prototype.min = function (salient) { } else { var mapper = salient || function (obj) { return obj; } } - + function fn (a, b) { return mapper(a) > mapper(b); } @@ -406,8 +406,8 @@ Array.prototype.sum = function (salient) { } var features = this.map(mapper); - - return features.reduce(function (a, b) { return a + b; }); + + return features.reduce(function (a, b) { return a + b; }); } /** @@ -479,4 +479,14 @@ Array.prototype.last = function () { Array.prototype.contains = function (obj) { return this.indexOf(obj) != -1; -} \ No newline at end of file +} + +Array.prototype.inspect = function(dump) { + return '[' + this.map(function(item) { + return item.inspect ? item.inspect(dump) : item.toString() + }).join(', ') + ']' +} + +Array.prototype.log = function(dump) { + $.writeln(this.inspect(dump)); +} diff --git a/patches/object.jsx b/patches/object.jsx index e484f55..adf67b8 100644 --- a/patches/object.jsx +++ b/patches/object.jsx @@ -1,12 +1,12 @@ -/* - * Patches for functional programming. - * Inspired by and sometimes copied from underscore.js +/* + * Patches for functional programming. + * Inspired by and sometimes copied from underscore.js */ /** * @desc Merge two objects together. This modifies the original object. * First use :func:`Object#clone` on the object if you want to keep the original object intact. - * + * * @param {Object} obj The object to merge into this one. * * @returns {Object} Returns the merged object (``this``); @@ -14,7 +14,7 @@ Object.prototype.merge = function (obj) { if (!obj) return; - + var merged_obj = this; for (var name in obj) { merged_obj[name] = obj[name]; @@ -46,7 +46,7 @@ Object.prototype.clone = function () { /** * @desc * Returns only the keys (also known as 'names') of an object or associative array. - * Will filter out any functions, as these are presumed to be object methods. + * Will filter out any functions, as these are presumed to be object methods. * @returns {Array} An array with all the keys. */ @@ -95,8 +95,8 @@ Object.prototype.is = function(type) { Object.prototype.has = function (key) { // could be just null or an invalid object // either way, has() should return false - if (this == null || this[key] == null) return false; - + if (this == null || this[key] == null) return false; + if (key in this) { return new Boolean(this[key]) != false; } else { @@ -125,10 +125,29 @@ Object.prototype.to_console = function (dump) { if (dump) { var obj = this; var out = obj.reflect.properties.map(function (property) { - return property.name + "\t => " + obj[property.name]; + return property.name + "\t => " + obj[property.name]; }).join("\n"); } else { var out = this.toString(); } return $.writeln(out); -} \ No newline at end of file +} + +Object.prototype.log = function (dump) { + var out = this.inspect(dump); + return $.writeln(out); +} + +Object.prototype.inspect = function(dump) { + if (dump) { + var props = this.keys(); + for (var i = 0; i < props.length; i++) { + var property = props[i]; + props[i] = property + ": " + this[property]; + } + var out = "{" + props.join(", ") + "}"; + } else { + var out = this.toString(); + } + return out; +}