Skip to content

Commit

Permalink
tests: add spoon 10.4.0 as test resource (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
algomaster99 authored Aug 28, 2023
1 parent 9bea51b commit d2dd51a
Show file tree
Hide file tree
Showing 5 changed files with 1,294 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ JRELEASER_VERSION

### Deployment files ###
semver-*

### Spoon workload files ###
spooned*
33 changes: 33 additions & 0 deletions watchdog-agent/src/test/java/AgentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,39 @@ void sorald_0_8_5_shouldExitWith_1() throws IOException, InterruptedException {
assertThat(exitCode).isEqualTo(0);
}

// level 1: fat jar
@Test
void spoon_10_4_0() throws IOException, InterruptedException {
// contract: spoon 10.4.0 CLI should be self-contained in a fat jar and its execution should not load any
// classes outside SBOM
Path project = Paths.get("src/test/resources/spoon-10.4.0");

Path sbom = project.resolve("bom.json");
Path spoonExecutable = project.resolve("spoon-core-10.4.0-jar-with-dependencies.jar");
Path workload = project.resolve("Main.java").toAbsolutePath();

String agentArgs = "sbom=" + sbom;
String[] cmd = {
"java",
"-javaagent:" + getAgentPath(agentArgs),
"-jar",
spoonExecutable.toString(),
"--input",
workload.toString(),
"--disable-comments", // remove comments and prints in spooned/Main.java
"--compile" // prints bytecode in spooned-classes
};
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.redirectInput(ProcessBuilder.Redirect.INHERIT);
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
pb.redirectError(ProcessBuilder.Redirect.INHERIT);

Process p = pb.start();
int exitCode = p.waitFor();

assertThat(exitCode).isEqualTo(0);
}

private static void deleteContentsOfFile(String file) throws InterruptedException, IOException {
String[] deleteFile = {"rm", "-f", file};
Runtime.getRuntime().exec(deleteFile).waitFor();
Expand Down
8 changes: 8 additions & 0 deletions watchdog-agent/src/test/resources/spoon-10.4.0/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class Main {
// This comment should be removed by the processor
public static void main(String[] args) {
// This also
System.out.println("Hello World!");
}
// This also
}
Loading

0 comments on commit d2dd51a

Please sign in to comment.