Skip to content

Commit

Permalink
tests: add test to check determinism of runtime-index (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
algomaster99 authored Mar 5, 2024
1 parent 9eece8c commit 92174b9
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.github.algomaster99.terminator.index;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class RuntimeIndexerTest {

@Test
void runtimeIndexShouldBeDeterministic(@TempDir Path tempDir) throws IOException {
// arrange
Path indexFile = tempDir.resolve("r.json");
Path project = Path.of("src", "test", "resources", "runtime-index", "basic-math");

// act
String[] jdk_argsFirst = {"jdk", "-o", indexFile.toString()};
Index.main(jdk_argsFirst);
String[] runtime_argsFirst = {
"runtime", "-p", project.toString(), "-i", indexFile.toString(), "-mj", "basic-math", "--cleanup"
};
Index.main(runtime_argsFirst);
String contentFirst = Files.readString(indexFile);

String[] jdk_argsSecond = {"jdk", "-o", indexFile.toString()};
Index.main(jdk_argsSecond);
String[] runtime_argsSecond = {
"runtime", "-p", project.toString(), "-i", indexFile.toString(), "-mj", "basic-math", "--cleanup"
};
Index.main(runtime_argsSecond);
String contentSecond = Files.readString(indexFile);

// assert
assertThat(contentFirst).isEqualTo(contentSecond);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>basic-math</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package foo;

public class BasicMath {
public static int add(int x, int y) {
return x + y;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package foo;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class BasicMathTest {
@Test
void test_add() {
assertEquals(4, BasicMath.add(23,2));
}
}

0 comments on commit 92174b9

Please sign in to comment.