Skip to content

Commit

Permalink
CTEST: Make JPL test for Prolog in Java work
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Wielemaker authored and Jan Wielemaker committed Oct 9, 2018
1 parent 7bc11ec commit 37cfb7a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
22 changes: 18 additions & 4 deletions CMakeLists.txt
Expand Up @@ -39,7 +39,9 @@ if(NOT JAVA_HOME)
endif()

find_package(JNI)
if(JNI_FOUND)
find_package(Java COMPONENTS Development)
if(JNI_FOUND AND Java_FOUND)
include(JUnit)

add_subdirectory(src/java)

Expand Down Expand Up @@ -70,8 +72,20 @@ swipl_plugin(
################
# Testing

test_libs(jpl
PACKAGES plunit)
test_lib(jpl
NAME java_in_prolog
PACKAGES plunit)

if(JUNIT_JAR)
add_test(
NAME jpl:prolog_in_java
COMMAND env SWI_HOME_DIR=../../home
TEST_JPL=../../../packages/jpl/test_jpl.pl
${Java_JAVA_EXECUTABLE}
-Djava.library.path=.
-classpath ${JUNIT_JAR}:src/java/jpl.jar:src/java/jpltest.jar
junit.textui.TestRunner org.jpl7.test.TestJUnit)
endif()

################
# Install examples
Expand All @@ -96,4 +110,4 @@ pkg_doc(
SOURCE jpl.pl jpldoc.tex
DEPENDS jpl)

endif(JNI_FOUND)
endif(JNI_FOUND AND Java_FOUND)
6 changes: 4 additions & 2 deletions src/java/org/jpl7/test/TestJUnit.java
Expand Up @@ -27,6 +27,8 @@ public class TestJUnit extends TestCase {
: System.getenv("TEST_JPL"));
public static final String syntax = (System.getenv("SWIPL_SYNTAX") == null ? "modern"
: System.getenv("SWIPL_SYNTAX"));
public static final String home = (System.getenv("SWI_HOME_DIR") == null ? "../.."
: System.getenv("SWI_HOME_DIR"));

public TestJUnit(String name) { // called for each public void test*()
// method
Expand All @@ -39,12 +41,12 @@ public static junit.framework.Test suite() {
Prolog.set_default_init_args(new String[] {
"swipl.dll", "-x", startup, "-f", "none",
"-g", "true", "--traditional", "-q",
"--home=../..", "--nosignals" });
"--home="+home, "--nosignals" });
} else {
Prolog.set_default_init_args(new String[] {
"swipl.dll", "-x", startup, "-f", "none",
"-g", "true", "-q",
"--home=../..", "--nosignals" });
"--home="+home, "--nosignals" });
}
assertTrue((new Query("consult", new Term[] { new Atom(test_jpl) })).hasSolution());
assertTrue((new Query("use_module(library(jpl))")).hasSolution());
Expand Down
4 changes: 4 additions & 0 deletions test_jpl.pl
Expand Up @@ -48,6 +48,10 @@
:- asserta(user:file_search_path(library, '.')).
:- asserta(user:file_search_path(library, '../plunit')).

% paths for Prolog embedded in Java under CTest
:- asserta(user:file_search_path(library, '../../../packages/jpl')).
:- asserta(user:file_search_path(library, '../../../packages/plunit')).

:- use_module(library(jpl)).
:- use_module(library(plunit)).

Expand Down

0 comments on commit 37cfb7a

Please sign in to comment.