-
Notifications
You must be signed in to change notification settings - Fork 127
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
Test API for calling Mojos
#1417
Comments
@volodya-lombrozo I totally agree, but what would such an API look like? |
It's just a sketch. But the Idea is to create an Object-Oriented API for each compilation step, then our tests will look like: @Test
void testExample(){
new Assemble(
new CorrectProgram(),
"trackOptimizationSteps=true"
).execute();
assertSomething();
} instead of: @Test
void testExample(){
final Path src = temp.resolve("src");
new Home(src).save(
String.join(
"\n",
"+alias stdout org.eolang.io.stdout",
"",
"[x] > main\n (stdout \"Hello!\" x).print\n"
),
Paths.get("main.eo")
);
final Path target = temp.resolve("target");
new Moja<>(RegisterMojo.class)
.with("foreign", temp.resolve("eo-foreign.json").toFile())
.with("foreignFormat", "json")
.with("sourcesDir", src.toFile())
.with("includeSources", new SetOf<>("**.eo"))
.execute();
new Moja<>(AssembleMojo.class)
.with("outputDir", temp.resolve("out").toFile())
.with("targetDir", target.toFile())
.with("foreign", temp.resolve("eo-foreign.json").toFile())
.with("foreignFormat", "json")
.with("placed", temp.resolve("list").toFile())
.with("cache", temp.resolve("cache/parsed"))
.with("skipZeroVersions", true)
.with("central", Central.EMPTY)
.with("ignoreTransitive", true)
.with(
"objectionary",
(Objectionary) input -> new InputOf(
"[] > sprintf\n"
)
)
.execute();
assertSomething();
} In constructors we will have some sort of flexibility in adjusting different parameters for different cases. Also pay attention, that each step will use previous steps internally. It's important, because when I wanna test |
@volodya-lombrozo We also need flexibility of choosing what mojos are executed. Ideally we want some kind of DSL which allows to specify steps (mojos) and their configurations. |
I believe some sort of predefined test configurations of steps might help here. It can use naming conventions for paths and file names to supply input and check output |
We have OOP way to specify steps and their configurations, DSL - it's too much, as for me :) new Assemble(
new Register("foreign=eo-foreign.json"),
"foreignFormat=json",
"cache=/tmp/test"
).execute(); |
It's a dark magic which is hard to read and configure. But it's only my personal opinion. I can be wrong. |
@volodya-lombrozo you still have to specify all properties. Also it's not clear how to convert string |
@mximp Not really, In most cases we will use simple constructors without params (default properties will be set in each class inside constructors as |
@mximp @volodya-lombrozo how about rewriting this test:
as such: @Test
void testExample(@TempDir temp){
new FakeMaven()
.home(temp.resolve("src"))
.save(
String.join(
"\n",
"+alias stdout org.eolang.io.stdout",
"",
"[x] > main\n (stdout \"Hello!\" x).print\n"
),
"main.eo"
)
.with("foreign", "./eo-foreign.json")
.with("foreignFormat", "json")
.with("sourcesDir", ".")
.with("includeSources", "**.eo")
.with("outputDir", "./out")
.with("targetDir", ".")
.with("placed", "./list")
.with("cache", "./cache/parsed")
.with("skipZeroVersions", true)
.with("central", Central.EMPTY)
.with("ignoreTransitive", true)
.with(
"objectionary",
(Objectionary) input -> new InputOf(
"[] > sprintf\n"
)
)
.execute(RegisterMojo.class)
.execute(AssembleMojo.class)
.assertFileExists("./target/eo-foreign.json");
} |
@yegor256 as for me, that code doesn't solve the original problem:
|
@volodya-lombrozo well... 2.2) we can have defaults, 2.3) this is fake-test class, it's OK to make it large, I believe, 3) let's do this instead:
|
@yegor256 I'm still afraid of 2.2. Why should we consider the test classes as code that may violate all the principles? It's the same code as a production code, and, as for me, it's even more important code. But I can be wrong, of course, and probably I'm just exaggerating the problem. |
@volodya-lombrozo you are not wrong, but I don't see a mess. In most cases our code will look like this: @Test
void testExample(@TempDir temp){
assertThat(
new FakeMaven()
.home(temp.resolve("src"))
.save(
String.join(
"\n",
"+alias stdout org.eolang.io.stdout",
"",
"[x] > main\n (stdout \"Hello!\" x).print\n"
),
"main.eo"
)
.with("cache", "./cache/parsed")
.execute(RegisterMojo.class)
.execute(AssembleMojo.class),
hasKey("./target/eo-foreign.json")
);
} I don't see a mess. Keep in mind, most Even the @Test
void testExample(@TempDir temp){
assertThat(
new FakeMaven()
.home(temp.resolve("src"))
.saveDefault()
.with("cache", "./cache/parsed")
.execute(RegisterMojo.class)
.execute(AssembleMojo.class),
hasKey("./target/eo-foreign.json")
);
} |
@yegor256 let's try. But I have one more question - can we create an objects abstractions for eo programs? In other words instead of that: @Test
void testExample(@TempDir temp){
assertThat(
new FakeMaven()
.home(temp.resolve("src"))
.save(
String.join(
"\n",
"+alias stdout org.eolang.io.stdout",
"",
"[x] > main\n (stdout \"Hello!\" x).print\n"
),
"main.eo"
)
.with("cache", "./cache/parsed")
.execute(RegisterMojo.class)
.execute(AssembleMojo.class),
hasKey("./target/eo-foreign.json")
);
} can we use something like: @Test
void testExample(@TempDir temp){
assertThat(
new FakeMaven()
.home(temp.resolve("src"))
.save(
new SimpleEoProgram()
)
.with("cache", "./cache/parsed")
.execute(RegisterMojo.class)
.execute(AssembleMojo.class),
hasKey("./target/eo-foreign.json")
);
} It:
|
@volodya-lombrozo in general, I would suggest to use a simple rule: use scalar values first and THEN, when you see the necessity of an object, make an object. Java is not "object friendly" language. Each class, unfortunately, adds complexity to the code. Try to keep code simple first and OOP second :) So, I'm not against this |
feat(objectionary#1417): add FakeMaven class feat(objectionary#1417): simplify API code feat(objectionary#1417): add package-info.java
@volodya-lombrozo the puzzle #1479 is still not solved. |
@volodya-lombrozo 2 puzzles #1488, #1489 are still not solved; solved: #1479. |
@volodya-lombrozo the puzzle #1488 is still not solved; solved: #1479, #1489. |
@volodya-lombrozo all 3 puzzles are solved here: #1479, #1488, #1489. |
We are using the next test code almost in all tests that are somehow connected with
Mojos
:or
In some test cases we even have already started to extract methods with that code, see
discover()
method above. When I write a new test, I quite often just copy that mess, add one morenew Moja
and continue (in most cases I even don't care about params for mojos). The problem with that code - is obvious duplication and verbosity, moreover it's hard to find the main idea of the test in all this mess. I think we have to invent some sort of Test API in order to decrease code duplication and simplify test code.The text was updated successfully, but these errors were encountered: