Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Sep 1, 2023
2 parents fd7475b + 6aee495 commit a586fe0
Show file tree
Hide file tree
Showing 21 changed files with 136 additions and 228 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: teatimeguest/[email protected]
with:
update-all-packages: true
packages: scheme-basic geometry xcolor naive-ebnf microtype etoolbox
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: teatimeguest/[email protected]
with:
update-all-packages: true
packages: scheme-basic geometry xcolor naive-ebnf microtype etoolbox
- uses: actions/cache@v3
with:
path: ~/.m2/repository
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/mvn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ jobs:
CONVERT_PATH: /tmp/antlr4-to-bnf-converter
steps:
- uses: actions/checkout@v3
- uses: teatimeguest/[email protected]
with:
update-all-packages: true
packages: scheme-basic geometry xcolor naive-ebnf microtype etoolbox
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: teatimeguest/[email protected]
with:
update-all-packages: true
packages: scheme-basic geometry xcolor naive-ebnf microtype etoolbox
- uses: actions/setup-java@v3
with:
java-version: 11
Expand Down
5 changes: 5 additions & 0 deletions eo-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ SOFTWARE.
logging system. -->
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.yegor256</groupId>
<artifactId>jaxec</artifactId>
<!-- version from parent POM -->
</dependency>
<dependency>
<groupId>org.eolang</groupId>
<artifactId>jucs</artifactId>
Expand Down
42 changes: 11 additions & 31 deletions eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package org.eolang.maven;

import com.jcabi.log.Logger;
import com.jcabi.log.VerboseProcess;
import com.yegor256.Jaxec;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
Expand Down Expand Up @@ -106,10 +106,7 @@ public void exec() throws IOException {
)
)
).intValue();
Logger.info(
this,
String.format("Built in total %d cargo projects", total)
);
Logger.info(this, "Built in total %d cargo projects", total);
}

/**
Expand All @@ -134,43 +131,26 @@ private void build(final File project) throws IOException {
.resolve(project.getName())
.resolve("target").toFile();
if (cached.exists()) {
Logger.info(
this,
String.format(
"Copying %s to %s",
cached,
target
)
);
FileUtils.copyDirectory(
cached,
target
);
Logger.info(this, "Copying %s to %s", cached, target);
FileUtils.copyDirectory(cached, target);
}
Logger.info(this, "Building rust project..");
try (
VerboseProcess proc = new VerboseProcess(
new ProcessBuilder("cargo", "build")
.directory(project)
)
) {
proc.stdout();
} catch (final IllegalArgumentException exc) {
try {
new Jaxec("cargo", "build").withHome(project).execUnsafe();
} catch (final IOException ex) {
throw new BuildFailureException(
String.format(
"Failed to build cargo project with dest = %s",
project
),
exc
ex
);
}
Logger.info(
this,
String.format(
"Cargo building succeeded, update cached %s with %s",
cached,
target
)
"Cargo building succeeded, update cached %s with %s",
cached,
target
);
FileUtils.copyDirectory(target, cached);
}
Expand Down
158 changes: 35 additions & 123 deletions eo-maven-plugin/src/test/java/org/eolang/maven/it/SnippetTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
*/
package org.eolang.maven.it;

import com.jcabi.log.Logger;
import com.jcabi.log.VerboseProcess;
import java.io.ByteArrayOutputStream;
import com.yegor256.Jaxec;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
Expand All @@ -38,14 +35,8 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.cactoos.Input;
import org.cactoos.Output;
import org.cactoos.io.InputOf;
import org.cactoos.io.OutputTo;
import org.cactoos.io.TeeInput;
import org.cactoos.iterable.Mapped;
import org.cactoos.list.Joined;
import org.cactoos.list.ListOf;
import org.cactoos.scalar.LengthOf;
import org.eolang.jucs.ClasspathSource;
import org.eolang.maven.AssembleMojo;
import org.eolang.maven.DemandMojo;
Expand Down Expand Up @@ -109,24 +100,15 @@ final class SnippetTestCase {
void runsAllSnippets(final String yml) throws Exception {
final Yaml yaml = new Yaml();
final Map<String, Object> map = yaml.load(yml);
final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
final int result = SnippetTestCase.run(
final String stdout = SnippetTestCase.run(
this.temp,
new InputOf(String.format("%s\n", map.get("eo"))),
(List<String>) map.get("args"),
new InputOf(map.get("in").toString()),
new OutputTo(stdout)
map.get("in").toString()
);
MatcherAssert.assertThat(
String.format("'%s' returned wrong exit code", yml),
result,
Matchers.equalTo(map.get("exit"))
);
final String actual = new String(stdout.toByteArray(), StandardCharsets.UTF_8);
Logger.debug(this, "Stdout: \"%s\"", actual);
MatcherAssert.assertThat(
String.format("'%s' printed something wrong", yml),
actual,
stdout,
Matchers.allOf(
new Mapped<>(
ptn -> Matchers.matchesPattern(
Expand Down Expand Up @@ -162,18 +144,16 @@ static String classpath() {
* @param code EO sources
* @param args Command line arguments
* @param stdin The input
* @param stdout Where to put stdout
* @return All Java code
* @return Stdout
* @throws Exception If fails
* @checkstyle ParameterNumberCheck (5 lines)
*/
@SuppressWarnings({"unchecked", "PMD.ExcessiveMethodLength"})
private static int run(
private static String run(
final Path tmp,
final Input code,
final List<String> args,
final Input stdin,
final Output stdout
final String stdin
) throws Exception {
final Path src = tmp.resolve("src");
final CommitHash hash = new ChRemote("master");
Expand All @@ -189,119 +169,51 @@ private static int run(
maven.execute(TranspileMojo.class);
final Path classes = maven.targetPath().resolve("classes");
SnippetTestCase.compileJava(maven.generatedPath(), classes);
SnippetTestCase.runJava(args, stdin, stdout, classes);
return 0;
return SnippetTestCase.runJava(args, stdin, classes);
}

/**
* Compile Java sources.
* @param generated Where to find Java sources
* @param classes Where to put compiled classes
* @throws Exception If fails
*/
private static void compileJava(final Path generated, final Path classes) throws Exception {
SnippetTestCase.exec(
String.format(
"%s -encoding utf-8 %s -d %s -cp %s",
SnippetTestCase.jdkExecutable("javac"),
new Walk(generated).stream()
.map(Path::toAbsolutePath)
.map(Path::toString)
.collect(Collectors.joining(" ")),
classes,
SnippetTestCase.classpath()
),
generated
);
private static void compileJava(final Path generated, final Path classes) {
new Jaxec(
SnippetTestCase.jdkExecutable("javac"),
"-encoding", "utf-8",
new Walk(generated).stream()
.map(Path::toAbsolutePath)
.map(Path::toString)
.collect(Collectors.joining(" ")),
"-d", classes.toString(),
"-cp", SnippetTestCase.classpath()
).withHome(generated).exec();
}

/**
* Run Java.
* @param args Command line arguments
* @param stdin The input
* @param stdout Where to put stdout
* @param classes Where to find compiled classes
* @throws Exception If fails
* @return The stdout
* @checkstyle ParameterNumberCheck (5 lines)
*/
private static void runJava(
final List<String> args,
final Input stdin,
final Output stdout,
final Path classes
) throws Exception {
SnippetTestCase.exec(
String.join(
" ",
new Joined<String>(
new ListOf<>(
SnippetTestCase.jdkExecutable("java"),
"-Dfile.encoding=UTF-8",
"-Dsun.stdout.encoding=UTF-8",
"-Dsun.stderr.encoding=UTF-8",
"-cp",
SnippetTestCase.classpath(),
"org.eolang.Main"
),
args
)
),
classes, stdin, stdout
);
}

/**
* Run some command and print out the output.
*
* @param cmd The command
* @param dir The home dir
* @throws Exception If fails
*/
private static void exec(final String cmd, final Path dir) throws Exception {
SnippetTestCase.exec(
cmd,
dir,
new InputOf(""),
new OutputTo(new ByteArrayOutputStream())
);
}

/**
* Run some command and print out the output.
*
* @param cmd The command
* @param dir The home dir
* @param stdin Stdin
* @param stdout Stdout
* @throws Exception If fails
* @checkstyle ParameterNumberCheck (5 lines)
*/
private static void exec(
final String cmd,
final Path dir,
final Input stdin,
final Output stdout
) throws Exception {
Logger.debug(SnippetTestCase.class, "+%s", cmd);
final Process proc = new ProcessBuilder()
.command(cmd.split(" "))
.directory(dir.toFile())
.redirectErrorStream(true)
.start();
new LengthOf(
new TeeInput(
stdin,
new OutputTo(proc.getOutputStream())
private static String runJava(final List<String> args, final String stdin,
final Path classes) {
return new Jaxec()
.with(
SnippetTestCase.jdkExecutable("java"),
"-Dfile.encoding=UTF-8",
"-Dsun.stdout.encoding=UTF-8",
"-Dsun.stderr.encoding=UTF-8",
"-cp",
SnippetTestCase.classpath(),
"org.eolang.Main"
)
).value();
try (VerboseProcess vproc = new VerboseProcess(proc)) {
new LengthOf(
new TeeInput(
new InputOf(vproc.stdout()),
stdout
)
).value();
}
.with(args)
.withHome(classes)
.withStdin(stdin)
.exec();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
exit: 0
in: ""
out:
- ".*works!.*"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
exit: 0
in: ""
out:
- ".*true.*"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
exit: 0
in: ""
out:
- ".*greater.*"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
exit: 0
in: ""
out:
- ".*123.*"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
exit: 0
in: ""
out:
- ".*Hello, дорогой!.*"
Expand Down
5 changes: 5 additions & 0 deletions eo-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ SOFTWARE.
<artifactId>xsline</artifactId>
<!-- version from parent POM -->
</dependency>
<dependency>
<groupId>com.yegor256</groupId>
<artifactId>jaxec</artifactId>
<!-- version from parent POM -->
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
Expand Down
Loading

0 comments on commit a586fe0

Please sign in to comment.