Skip to content

Commit

Permalink
feat(objectionary#37): rewrite bytecode after optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Sep 7, 2023
1 parent 6219418 commit 14e1338
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/eolang/jeo/Optimization.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void recompile(final IR ir) {
subpath[subpath.length - 1] = String.format("%s.class", subpath[subpath.length - 1]);
final Path path = Paths.get(this.classes.toString(), subpath);
Files.createDirectories(path.getParent());
Files.write(path, bytecode, StandardOpenOption.CREATE_NEW);
Files.write(path, bytecode, StandardOpenOption.CREATE);
} catch (final IOException exception) {
throw new IllegalStateException(String.format("Can't recompile '%s'", name), exception);
}
Expand Down
16 changes: 10 additions & 6 deletions src/test/java/org/eolang/jeo/OptimizationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@
package org.eolang.jeo;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import org.cactoos.bytes.BytesOf;
import org.cactoos.bytes.UncheckedBytes;
import org.cactoos.io.ResourceOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.io.FileMatchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

Expand All @@ -53,9 +56,14 @@ class OptimizationTest {

@Test
void appliesAllBoosts(@TempDir final Path classes) throws IOException {
final Path directory = Paths.get("org")
.resolve("eolang")
.resolve("jeo");
final String name = "MethodByte.class";
final Path clazz = classes.resolve(directory).resolve(name);
Files.createDirectories(clazz.getParent());
Files.write(
classes.resolve(name),
clazz,
new UncheckedBytes(new BytesOf(new ResourceOf(name))).asBytes(),
StandardOpenOption.CREATE_NEW
);
Expand All @@ -68,11 +76,7 @@ void appliesAllBoosts(@TempDir final Path classes) throws IOException {
);
MatcherAssert.assertThat(
"Optimization should save final bytecode into appropriate directory",
classes.resolve("org")
.resolve("eolang")
.resolve("jeo")
.resolve("MethodByte.class")
.toFile(),
clazz.toFile(),
FileMatchers.anExistingFile()
);
}
Expand Down

0 comments on commit 14e1338

Please sign in to comment.