1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
/* SingleTestHarness.java -- Runs one test given on the command line
Copyright (C) 2005 Mark J. Wielaard
This file is part of Mauve.
Mauve is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
Mauve 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with Mauve; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
package gnu.testlet;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
public class SingleTestHarness extends TestHarness
{
private int count;
private String className;
private String last_check;
public SingleTestHarness(Testlet t)
{
className = t.getClass().getName();
}
public void check(boolean result)
{
String message = (result ? "PASS" : "FAIL") + ": " + className
+ ((last_check == null) ? "" : (": " + last_check))
+ " (number " + count++ + ")";
System.out.println(message);
}
public Reader getResourceReader(String name) throws ResourceNotFoundException
{
return new BufferedReader(new InputStreamReader(getResourceStream(name)));
}
public InputStream getResourceStream(String name)
throws ResourceNotFoundException
{
// The following code assumes File.separator is a single character.
if (File.separator.length() > 1)
throw new Error("File.separator length is greater than 1");
String realName = name.replace('#', File.separator.charAt(0));
try
{
return new FileInputStream(getSourceDirectory() + File.separator
+ realName);
}
catch (FileNotFoundException ex)
{
throw new ResourceNotFoundException(ex.getLocalizedMessage() + ": "
+ getSourceDirectory()
+ File.separator + realName);
}
}
public File getResourceFile(String name) throws ResourceNotFoundException
{
// The following code assumes File.separator is a single character.
if (File.separator.length() > 1)
throw new Error("File.separator length is greater than 1");
String realName = name.replace('#', File.separator.charAt(0));
File f = new File(getSourceDirectory() + File.separator + realName);
if (!f.exists())
{
throw new ResourceNotFoundException("cannot find mauve resource file"
+ ": " + getSourceDirectory()
+ File.separator + realName);
}
return f;
}
public void checkPoint (String name)
{
last_check = name;
count = 0;
}
public void verbose (String message)
{
System.out.println(message);
}
public void debug (String message)
{
debug(message, true);
}
public void debug (String message, boolean newline)
{
if (newline)
System.out.println(message);
else
System.out.print(message);
}
public void debug (Throwable ex)
{
ex.printStackTrace(System.out);
}
public void debug (Object[] o, String desc)
{
debug("Dumping Object Array: " + desc);
if (o == null)
{
debug("null");
return;
}
for (int i = 0; i < o.length; i++) {
if (o[i] instanceof Object[])
debug((Object[]) o[i], desc + " element " + i);
else
debug(" Element " + i + ": " + o[i]);
}
}
public static void main(String[] args) throws Exception
{
String name = args[0];
Class k = Class.forName(name);
Testlet t = (Testlet) k.newInstance();
TestHarness h = new SingleTestHarness(t);
t.test(h);
}
}
|