Skip to content

Commit

Permalink
#3492 farea 0.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 14, 2024
1 parent b4f7aa5 commit 42d476e
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
*/
@SuppressWarnings("PMD.TooManyMethods")
@ExtendWith(MktmpResolver.class)
@ExtendWith(RandomProgramResolver.class)
final class PhiMojoTest {
/**
* Comment.
Expand All @@ -56,13 +57,12 @@ final class PhiMojoTest {
"# This is the default 64+ symbols comment in front of named abstract object.";

@Test
void convertsSimpleObjectToPhi(@Mktmp final Path temp) throws Exception {
void convertsSimpleObjectToPhi(@Mktmp final Path temp,
@RandomProgram final String program) throws Exception {
new Farea(temp).together(
f -> {
f.clean();
f.files().file("src/main/eo/foo.eo").write(
String.format("%s\n[] > foo\n", PhiMojoTest.COMMENT).getBytes()
);
f.files().file("src/main/eo/foo.eo").write(program.getBytes());
f.build()
.plugins()
.appendItself()
Expand Down
41 changes: 41 additions & 0 deletions eo-maven-plugin/src/test/java/org/eolang/maven/RandomProgram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.eolang.maven;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* This annotation is used in unit tests in order to signal
* to JUnit that a certain method argument must be generated
* through the {@link RandomProgramResolver}.
*
* @since 0.42.0
*/
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface RandomProgram {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.eolang.maven;

import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolver;

/**
* This class is instantiated and then called by JUnit when
* an argument of a test method is marked with the {@link RandomProgram}
* annotation.
*
* @since 0.42.0
*/
public final class RandomProgramResolver implements ParameterResolver {

@Override
public boolean supportsParameter(final ParameterContext context,
final ExtensionContext ext) {
return context.getParameter().getType().equals(String.class)
&& context.isAnnotated(RandomProgram.class);
}

@Override
public Object resolveParameter(final ParameterContext context,
final ExtensionContext ext) {
return String.join(
"\n",
"# This is a random program in EO, which supposedly",
"# complies with all syntactic rules of the language,",
"# include the requirements for comments.",
"[] > foo",
" QQ.io.stdout > @",
" \"Hello, world!\\n\"",
""
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<!--
Raise an error if errors are found within program
Raise an error if errors are found within program.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" xmlns:xs="http://www.w3.org/2001/XMLSchema" id="fail-on-errors" version="2.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="fail-on-errors" version="2.0">
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/program/errors/error[@severity='error']">
<xsl:message terminate="yes">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/
package EOorg.EOeolang.EOfs; // NOPMD

import com.yegor256.Mktmp;
import com.yegor256.MktmpResolver;
import java.io.BufferedWriter;
import java.io.IOException;
Expand All @@ -39,7 +40,6 @@
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import com.yegor256.Mktmp;
import org.junit.jupiter.api.extension.ExtendWith;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import EOorg.EOeolang.EOsys.Win32.Kernel32;
import EOorg.EOeolang.EOsys.Win32.WinBase;
import EOorg.EOeolang.EOsys.Win32.WinNT;
import com.yegor256.Mktmp;
import com.yegor256.MktmpResolver;
import java.io.File;
import java.io.IOException;
Expand All @@ -53,7 +54,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import com.yegor256.Mktmp;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
Expand Down
2 changes: 1 addition & 1 deletion eo-runtime/src/test/java/org/eolang/SnippetIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.eolang;

import com.jcabi.log.Logger;
import com.yegor256.Mktmp;
import com.yegor256.MktmpResolver;
import com.yegor256.WeAreOnline;
import com.yegor256.farea.Farea;
Expand All @@ -39,7 +40,6 @@
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.extension.ExtendWith;
import com.yegor256.Mktmp;
import org.junit.jupiter.params.ParameterizedTest;
import org.yaml.snakeyaml.Yaml;

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ SOFTWARE.
<dependency>
<groupId>com.yegor256</groupId>
<artifactId>farea</artifactId>
<version>0.12.0</version>
<version>0.13.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down

0 comments on commit 42d476e

Please sign in to comment.