Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add spoon 10.4.0 as test resource #66

Merged
merged 6 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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