|
From: <cr...@us...> - 2009-02-16 13:47:37
|
Revision: 5032
http://jnode.svn.sourceforge.net/jnode/?rev=5032&view=rev
Author: crawley
Date: 2009-02-16 13:47:27 +0000 (Mon, 16 Feb 2009)
Log Message:
-----------
Add support for input and output files to the black-box test harness
Modified Paths:
--------------
trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java
trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml
trunk/shell/src/test/org/jnode/test/shell/harness/ClassTestRunner.java
trunk/shell/src/test/org/jnode/test/shell/harness/CommandTestRunner.java
trunk/shell/src/test/org/jnode/test/shell/harness/ScriptTestRunner.java
trunk/shell/src/test/org/jnode/test/shell/harness/TestHarness.java
trunk/shell/src/test/org/jnode/test/shell/harness/TestRunnable.java
trunk/shell/src/test/org/jnode/test/shell/harness/TestSpecification.java
trunk/shell/src/test/org/jnode/test/shell/harness/TestSpecificationParser.java
Added Paths:
-----------
trunk/shell/src/test/org/jnode/test/shell/harness/TestRunnerBase.java
Removed Paths:
-------------
trunk/shell/src/test/org/jnode/test/shell/harness/JNodeTestRunnerBase.java
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java 2009-02-15 22:30:50 UTC (rev 5031)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java 2009-02-16 13:47:27 UTC (rev 5032)
@@ -39,6 +39,7 @@
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -913,7 +914,7 @@
map.put(var.name, var.value);
}
}
- return map;
+ return Collections.unmodifiableMap(map);
}
PrintStream resolvePrintStream(CommandIO commandIOIF) {
Modified: trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml 2009-02-15 22:30:50 UTC (rev 5031)
+++ trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml 2009-02-16 13:47:27 UTC (rev 5032)
@@ -588,9 +588,9 @@
echo 'a b'
echo "a b"
echo $*
- echo $@
+ echo $@@
echo "$*"
- echo "$@"
+ echo "$@@"
</script>
<arg>arg1</arg>
<arg>arg2</arg>
@@ -611,4 +611,11 @@
+ echo arg1 arg2
</error>
</testSpec>
+ <testSpec title="redirection" command="test" runMode="AS_SCRIPT" rc="0">
+ <script>#!bjorne
+ echo > @TEMP_DIR@/blablah Hi mum
+ </script>
+ <file name="blablah" input="false">Hi mum
+</file>
+ </testSpec>
</testSet>
\ No newline at end of file
Modified: trunk/shell/src/test/org/jnode/test/shell/harness/ClassTestRunner.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/harness/ClassTestRunner.java 2009-02-15 22:30:50 UTC (rev 5031)
+++ trunk/shell/src/test/org/jnode/test/shell/harness/ClassTestRunner.java 2009-02-16 13:47:27 UTC (rev 5032)
@@ -20,9 +20,7 @@
package org.jnode.test.shell.harness;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
+import java.io.IOException;
import java.lang.reflect.Method;
/**
@@ -31,17 +29,10 @@
*
* @author cr...@jn...
*/
-class ClassTestRunner implements TestRunnable {
+class ClassTestRunner extends TestRunnerBase implements TestRunnable {
- private ByteArrayOutputStream outBucket;
- private ByteArrayOutputStream errBucket;
-
- private final TestSpecification spec;
- private final TestHarness harness;
-
public ClassTestRunner(TestSpecification spec, TestHarness harness) {
- this.spec = spec;
- this.harness = harness;
+ super(spec, harness);
}
@Override
@@ -53,24 +44,11 @@
return check() ? 0 : 1;
}
- private boolean check() {
+ private boolean check() throws IOException {
// When a class is run this way we cannot capture the RC.
return
harness.expect(outBucket.toString(), spec.getOutputContent(), "output content") &
- harness.expect(errBucket.toString(), spec.getErrorContent(), "err content");
+ harness.expect(errBucket.toString(), spec.getErrorContent(), "err content") &
+ checkFiles();
}
-
- @Override
- public void cleanup() {
- }
-
- @Override
- public void setup() {
- System.setIn(new ByteArrayInputStream(spec.getInputContent().toString().getBytes()));
- outBucket = new ByteArrayOutputStream();
- errBucket = new ByteArrayOutputStream();
- System.setOut(new PrintStream(outBucket));
- System.setErr(new PrintStream(errBucket));
- }
-
}
Modified: trunk/shell/src/test/org/jnode/test/shell/harness/CommandTestRunner.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/harness/CommandTestRunner.java 2009-02-15 22:30:50 UTC (rev 5031)
+++ trunk/shell/src/test/org/jnode/test/shell/harness/CommandTestRunner.java 2009-02-16 13:47:27 UTC (rev 5032)
@@ -20,9 +20,7 @@
package org.jnode.test.shell.harness;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
+import java.io.IOException;
import org.jnode.shell.CommandShell;
@@ -33,12 +31,8 @@
*
* @author cr...@jn...
*/
-class CommandTestRunner extends JNodeTestRunnerBase implements TestRunnable {
+class CommandTestRunner extends TestRunnerBase implements TestRunnable {
- private ByteArrayOutputStream outBucket;
- private ByteArrayOutputStream errBucket;
-
-
public CommandTestRunner(TestSpecification spec, TestHarness harness) {
super(spec, harness);
}
@@ -55,24 +49,11 @@
return check(rc) ? 0 : 1;
}
- private boolean check(int rc) {
+ private boolean check(int rc) throws IOException {
return
harness.expect(rc, spec.getRc(), "return code") &
harness.expect(outBucket.toString(), spec.getOutputContent(), "output content") &
- harness.expect(errBucket.toString(), spec.getErrorContent(), "err content");
+ harness.expect(errBucket.toString(), spec.getErrorContent(), "err content") &
+ checkFiles();
}
-
- @Override
- public void cleanup() {
- }
-
- @Override
- public void setup() {
- System.setIn(new ByteArrayInputStream(spec.getInputContent().toString().getBytes()));
- outBucket = new ByteArrayOutputStream();
- errBucket = new ByteArrayOutputStream();
- System.setOut(new PrintStream(outBucket));
- System.setErr(new PrintStream(errBucket));
- }
-
}
Deleted: trunk/shell/src/test/org/jnode/test/shell/harness/JNodeTestRunnerBase.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/harness/JNodeTestRunnerBase.java 2009-02-15 22:30:50 UTC (rev 5031)
+++ trunk/shell/src/test/org/jnode/test/shell/harness/JNodeTestRunnerBase.java 2009-02-16 13:47:27 UTC (rev 5032)
@@ -1,144 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2003-2009 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.test.shell.harness;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FilterOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
-
-import org.jnode.naming.InitialNaming;
-import org.jnode.plugin.PluginManager;
-import org.jnode.shell.CommandShell;
-import org.jnode.shell.ShellException;
-
-/**
- * This base class supplies functions for getting hold of "the shell" for
- * testing commands, configuring required plugins and setting up the
- * System streams for a command.
- *
- * @author cr...@jn...
- */
-public abstract class JNodeTestRunnerBase implements TestRunnable {
-
- private class TeeStream extends FilterOutputStream {
- private OutputStream out2;
-
- public TeeStream(OutputStream out, OutputStream out2) {
- super(out);
- this.out2 = out2;
- }
-
- @Override
- public void close() throws IOException {
- super.close();
- out2.close();
- }
-
- @Override
- public void flush() throws IOException {
- super.flush();
- out2.flush();
- }
-
- @Override
- public void write(int b) throws IOException {
- super.write(b);
- out2.write(b);
- }
- }
-
- protected ByteArrayOutputStream outBucket;
- protected ByteArrayOutputStream errBucket;
-
- protected final TestSpecification spec;
- protected final TestHarness harness;
-
- protected final boolean usingEmu;
-
- public JNodeTestRunnerBase(TestSpecification spec, TestHarness harness) {
- super();
- this.spec = spec;
- this.harness = harness;
- this.usingEmu = TestEmu.initEmu(harness.getRoot());
- }
-
- public CommandShell getShell() throws ShellException {
- CommandShell shell = TestEmu.getShell();
- if (shell == null) {
- shell = new TestCommandShell(System.in, System.out, System.err);
- shell.configureShell();
- }
- return shell;
- }
-
- @Override
- public void cleanup() {
- }
-
- @Override
- public void setup() {
- ensurePluginsLoaded(spec.getTestSet());
- for (PluginSpecification plugin : spec.getPlugins()) {
- ensurePluginLoaded(plugin);
- }
- System.setIn(new ByteArrayInputStream(spec.getInputContent().toString().getBytes()));
- outBucket = new ByteArrayOutputStream();
- errBucket = new ByteArrayOutputStream();
- if (harness.isDebug()) {
- System.setOut(new PrintStream(new TeeStream(outBucket, System.out)));
- System.setErr(new PrintStream(new TeeStream(errBucket, System.err)));
- } else {
- System.setOut(new PrintStream(outBucket));
- System.setErr(new PrintStream(errBucket));
- }
- }
-
- private void ensurePluginsLoaded(TestSetSpecification testSet) {
- if (testSet == null) {
- return;
- }
- ensurePluginsLoaded(testSet.getParentSet());
- for (PluginSpecification plugin : spec.getTestSet().getPlugins()) {
- ensurePluginLoaded(plugin);
- }
- }
-
- protected void ensurePluginLoaded(PluginSpecification plugin) {
- if (usingEmu) {
- TestEmu.loadPseudoPlugin(plugin.getPluginId(), plugin.getClassName());
- } else {
- // TODO - I'm not sure about this. A simpler alternative is to assume
- // that all required plugins have already been loaded by JNode.
- String ver = (plugin.getPluginVersion().length() == 0) ?
- System.getProperty("os.version") : plugin.getPluginVersion();
- try {
- PluginManager mgr = InitialNaming.lookup(PluginManager.NAME);
- mgr.getRegistry().loadPlugin(mgr.getLoaderManager(), plugin.getPluginId(), ver);
- } catch (Exception ex) {
- throw new RuntimeException(
- "Cannot load plugin '" + plugin.getPluginId() + "/" + ver + "'");
- }
- }
- }
-}
Modified: trunk/shell/src/test/org/jnode/test/shell/harness/ScriptTestRunner.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/harness/ScriptTestRunner.java 2009-02-15 22:30:50 UTC (rev 5031)
+++ trunk/shell/src/test/org/jnode/test/shell/harness/ScriptTestRunner.java 2009-02-16 13:47:27 UTC (rev 5032)
@@ -20,9 +20,13 @@
package org.jnode.test.shell.harness;
+import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
-import java.io.Writer;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.Properties;
/**
@@ -31,7 +35,7 @@
*
* @author cr...@jn...
*/
-class ScriptTestRunner extends JNodeTestRunnerBase implements TestRunnable {
+class ScriptTestRunner extends TestRunnerBase implements TestRunnable {
private File tempScriptFile;
@@ -41,25 +45,28 @@
@Override
public int run() throws Exception {
+ Properties props = new Properties();
+ props.setProperty("TEMP_DIR", System.getProperty("java.io.tmpdir"));
tempScriptFile = new File(System.getProperty("java.io.tmpdir"), spec.getCommand());
- Writer w = null;
+ BufferedWriter bw = null;
try {
- w = new FileWriter(tempScriptFile);
- w.write(spec.getScriptContent().toString());
- w.write('\n');
+ bw = new BufferedWriter(new FileWriter(tempScriptFile));
+ expand(props, spec.getScriptContent().toString(), bw, '@');
+ bw.write('\n');
} finally {
- w.close();
+ bw.close();
}
int rc = getShell().runCommandFile(tempScriptFile,
spec.getCommand(), spec.getArgs().toArray(new String[0]));
return check(rc) ? 0 : 1;
}
- private boolean check(int rc) {
+ private boolean check(int rc) throws IOException {
return
harness.expect(rc, spec.getRc(), "return code") &
harness.expect(outBucket.toString(), spec.getOutputContent(), "output content") &
- harness.expect(errBucket.toString(), spec.getErrorContent(), "err content");
+ harness.expect(errBucket.toString(), spec.getErrorContent(), "err content") &
+ checkFiles();
}
@Override
@@ -69,5 +76,56 @@
}
super.cleanup();
}
-
+
+ /**
+ * Expand a '@...@' sequences in a template, writing the result to an
+ * Writer. A sequence '@@' turns into a single '@'. A sequence
+ * '@name@' expands to the value of the named property if it is defined in
+ * the property set, or the sequence '@name@' if it does not. A CR, NL or
+ * EOF in an '@...@' sequence is an error.
+ *
+ * @param props the properties to be expanded
+ * @param template is the template string
+ * @param w the sink for the expanded template
+ * @param marker the sequence marker character(defaults to '@')
+ * @throws IOException
+ * @throws TestSpecificationException
+ */
+ private void expand(Properties props, String template, BufferedWriter w, char marker)
+ throws IOException, TestSpecificationException {
+ int ch;
+ Reader r = new StringReader(template);
+ while ((ch = r.read()) != -1) {
+ if (ch == marker) {
+ StringBuffer sb = new StringBuffer(20);
+ while ((ch = r.read()) != marker) {
+ switch (ch) {
+ case -1:
+ throw new TestSpecificationException("Encountered EOF in a " + marker +
+ "..." + marker + " sequence in script template");
+ case '\n':
+ throw new TestSpecificationException("Encountered newline in a " +
+ marker + "..." + marker + " sequence in script template");
+ default:
+ sb.append((char) ch);
+ }
+ }
+ if (sb.length() == 0) {
+ w.write(marker);
+ } else {
+ String name = sb.toString();
+ String value = props.getProperty(name);
+ if (value == null) {
+ w.write(marker);
+ w.write(sb.toString().toCharArray());
+ w.write(marker);
+ } else {
+ w.write(value.toCharArray());
+ }
+ }
+ } else {
+ w.write((char) ch);
+ }
+ }
+ }
}
Modified: trunk/shell/src/test/org/jnode/test/shell/harness/TestHarness.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/harness/TestHarness.java 2009-02-15 22:30:50 UTC (rev 5031)
+++ trunk/shell/src/test/org/jnode/test/shell/harness/TestHarness.java 2009-02-16 13:47:27 UTC (rev 5032)
@@ -279,4 +279,13 @@
public boolean isDebug() {
return debug;
}
+
+ public File tempFile(File file) {
+ return new File(System.getProperty("java.io.tmpdir"), file.toString());
+ }
+
+ public boolean fail(String msg) {
+ report("Incorrect test result in test " + asString(spec.getTitle()) + ": " + msg);
+ return false;
+ }
}
Modified: trunk/shell/src/test/org/jnode/test/shell/harness/TestRunnable.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/harness/TestRunnable.java 2009-02-15 22:30:50 UTC (rev 5031)
+++ trunk/shell/src/test/org/jnode/test/shell/harness/TestRunnable.java 2009-02-16 13:47:27 UTC (rev 5032)
@@ -20,6 +20,7 @@
package org.jnode.test.shell.harness;
+
/**
* This is the API implemented by the command test runners. We cannot
* use / extend Runnable because we need to propagate any exceptions
@@ -31,7 +32,7 @@
public int run() throws Exception;
- public void setup();
+ public void setup() throws Exception;
public void cleanup();
Added: trunk/shell/src/test/org/jnode/test/shell/harness/TestRunnerBase.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/harness/TestRunnerBase.java (rev 0)
+++ trunk/shell/src/test/org/jnode/test/shell/harness/TestRunnerBase.java 2009-02-16 13:47:27 UTC (rev 5032)
@@ -0,0 +1,196 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2009 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.test.shell.harness;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+import org.jnode.naming.InitialNaming;
+import org.jnode.plugin.PluginManager;
+import org.jnode.shell.CommandShell;
+import org.jnode.shell.ShellException;
+import org.jnode.test.shell.harness.TestSpecification.FileSpecification;
+
+/**
+ * This base class supplies functions for getting hold of "the shell" for
+ * testing commands, configuring required plugins and setting up the
+ * System streams for a command.
+ *
+ * @author cr...@jn...
+ */
+public abstract class TestRunnerBase implements TestRunnable {
+
+ private class TeeStream extends FilterOutputStream {
+ private OutputStream out2;
+
+ public TeeStream(OutputStream out, OutputStream out2) {
+ super(out);
+ this.out2 = out2;
+ }
+
+ @Override
+ public void close() throws IOException {
+ super.close();
+ out2.close();
+ }
+
+ @Override
+ public void flush() throws IOException {
+ super.flush();
+ out2.flush();
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+ super.write(b);
+ out2.write(b);
+ }
+ }
+
+ protected ByteArrayOutputStream outBucket;
+ protected ByteArrayOutputStream errBucket;
+
+ protected final TestSpecification spec;
+ protected final TestHarness harness;
+
+ protected final boolean usingEmu;
+
+ public TestRunnerBase(TestSpecification spec, TestHarness harness) {
+ super();
+ this.spec = spec;
+ this.harness = harness;
+ this.usingEmu = TestEmu.initEmu(harness.getRoot());
+ }
+
+ public CommandShell getShell() throws ShellException {
+ CommandShell shell = TestEmu.getShell();
+ if (shell == null) {
+ shell = new TestCommandShell(System.in, System.out, System.err);
+ shell.configureShell();
+ }
+ return shell;
+ }
+
+ @Override
+ public void cleanup() {
+ if (!harness.isDebug()) {
+ for (FileSpecification fs : spec.getFiles()) {
+ if (fs.isInput()) {
+ File tempFile = harness.tempFile(fs.getFile());
+ tempFile.delete();
+ }
+ }
+ }
+ }
+
+ @Override
+ public void setup() throws IOException {
+ ensurePluginsLoaded(spec.getTestSet());
+ for (PluginSpecification plugin : spec.getPlugins()) {
+ ensurePluginLoaded(plugin);
+ }
+ System.setIn(new ByteArrayInputStream(spec.getInputContent().toString().getBytes()));
+ outBucket = new ByteArrayOutputStream();
+ errBucket = new ByteArrayOutputStream();
+ if (harness.isDebug()) {
+ System.setOut(new PrintStream(new TeeStream(outBucket, System.out)));
+ System.setErr(new PrintStream(new TeeStream(errBucket, System.err)));
+ } else {
+ System.setOut(new PrintStream(outBucket));
+ System.setErr(new PrintStream(errBucket));
+ }
+ for (FileSpecification fs : spec.getFiles()) {
+ File tempFile = harness.tempFile(fs.getFile());
+ if (fs.isInput()) {
+ OutputStream os = new FileOutputStream(tempFile);
+ try {
+ byte[] bytes = fs.getFileContent().getBytes();
+ os.write(bytes);
+ } finally {
+ os.close();
+ }
+ } else {
+ tempFile.delete();
+ }
+ }
+ }
+
+ protected boolean checkFiles() throws IOException {
+ boolean ok = true;
+ for (FileSpecification fs : spec.getFiles()) {
+ File tempFile = harness.tempFile(fs.getFile());
+ if (!fs.isInput()) {
+ if (!tempFile.exists()) {
+ harness.fail("file not created: '" + tempFile + "'");
+ ok = false;
+ } else {
+ int fileLength = (int) tempFile.length();
+ byte[] bytes = new byte[fileLength];
+ InputStream is = new FileInputStream(tempFile);
+ try {
+ is.read(bytes);
+ } finally {
+ is.close();
+ }
+ String content = new String(bytes);
+ ok = ok & harness.expect(content, fs.getFileContent(), "file content (" + tempFile + ")");
+ }
+ }
+ }
+ return ok;
+ }
+
+ private void ensurePluginsLoaded(TestSetSpecification testSet) {
+ if (testSet == null) {
+ return;
+ }
+ ensurePluginsLoaded(testSet.getParentSet());
+ for (PluginSpecification plugin : spec.getTestSet().getPlugins()) {
+ ensurePluginLoaded(plugin);
+ }
+ }
+
+ protected void ensurePluginLoaded(PluginSpecification plugin) {
+ if (usingEmu) {
+ TestEmu.loadPseudoPlugin(plugin.getPluginId(), plugin.getClassName());
+ } else {
+ // TODO - I'm not sure about this. A simpler alternative is to assume
+ // that all required plugins have already been loaded by JNode.
+ String ver = (plugin.getPluginVersion().length() == 0) ?
+ System.getProperty("os.version") : plugin.getPluginVersion();
+ try {
+ PluginManager mgr = InitialNaming.lookup(PluginManager.NAME);
+ mgr.getRegistry().loadPlugin(mgr.getLoaderManager(), plugin.getPluginId(), ver);
+ } catch (Exception ex) {
+ throw new RuntimeException(
+ "Cannot load plugin '" + plugin.getPluginId() + "/" + ver + "'");
+ }
+ }
+ }
+}
Modified: trunk/shell/src/test/org/jnode/test/shell/harness/TestSpecification.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/harness/TestSpecification.java 2009-02-15 22:30:50 UTC (rev 5031)
+++ trunk/shell/src/test/org/jnode/test/shell/harness/TestSpecification.java 2009-02-16 13:47:27 UTC (rev 5032)
@@ -22,9 +22,7 @@
import java.io.File;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
/**
* This represents a command test specification for a command or script.
@@ -39,6 +37,31 @@
AS_ALIAS
}
+ public static class FileSpecification {
+ private final File file;
+ private final boolean input;
+ private final String fileContent;
+
+ public FileSpecification(File file, boolean input,
+ String fileContent) {
+ this.file = file;
+ this.input = input;
+ this.fileContent = fileContent;
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public boolean isInput() {
+ return input;
+ }
+
+ public String getFileContent() {
+ return fileContent;
+ }
+ }
+
private final RunMode runMode;
private final String command;
private final List<String> args = new ArrayList<String>();
@@ -49,19 +72,19 @@
private final String title;
private final List<PluginSpecification> plugins = new ArrayList<PluginSpecification>();
private final int rc;
- private final Map<File, String> fileMap = new HashMap<File, String>();
+ private final List<FileSpecification> files = new ArrayList<FileSpecification>();
private TestSetSpecification testSet;
- public TestSpecification(RunMode runMode, String command, String scriptContent2,
- String inputContent2, String outputContent2, String errorContent2,
+ public TestSpecification(RunMode runMode, String command, String scriptContent,
+ String inputContent, String outputContent, String errorContent,
String title, int rc) {
super();
this.runMode = runMode;
this.command = command;
- this.scriptContent = scriptContent2;
- this.inputContent = inputContent2;
- this.outputContent = outputContent2;
- this.errorContent = errorContent2;
+ this.scriptContent = scriptContent;
+ this.inputContent = inputContent;
+ this.outputContent = outputContent;
+ this.errorContent = errorContent;
this.title = title;
this.rc = rc;
}
@@ -86,12 +109,12 @@
plugins.add(plugin);
}
- public void addFile(File file, String content) {
- fileMap.put(file, content);
+ public void addFile(FileSpecification file) {
+ files.add(file);
}
- public Map<File, String> getFileMap() {
- return fileMap;
+ public List<FileSpecification> getFiles() {
+ return files;
}
public RunMode getRunMode() {
Modified: trunk/shell/src/test/org/jnode/test/shell/harness/TestSpecificationParser.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/harness/TestSpecificationParser.java 2009-02-15 22:30:50 UTC (rev 5031)
+++ trunk/shell/src/test/org/jnode/test/shell/harness/TestSpecificationParser.java 2009-02-16 13:47:27 UTC (rev 5032)
@@ -113,13 +113,19 @@
private void parseFile(IXMLElement elem, TestSpecification res)
throws TestSpecificationException {
String fileName = extractAttribute(elem, "name");
- String content = extractElementValue(elem, "content", "");
- res.addFile(new File(fileName), content);
+ boolean isInput = extractAttribute(elem, "input", "false").equals("true");
+ String content = extractElementValue(elem, null, "");
+ File file = new File(fileName);
+ if (file.isAbsolute()) {
+ throw new TestSpecificationException(
+ "A '" + elem.getName() + "' element must have a relative 'name''");
+ }
+ res.addFile(new TestSpecification.FileSpecification(file, isInput, content));
}
@SuppressWarnings("unused")
private String extractElementValue(IXMLElement parent, String name) throws TestSpecificationException {
- IXMLElement elem = parent.getFirstChildNamed(name);
+ IXMLElement elem = name == null ? parent : parent.getFirstChildNamed(name);
if (elem == null) {
throw new TestSpecificationException(
"Element '" + name + "' not found in '" + parent.getName() + "'");
@@ -130,7 +136,7 @@
}
private String extractElementValue(IXMLElement parent, String name, String dflt) {
- IXMLElement elem = parent.getFirstChildNamed(name);
+ IXMLElement elem = name == null ? parent : parent.getFirstChildNamed(name);
return elem == null ? dflt : elem.getContent();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|