Skip to content

Commit

Permalink
Initial progress to validate Gherkin files
Browse files Browse the repository at this point in the history
  • Loading branch information
jabrena committed Jan 1, 2025
1 parent 2950a48 commit 1238b78
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 1 deletion.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
50 changes: 50 additions & 0 deletions 2015/src/test/java/info/jab/aoc/GherkinValidatorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package info.jab.aoc;

import io.cucumber.gherkin.GherkinParser;
import io.cucumber.messages.types.Envelope;
import io.cucumber.messages.types.GherkinDocument;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

public class GherkinValidatorTest {

@Disabled
@Test
void validateAllGherkinFiles() throws IOException {
// Encuentra todos los archivos .feature recursivamente
try (Stream<Path> paths = Files.walk(Paths.get("src/main/gherkin"))) {
paths.filter(Files::isRegularFile)
.filter(path -> path.toString().endsWith(".feature"))
.forEach(this::validateGherkinFile);
}
}

private void validateGherkinFile(Path path) {
try {
GherkinParser parser = GherkinParser.builder().build();

// Validar el documento - si no hay excepciones, el archivo es válido
Optional<GherkinDocument> doc = parser.parse(path)
.filter(envelope -> envelope.getGherkinDocument() != null)
.map(Envelope::getGherkinDocument)
.findFirst()
.orElseThrow(() -> new IllegalStateException("No se encontró GherkinDocument en " + path));

// Si llegamos aquí, el documento es válido
System.out.println("Archivo válido: " + path);

} catch (Exception e) {
throw new AssertionError(
"Error validando archivo: " + path + "\n" + e.getMessage(), e);
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ java -version
./mvnw -pl 2015 clean compile -am
./mvnw -pl 2015 clean verify -am
./mvnw -pl 2015 clean test -Dtest=Day9Test
./mvnw -pl 2016 clean dependency:tree
./mvnw -pl 2015 clean dependency:tree
./mvnw -pl 2016 clean verify surefire-report:report -DshowSuccess=false
jwebserver -p 9000 -d "$(pwd)/2024/target/reports"

Expand Down
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

<junit-jupiter.version>5.11.4</junit-jupiter.version>
<assertj-core.version>3.26.3</assertj-core.version>
<cucumber-gherkin.version>30.0.4</cucumber-gherkin.version>

<jol.version>0.17</jol.version>
<jmh.version>1.37</jmh.version>
Expand Down Expand Up @@ -112,6 +113,16 @@
<artifactId>assertj-core</artifactId>
<version>${assertj-core.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-gherkin</artifactId>
<version>${cucumber-gherkin.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>${cucumber-gherkin.version}</version>
</dependency>

<!-- JOL -->
<dependency>
Expand Down Expand Up @@ -182,6 +193,17 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-gherkin</artifactId>
<version>7.15.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<scope>test</scope>
</dependency>

<!-- JMH -->
<dependency>
Expand Down

0 comments on commit 1238b78

Please sign in to comment.