Skip to content

Commit 91ca2ae

Browse files
committed
Redesign EvaluateTest to use golden files
1 parent 84e28c9 commit 91ca2ae

File tree

118 files changed

+463
-415
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+463
-415
lines changed

src/cli/src/test/java/org/smoothbuild/cli/accept/EvaluateTest.java

Lines changed: 0 additions & 415 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.smoothbuild.cli.accept.evaluate;
2+
3+
import java.io.IOException;
4+
import java.nio.file.Path;
5+
import java.util.Map;
6+
import org.junit.jupiter.params.ParameterizedTest;
7+
import org.junit.jupiter.params.provider.ArgumentsSource;
8+
import org.smoothbuild.common.collect.Maybe;
9+
import org.smoothbuild.common.testing.GoldenFilesArgumentsProvider;
10+
import org.smoothbuild.common.testing.GoldenFilesTestCase;
11+
import org.smoothbuild.evaluator.testing.EvaluatorTestContext;
12+
import org.smoothbuild.virtualmachine.testing.func.nativ.StringIdentity;
13+
import org.smoothbuild.virtualmachine.testing.func.nativ.ThrowException;
14+
15+
public class EvaluateTest extends EvaluatorTestContext {
16+
private static final String TESTS_DIR = "src/test/java/org/smoothbuild/cli/accept/evaluate";
17+
18+
@ParameterizedTest
19+
@ArgumentsSource(ArgumentsProvider.class)
20+
void test_compile(GoldenFilesTestCase testCase) throws IOException {
21+
testCase.assertWithGoldenFiles(generateFiles(testCase));
22+
}
23+
24+
private Map<String, String> generateFiles(GoldenFilesTestCase testCase) throws IOException {
25+
var code = testCase.readFile("smooth");
26+
var importedCode = testCase.readFileMaybe("imported");
27+
var artifact = evaluate(code, importedCode);
28+
return Map.of("artifact", artifact);
29+
}
30+
31+
private String evaluate(String code, Maybe<String> importedModule) throws IOException {
32+
createUserModule(code, StringIdentity.class, ThrowException.class);
33+
evaluate("result");
34+
return artifact().toString();
35+
}
36+
37+
static class ArgumentsProvider extends GoldenFilesArgumentsProvider {
38+
public ArgumentsProvider() {
39+
super(Path.of(TESTS_DIR), "smooth");
40+
}
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BInt(
2+
hash = b00b1c1fa3eb808c7898052142c9f222df725d8e5f3801b69326c4bc3c2d2809
3+
type = Int
4+
value = 7
5+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
myFunc(Int int) = int;
2+
result = 7 > myFunc();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BInt(
2+
hash = b00b1c1fa3eb808c7898052142c9f222df725d8e5f3801b69326c4bc3c2d2809
3+
type = Int
4+
value = 7
5+
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
myFunc() = 7;
2+
result = myFunc();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BString(
2+
hash = a8290d3ebf36fd0cda7c9e3e5e4a81199d86c6ed3585c073502313f03bdf9986
3+
type = String
4+
value = "abc"
5+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
String returnAbc() = "abc";
2+
A invokeProducer<A>(()->A producer) = producer();
3+
result = invokeProducer(returnAbc);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BString(
2+
hash = a8290d3ebf36fd0cda7c9e3e5e4a81199d86c6ed3585c073502313f03bdf9986
3+
type = String
4+
value = "abc"
5+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
String returnAbc() = "abc";
2+
()->String createProducer() = returnAbc;
3+
result = createProducer()();

0 commit comments

Comments
 (0)