2011-07-23 19 views
1

我正在嘗試使用RhinoUnit對基於XUL的獨立JavaScript應用程序進行單元測試。我已經成功地修改了大量的路徑build.xml - 主要是改變RhinoUnit腳本的路徑,我寧願將其放在另一個目錄中,而不是默認路徑(也就是說,我將RhinoUnit文件放在chrome/content/rhino和JSLint文件的chrome/content/lint中)。在某些時刻,但是,我得到這個錯誤:在RhinoUnit中設置JSLint JavaScript代碼使用的屬性

/<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 

有一個在build.xmljslint/fulljslint.js沒有提及,但我發現這個代碼在jslintant.js

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

它看着我該代碼將默認值設置爲變量,然後嘗試使用某個對象的值。我認爲這些attributes可以通過例如腳本設置在腳本之外。一些<atttribute />標籤int build.xml或一些配置文件。

我的問題是:我怎麼能改變對象的值?那可能嗎?或者我應該從腳本中更改硬編碼的字符串?

回答

1

這是一個可以考慮的可能性。

如何弄清楚是怎麼回事: 如果您在jslintant.js文件中插入此,剛剛你提到的jsLintPath分配前:

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

然後運行RhinoUnit打造,你應該看到的東西像:

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

怎麼做你想要什麼:的「選項'被定義爲jslintant scriptdef的屬性。要傳播jslintpath的值,需要將其作爲scriptdef中的一個屬性添加,然後在使用如此定義的任務時對其進行設置。例如:

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

然後使用任務:

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

如果重新運行構建,你應該再看看:

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

而你選擇的路徑將被用於查找fulljslint.js