[Japi-cvs] SF.net SVN: japi:[772] libs/argparser/trunk/src/tst/test/net/sf/japi/io/ args/ArgParserT
Status: Beta
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2008-12-30 03:12:22
|
Revision: 772
http://japi.svn.sourceforge.net/japi/?rev=772&view=rev
Author: christianhujer
Date: 2008-12-30 03:12:18 +0000 (Tue, 30 Dec 2008)
Log Message:
-----------
Made test run from Ant and from IntelliJ IDEA by finding paths itself.
Modified Paths:
--------------
libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/ArgParserTest.java
Modified: libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/ArgParserTest.java
===================================================================
--- libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/ArgParserTest.java 2008-12-29 20:42:03 UTC (rev 771)
+++ libs/argparser/trunk/src/tst/test/net/sf/japi/io/args/ArgParserTest.java 2008-12-30 03:12:18 UTC (rev 772)
@@ -20,6 +20,7 @@
package test.net.sf.japi.io.args;
import java.io.File;
+import java.io.IOException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Set;
@@ -35,6 +36,7 @@
import net.sf.japi.io.args.UnknownOptionException;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
+import org.junit.BeforeClass;
import org.junit.Test;
/**
@@ -43,6 +45,30 @@
*/
public class ArgParserTest {
+ /** The path that needs to be used for the test to find its files. */
+ private static String pathPrefix;
+
+ /** Finds the {@link #pathPrefix}.
+ * @throws IOException if a canonical file resolution required for determining {@link #pathPrefix} failed.
+ */
+ @BeforeClass
+ public static void initPathPrefix() throws IOException {
+ final String testPathname = "src/tst/test/net/sf/japi/io/args/ArgParserTest_OptionsFileSingleLine";
+ final File f = new File(testPathname);
+ if (f.exists()) {
+ // We already are at a location where the test files can be found.
+ // That's the case if run from Ant.
+ // No pathPrefix needed.
+ pathPrefix = "";
+ } else {
+ // The test pathname was not found.
+ // That's the case if run from IntelliJ IDEA with japi.ipr.
+ // That means the cwd is japi and paths need to be prefixed with the module directory path.
+ pathPrefix = "libs/argparser/trunk/";
+ assert new File(pathPrefix, testPathname).exists();
+ }
+ }
+
/**
* Tests that {@link ArgParser#getOptionMethods(Command)} works.
* @throws Exception (unexpected)
@@ -270,7 +296,7 @@
@Test
public void testOptionsFromFileSingleLine() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException, ArgumentFileNotFoundException {
final MockCommand command = new MockCommand();
- ArgParser.parseAndRun(command, "@src/tst/test/net/sf/japi/io/args/ArgParserTest_OptionsFileSingleLine");
+ ArgParser.parseAndRun(command, "@" + pathPrefix + "src/tst/test/net/sf/japi/io/args/ArgParserTest_OptionsFileSingleLine");
final List<String> args = command.getArgs();
Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput());
Assert.assertTrue("Run must be called even with zero arguments.", command.isRunCalled());
@@ -291,7 +317,7 @@
@Test
public void testOptionsFromFileMultiple() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException, ArgumentFileNotFoundException {
final MockCommand command = new MockCommand();
- ArgParser.parseAndRun(command, "@src/tst/test/net/sf/japi/io/args/ArgParserTest_MultipleOptionsFileMaster");
+ ArgParser.parseAndRun(command, "@" + pathPrefix + "src/tst/test/net/sf/japi/io/args/ArgParserTest_MultipleOptionsFileMaster");
final List<String> args = command.getArgs();
Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput());
Assert.assertTrue("Run must be called even with zero arguments.", command.isRunCalled());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|