brandizzi
brandizzi

Reputation: 27050

Setting an attribute used by JSLint JavaScript code in RhinoUnit

I am trying to use RhinoUnit for unit testing of a standalone, XUL-based JavaScript app. I have successfully altered a lot of paths in the given build.xml - mostly changing paths to RhinoUnit scripts, which I prefer to put in another directory than the default one (that is, I put RhinoUnit files in chrome/content/rhino and JSLint files in chrome/content/lint). On some moment, however, I've got this error:

/<project-path>/build.xml:52: javax.script.ScriptException: 
sun.org.mozilla.javascript.internal.WrappedException: Wrapped 
java.io.FileNotFoundException: /<project-path>/jslint/fulljslint.js
(No such file or directory) (<Unknown source>#31) in <Unknown source>
at line number 31

There is no reference to jslint/fulljslint.js in the build.xml, but I have found this code at jslintant.js:

var jsLintPath = "jslint/fulljslint.js";
if (attributes.get("jslintpath")) {
    jsLintPath = attributes.get("jslintpath");
}

It looked to me that this code sets a default value to the variable and then try to use the value from some attributes object. I am supposing these attributes can be set outside the script, through e.g. some <atttribute /> tag int build.xml or some configuration file.

My question is: how could I change the value from the object? Is that possible? Or should I change the hardcoded string from the script?

Upvotes: 1

Views: 660

Answers (1)

martin clayton
martin clayton

Reputation: 78135

Here's a possibility to consider.

How to figure out what's going on: If you insert this in the jslintant.js file, just prior to the jsLintPath assignment you mention:

echo = project.createTask( "echo" );
echo.setMessage( attributes );
echo.perform( );

Then run the RhinoUnit build, you should see something like:

run-js-lint:
     [echo] {options={eqeqeq : false, white: true, plusplus : false, bitwise :  ... }}

How to do what you want: The 'options' are defned as an attribute of the jslintant scriptdef. To propagate a value for jslintpath, you need to add it as an attribute in the scriptdef, then set it when you use the task so defined. For example:

<scriptdef name="jslintant"
           src="jslint/jslintant.js"
           language="javascript">
    <attribute name="options" />
    <attribute name="jslintpath" /> <!-- This line added. -->
    <element name="fileset" type="fileset" />
</scriptdef>

then use the task:

<jslintant options="{eqeqeq : false, ... }"
           jslintpath="your_path_here/fulljslint.js" />

If you rerun the build, you should then see:

run-js-lint:
     [echo] {jslintpath=your_path_here/fulljslint.js, options={eqeqeq : false, ... }}

And the path you chose will be used to find fulljslint.js.

Upvotes: 1

Related Questions