Skip to content

Commit

Permalink
Merge pull request #105 from sharwell/fix-103
Browse files Browse the repository at this point in the history
Unique test folders
  • Loading branch information
parrt committed Feb 20, 2015
2 parents 16c85ad + e0def14 commit ce9f65b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ There are currently about 600 StringTemplate source downloads a month.
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<systemProperties>
<java.io.tmpdir>${project.build.directory}/test-output/</java.io.tmpdir>
</systemProperties>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/src</additionalClasspathElement>
</additionalClasspathElements>
Expand Down
18 changes: 11 additions & 7 deletions test/org/stringtemplate/v4/test/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT

public abstract class BaseTest {
public static final String pathSep = System.getProperty("path.separator");
public static final String tmpdir = System.getProperty("java.io.tmpdir");
public static final boolean interactive = Boolean.parseBoolean(System.getProperty("test.interactive"));
public static final String newline = Misc.newline;

public String tmpdir = null;

/**
* When runnning from Maven, the junit tests are run via the surefire plugin. It sets the
* classpath for the test environment into the following property. We need to pick this up
Expand Down Expand Up @@ -105,6 +106,10 @@ public String toString() {
public void setUp() {
STGroup.defaultGroup = new STGroup();
Compiler.subtemplateCount = 0;

String baseTestDirectory = System.getProperty("java.io.tmpdir");
String testDirectory = getClass().getSimpleName() + "-" + System.currentTimeMillis();
tmpdir = new File(baseTestDirectory, testDirectory).getAbsolutePath();
}

/**
Expand Down Expand Up @@ -340,12 +345,11 @@ public boolean equals(Object o) {
}
}

public static String getRandomDir() {
String randomDir = tmpdir+"dir"+String.valueOf((int)(Math.random()*100000));
File f = new File(randomDir);
f.mkdirs();
return randomDir;
}
public String getRandomDir() {
File randomDir = new File(tmpdir, "dir" + String.valueOf((int)(Math.random() * 100000)));
randomDir.mkdirs();
return randomDir.getAbsolutePath();
}

/**
* Removes the specified file or directory, and all subdirectories.
Expand Down
3 changes: 0 additions & 3 deletions test/org/stringtemplate/v4/test/TestCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
import static org.junit.Assert.assertEquals;

public class TestCompiler extends BaseTest {
@Before
@Override
public void setUp() { org.stringtemplate.v4.compiler.Compiler.subtemplateCount = 0; }

@Test public void testAttr() throws Exception {
String template = "hi <name>";
Expand Down
1 change: 1 addition & 0 deletions test/org/stringtemplate/v4/test/TestRenderers.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class TestRenderers extends BaseTest {
@Before
@Override
public void setUp() {
super.setUp();
origLocale = Locale.getDefault();
Locale.setDefault(Locale.US);
}
Expand Down

0 comments on commit ce9f65b

Please sign in to comment.