Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests for showcases #721

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/showcase-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: showcase-tests
run-name: Showcase Tests
on:
pbt-santos marked this conversation as resolved.
Show resolved Hide resolved
schedule:
- cron: '0 0,12 * * *' # run twice daily
push:
branches:
- master
paths:
- 'showcases/'
pull_request:
branches:
- '**'
paths:
- 'showcases/'

jobs:
test:
name: Showcase Compile Test
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Setup Java JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'oracle'
cache: 'maven'
pbt-santos marked this conversation as resolved.
Show resolved Hide resolved

- name: Run Showcase test with latest Legend versions
run: |
mvn versions:use-latest-versions -f legend/showcases/pom.xml
mvn -B -Dmaven.surefire.thread.count=$THREAD_COUNT -showcase.locations=$SHOWCASE_LOCATIONS test
env:
THREAD_COUNT: 3
SHOWCASE_LOCATIONS: legend/showcases/data
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Thumbs.db

# IDE
/.idea/
*.iml

# Dependencies
**/node_modules
Expand Down Expand Up @@ -34,3 +35,6 @@ docs/roadmap.md

# Ignore checked out models
docs/models

# Ignore Java generated files
showcases/target/
2 changes: 1 addition & 1 deletion scripts/buildShowcasesData.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const startTime = Date.now();
console.log(`Building showcase registry data...`);

extractShowcaseRegistryData(
resolve(__dirname, "../showcases"),
resolve(__dirname, "../showcases/data"),
resolve(outputDir, "data.json")
);

Expand Down
14 changes: 14 additions & 0 deletions showcases/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Contribution Guide

Disclaimer: This guide is a work in progress.


## Showcases

Definition: the smallest snippet of code that highlights a feature.


## Navigation

Add any new showcase under the data directory. The src directory will contain
code that helps test and maintain the showcase code.
85 changes: 85 additions & 0 deletions showcases/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.finos</groupId>
<artifactId>legend-showcases</artifactId>
<version>1.0-SNAPSHOT</version>

<name>Legend Showcases</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.surefire.thread.count>3</maven.surefire.thread.count>
<showcase.projects.location>data</showcase.projects.location>
</properties>

<dependencies>
<!-- TODO: auto-update these on a schedule to make local development easier -->
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-extensions-collection-execution</artifactId>
<version>4.18.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-extensions-collection-generation</artifactId>
<version>4.18.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- Fetch Snapshot versions -->
pbt-santos marked this conversation as resolved.
Show resolved Hide resolved
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<configuration>
<includes>
<include>org.finos.legend.engine:legend-engine-extensions-collection-execution</include>
<include>org.finos.legend.engine:legend-engine-extensions-collection-generation</include>
</includes>
<allowSnapshots>true</allowSnapshots>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<parallel>all</parallel>
<threadCount>${maven.surefire.thread.count}
</threadCount> <!-- Thread count is by default per core -->
<!-- <forkCount>3</forkCount>-->
<!-- <reuseForks>true</reuseForks>-->
</configuration>
</plugin>
</plugins>
</build>
</project>
89 changes: 89 additions & 0 deletions showcases/src/test/java/org/example/ShowcaseCompilerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.example;

import org.eclipse.collections.api.factory.Sets;
import org.finos.legend.engine.language.pure.grammar.from.PureGrammarParser;
import org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposer;
import org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerContext;
import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.Assert.assertEquals;

/**
* Unit tests for each showcase that will run in parallel reading from file
*/
@RunWith(Parameterized.class)
public class ShowcaseCompilerTest
{
private static final PathMatcher PURE_FILE_MATCHER = FileSystems.getDefault().getPathMatcher("glob:*.pure");
@Parameter
public Path showcasePath;

@Parameters(name = "{0}")
public static Iterable<?> showcaseFilePathsToTest()
{
final String[] SHOWCASE_LOCATIONS = System.getProperty("showcase.locations", "data").split(",");

Set<Path> showcasePaths = Sets.mutable.empty();

for (String location : SHOWCASE_LOCATIONS)
{
Path path = Paths.get(location);
if (Files.isDirectory(path))
{
showcasePaths.addAll(getShowcaseFilePaths(path));
}
else if (PURE_FILE_MATCHER.matches(path.getFileName()))
{
showcasePaths.add(path);
}
}

return showcasePaths;
}

private static Set<Path> getShowcaseFilePaths(Path showcaseDirectory)
{
try (Stream<Path> pathStream = Files.walk(showcaseDirectory))
{
return pathStream
.filter(p -> !Files.isDirectory(p))
.filter(p -> PURE_FILE_MATCHER.matches(p.getFileName()))
.collect(Collectors.toSet());
}
catch (IOException e)
{
throw new IllegalStateException(String.format("Invalid directory name %s.", showcaseDirectory), e);
}
}

/**
* Tests that a file can be processed by the new Legend version
*/
@Test
public void processShowcaseFile() throws IOException
{
String pureGrammar = String.join("\n", Files.readAllLines(showcasePath));

// TODO: Ideally want compilation and all testables to be run while maintaining comments in the code
PureModelContextData pureModelContextData = PureGrammarParser.newInstance().parseModel(pureGrammar, "", 0, 0, true);
PureGrammarComposer grammarComposer = PureGrammarComposer.newInstance(PureGrammarComposerContext.Builder.newInstance().build());

// Grammar composer adds a trailing newline
assertEquals(pureGrammar + "\n", grammarComposer.renderPureModelContextData(pureModelContextData));
}
}