-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests to verify if resources exist in classpath (#76)
Build tasks and tests to verify if resources exist in classpath * Added minimal Java main to debug Reporter (#75) * Added failing test due to missing .version file (#75) * Added generateVersion task on Gradle Build (#75) * Added test to check if hashes match with git output (#75)
- Loading branch information
1 parent
dda52e5
commit 8c822ac
Showing
2 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import gov.nasa.jpf.Config; | ||
import gov.nasa.jpf.JPF; | ||
import gov.nasa.jpf.util.test.TestJPF; | ||
|
||
/** | ||
* This is a plain JUnit test to check whether required resource files exist on | ||
* JPF classpath. | ||
* | ||
* @author Jeanderson Candido | ||
* | ||
*/ | ||
public class ReporterResourcesTest extends TestJPF { | ||
|
||
private JPF jpf; | ||
|
||
@Before | ||
public void setup() { | ||
String[] configArgs = { "+vm.class=.vm.MultiProcessVM", "+target.1=HelloWorld", "+target.2=HelloWorld" }; | ||
this.jpf = new JPF(new Config(configArgs)); | ||
} | ||
|
||
@Test | ||
public void checkResources() throws IOException { | ||
assertNotNull("build.properties should exist on classpath", jpf.getClass().getResourceAsStream("build.properties")); | ||
assertNotNull(".version should exist on classpath", jpf.getClass().getResourceAsStream(".version")); | ||
} | ||
|
||
@Test | ||
public void hashMustMatch() { | ||
InputStream stream = jpf.getClass().getResourceAsStream(".version"); | ||
assertEquals("Should have the same hash", fetchCurrentRevisionFromVCS().trim(), readContentFrom(stream).trim()); | ||
} | ||
|
||
private String fetchCurrentRevisionFromVCS() { | ||
String currentRevision = ""; | ||
try { | ||
Process process = Runtime.getRuntime().exec("git rev-parse HEAD"); | ||
process.waitFor(); | ||
InputStream output = process.getInputStream(); | ||
currentRevision = readContentFrom(output); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return currentRevision; | ||
} | ||
|
||
private String readContentFrom(InputStream stream) { | ||
BufferedReader buffer = new BufferedReader(new InputStreamReader(stream)); | ||
StringBuilder output = new StringBuilder(); | ||
try { | ||
while (buffer.ready()) { | ||
output.append(buffer.readLine().trim()).append("\n"); | ||
} | ||
} catch (IOException e) { | ||
fail("Should not have failed while reading the file"); | ||
} | ||
return output.toString(); | ||
} | ||
|
||
} |