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

Standalone pan tests #125

Merged
merged 3 commits into from
Dec 6, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 20 additions & 0 deletions panc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@

<executions>

<execution>
<id>test-jar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>org.quattor.pan.PanTest</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this assembly file is only relevant for this fat jar, bets rename it to assembly-fat.xml or so

</descriptors>

<finalName>panc-${project.version}-fat-jar</finalName>
</configuration>
</execution>

<execution>
<id>jar-with-dependencies</id>
<goals>
Expand Down
25 changes: 25 additions & 0 deletions panc/src/main/assembly/assembly.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<assembly>
<id>with-tests</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>test</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.directory}/test-classes</directory>
<outputDirectory></outputDirectory>
<includes>
<include>**/*.class</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>
2 changes: 2 additions & 0 deletions panc/src/test/java/org/quattor/pan/JavaCompilerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Centre National de la Recherche Scientifique (CNRS).

public class JavaCompilerTest {

public JavaCompilerTest() {}

protected Compiler getDefaultCompiler(File tplfile, File dir,
Formatter formatter) throws SyntaxException {
List<File> path = new LinkedList<File>();
Expand Down
100 changes: 100 additions & 0 deletions panc/src/test/java/org/quattor/pan/PanTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package org.quattor.pan;

import org.quattor.pan.exceptions.SyntaxException;
import java.util.*;

/**
* Created by iliclaey.
*
* When building the panc-project a panc-10.3-SNAPSHOT-fat-jar-with-tests.jar file is created.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use MAJOR.MINOR instead of 10.3

* This jar can be used to execute pan test files and should be used as follows:
* `java -Dpanc.testdir="path" -Dpanc.tmpdir="path" -jar path/to/panc-10.3-SNAPSHOT-fat-jar-with-tests.jar`.
* The panc.testdir and panc.tmpdir properties need to be set, otherwise an error will be thrown.
*
* To be able to execute your tests, they need to conform to a specific directory structure.
* The directory you pass to the panc.testdir property needs to contain the _Functionality_, _Dependency_ or
* _RootElement_ directories, depending on what type of tests you want to run. Each of these directories need to be
* divided in subdirectories, which contain the test files (or more subdirectories).
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mention that this is structure and implementation also/already used as part the panc unittests, and where the .pan testfiles are located in the pan repo (i.e. the path)

* panc.testdir
* |-- Dependency
* |-- Functionality
* | |-- subdir1
* | | |-- file1.pan
* | | |-- file2.pan
* | |-- subdir2
* | | |-- file1.pan
* | | |-- file2.pan
* |-- RootElement
*
* Dependency tests
* ================
* A simple example:
*
* # dep: simple
* object template simple;
*
* Functionality tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

describe this one before the Dependecy tests, as it is the most common one (or even only one)

* ===================
* You can declare whether the expected result will be an exception or a value in the tree.
* For example, if you expect a SyntaxException to be thrown, you would place the following line on top of the file:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also add a short exampole for a value.

*
* # @expect=org.quattor.pan.exception.SyntaxException regex.
*
* The regex is optional and is used to check specific error messages.
* If you expect a specific result, you should use an XPath. For example:
*
* # @expect="/profile/result=1"
*
* RootElement tests
* =================
* Specific functionality tests to test the root element in the tree.
*
*
* To run the tests in a specific directory, additional properties can be passed on to java:
* - test_functionality: runs the tests in the _Functionality_ directory. Default value is true.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_Functionality_ directory -> _Functionality_ subdirectory of panc.testdir

* - test_dependency: runs the tests in the _Dependency_ directory. Default value is false.
* - test_rootelement: runs the tests in the _RootElement_ directory. Default value is false.
*
* For example, when you only want to run the tests in the _Dependency_ directory you would use the following command:
* `java -Dpanc.testdir="path" -Dpanc.tmpdir="path" -Dtest_functionality="false" -Dtest_dependency="true" -jar ...`.
*
*/
public class PanTest {

static Properties props;

public static void main(String[] args) throws SyntaxException {

props = System.getProperties();
runTests();
}

public static void runTests() throws SyntaxException {

JavaCompilerTest jct = new JavaCompilerTest();

String functionality = props.getProperty("test_functionality");
if (functionality != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why so complicated?

if (functionality == null || Boolean.parseBoolean(functionality)) {
    jct.javaFunctionalTests();
}

if (Boolean.parseBoolean(functionality)) {
jct.javaFunctionalTests();
}
} else {
jct.javaFunctionalTests();
}

String dependency = props.getProperty("test_dependency");
if (dependency != null) {
if (Boolean.parseBoolean(dependency)) {
jct.javaDependencyTests();
}
}

String rootElement = props.getProperty("test_rootelement");
if (rootElement != null) {
if (Boolean.parseBoolean(rootElement)) {
jct.javaRootElementTests();
}
}
}
}