|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com |
| 3 | + * SPDX-License-Identifier: MIT |
| 4 | + */ |
| 5 | +package org.eolang.maven; |
| 6 | + |
| 7 | +import com.yegor256.MayBeSlow; |
| 8 | +import com.yegor256.Mktmp; |
| 9 | +import com.yegor256.MktmpResolver; |
| 10 | +import com.yegor256.WeAreOnline; |
| 11 | +import com.yegor256.farea.Farea; |
| 12 | +import java.nio.charset.StandardCharsets; |
| 13 | +import java.nio.file.Files; |
| 14 | +import java.nio.file.Path; |
| 15 | +import org.hamcrest.MatcherAssert; |
| 16 | +import org.hamcrest.Matchers; |
| 17 | +import org.junit.jupiter.api.Test; |
| 18 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 19 | + |
| 20 | +/** |
| 21 | + * Integration tests for {@link TranspileMojo}. |
| 22 | + * |
| 23 | + * @since 0.52 |
| 24 | + */ |
| 25 | +@SuppressWarnings({"JTCOP.RuleAllTestsHaveProductionClass", "JTCOP.RuleNotContainsTestWord"}) |
| 26 | +@ExtendWith({WeAreOnline.class, MktmpResolver.class, MayBeSlow.class, RandomProgramResolver.class}) |
| 27 | +final class TranspileMojoIT { |
| 28 | + @Test |
| 29 | + void transpilesWithPackage(@Mktmp final Path temp) throws Exception { |
| 30 | + new Farea(temp).together( |
| 31 | + f -> { |
| 32 | + f.clean(); |
| 33 | + f.files().file("src/main/eo/one/foo.eo").write( |
| 34 | + String.join( |
| 35 | + "\n", |
| 36 | + "+package one", |
| 37 | + "+unlint object-has-data", |
| 38 | + "", |
| 39 | + "# no comments.", |
| 40 | + "[] > foo", |
| 41 | + " QQ.io.stdout > @", |
| 42 | + " \"Hello, world!\\n\"" |
| 43 | + ).getBytes(StandardCharsets.UTF_8) |
| 44 | + ); |
| 45 | + new AppendedPlugin(f).value() |
| 46 | + .goals("register", "parse", "shake", "transpile"); |
| 47 | + f.exec("process-sources"); |
| 48 | + final String java = "EOfoo.java"; |
| 49 | + final String pname = "EOone"; |
| 50 | + final String pinfo = "package-info.java"; |
| 51 | + MatcherAssert.assertThat( |
| 52 | + String.format( |
| 53 | + "The %s file must be generated, but it didn't", |
| 54 | + java |
| 55 | + ), |
| 56 | + temp.resolve( |
| 57 | + String.format( |
| 58 | + "target/generated-sources/%s/%s", |
| 59 | + pname, |
| 60 | + java |
| 61 | + ) |
| 62 | + ).toFile().exists(), |
| 63 | + Matchers.is(true) |
| 64 | + ); |
| 65 | + MatcherAssert.assertThat( |
| 66 | + String.format( |
| 67 | + "The %s file must contain the %s package name", |
| 68 | + pinfo, |
| 69 | + pname |
| 70 | + ), |
| 71 | + Files.readString( |
| 72 | + temp.resolve( |
| 73 | + String.format( |
| 74 | + "target/generated-sources/%s/%s", |
| 75 | + pname, |
| 76 | + pinfo |
| 77 | + ) |
| 78 | + ), |
| 79 | + StandardCharsets.UTF_8 |
| 80 | + ), |
| 81 | + Matchers.containsString(String.format("package %s;", pname)) |
| 82 | + ); |
| 83 | + } |
| 84 | + ); |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + void transpilesSimpleApp(@Mktmp final Path temp, @RandomProgram final String prog) |
| 89 | + throws Exception { |
| 90 | + new Farea(temp).together( |
| 91 | + f -> { |
| 92 | + f.clean(); |
| 93 | + f.files().file("src/main/eo/foo.eo").write(prog.getBytes()); |
| 94 | + new AppendedPlugin(f).value() |
| 95 | + .goals("register", "parse", "shake", "transpile"); |
| 96 | + f.exec("process-sources"); |
| 97 | + final String java = "EOfoo.java"; |
| 98 | + MatcherAssert.assertThat( |
| 99 | + String.format( |
| 100 | + "The %s file is re-generated", |
| 101 | + java |
| 102 | + ), |
| 103 | + temp.resolve( |
| 104 | + String.format( |
| 105 | + "target/generated-sources/%s", |
| 106 | + java |
| 107 | + ) |
| 108 | + ).toFile().exists(), |
| 109 | + Matchers.is(true) |
| 110 | + ); |
| 111 | + final String pinfo = "package-info.java"; |
| 112 | + MatcherAssert.assertThat( |
| 113 | + String.format( |
| 114 | + "The %s file must not exist, but it doesn't", |
| 115 | + pinfo |
| 116 | + ), |
| 117 | + temp.resolve( |
| 118 | + String.format( |
| 119 | + "target/generated-sources/%s", |
| 120 | + pinfo |
| 121 | + ) |
| 122 | + ).toFile().exists(), |
| 123 | + Matchers.is(false) |
| 124 | + ); |
| 125 | + } |
| 126 | + ); |
| 127 | + } |
| 128 | +} |
0 commit comments