Merge remote-tracking branch 'upstream/master' into issue-2588

This commit is contained in:
Bennet Bleßmann
2024-10-04 19:11:26 +02:00
218 changed files with 22575 additions and 7754 deletions

View File

@@ -0,0 +1,5 @@
X = 1.
use_module(library(dif)).
X = 1.
dif(X,1).
halt.

View File

@@ -0,0 +1,4 @@
X = 1.
true.
X = 1.
dif:dif(X,1).

View File

@@ -0,0 +1,2 @@
# issue 857
args = ["-f", "--no-add-history"]

View File

@@ -0,0 +1 @@
:- initialization(throw(e)).

View File

@@ -0,0 +1,3 @@
['throw_e.pl'].
['throw_e.pl'].
halt.

View File

@@ -0,0 +1,2 @@
throw(e).
throw(e).

View File

@@ -0,0 +1,2 @@
# issue 852
args = ["-f", "--no-add-history"]

View File

@@ -0,0 +1,3 @@
test :- write(world), nl.
:- initialization(write(hello)).

View File

@@ -0,0 +1 @@
helloworld

View File

@@ -0,0 +1,2 @@
# issue 820
args = ["-f", "--no-add-history", "-g", "test,halt", "goals.pl"]

View File

@@ -0,0 +1,3 @@
test :- write(world), nl.
:- initialization(write(hello)).

View File

@@ -0,0 +1 @@
helloworld

View File

@@ -0,0 +1,2 @@
# issue 820
args = ["-f", "--no-add-history", "-g", "test", "-g", "halt", "goals.pl"]

View File

@@ -0,0 +1,11 @@
use_module(library(dif)).
use_module(library(iso_ext)).
-X\=X.
-X=X.
dif(-X,X).
dif(-X,X), -X=X.
call_residue_vars(dif(-X,X), Vars).
set_prolog_flag(occurs_check, true).
-X\=X.
dif(-X,X).
halt.

View File

@@ -0,0 +1,10 @@
true.
true.
false.
X = -X.
dif:dif(-X,X).
false.
Vars = [X], dif:dif(-X,X).
true.
true.
true.

View File

@@ -0,0 +1,2 @@
# issue 844
args = ["-f", "--no-add-history"]

View File

@@ -0,0 +1,2 @@
use_module(library(freeze)), freeze(X,false), X \=a.
halt.

View File

@@ -0,0 +1 @@
freeze:freeze(X,false).

View File

@@ -0,0 +1,2 @@
# issue 807
args = ["-f", "--no-add-history"]

View File

@@ -0,0 +1,2 @@
write(a), write(b), false.
halt.

View File

@@ -0,0 +1 @@
ab false.

View File

@@ -0,0 +1,2 @@
# issue 815
args = ["-f", "--no-add-history"]

View File

@@ -0,0 +1,3 @@
:- set_prolog_flag(occurs_check, true).
f(X, g(X)).

View File

@@ -0,0 +1,2 @@
f(X, X).
halt.

View File

@@ -0,0 +1 @@
false.

View File

@@ -0,0 +1,2 @@
# issue 841
args = ["-f", "--no-add-history", "occurs_check_example.pl"]

View File

@@ -0,0 +1,6 @@
set_prolog_flag(occurs_check, true).
X = -X.
asserta(f(X,g(X))).
f(X,X).
X-X = X-g(X).
halt.

View File

@@ -0,0 +1,5 @@
true.
false.
true.
false.
false.

View File

@@ -0,0 +1,2 @@
# issue 841
args = ["-f", "--no-add-history"]

View File

@@ -0,0 +1 @@
:- op(900, fy, [$,@]).

View File

View File

View File

@@ -0,0 +1,2 @@
# issue 839
args = ["-f", "--no-add-history", "op3.pl", "-g", "halt"]

View File

@@ -0,0 +1,6 @@
os:argv(V).
os:argv(["test1"|_]).
os:argv(["--"|_]).
os:argv([V, "--"|_]).
os:argv(["test2"|_]).
os:argv([]).

View File

@@ -0,0 +1,6 @@
V = ["test1","--","test2"].
true.
false.
V = "test1".
false.
false.

View File

@@ -0,0 +1,2 @@
# https://github.com/mthom/scryer-prolog/pull/2263#issuecomment-1874400820
args = ["-f", "--no-add-history", "--", "test1", "--", "test2"]

View File

View File

@@ -0,0 +1,6 @@
os:argv(V).
os:argv(["test1"|_]).
os:argv(["--"|_]).
os:argv([V, "--"|_]).
os:argv(["test2"|_]).
os:argv([]).

View File

@@ -0,0 +1,6 @@
V = ["test1","--","test2","--"].
true.
false.
V = "test1".
false.
false.

View File

@@ -0,0 +1,2 @@
# https://github.com/mthom/scryer-prolog/pull/2263#issuecomment-1874400820
args = ["-f", "--no-add-history", "--", "test1", "--", "test2", "--"]

View File

@@ -0,0 +1,4 @@
% hello
% line!
a :- b(X).

View File

@@ -0,0 +1,2 @@
['singleton_example.pl'].
halt.

View File

@@ -0,0 +1,2 @@
% Warning: singleton variables X at line 4 of singleton_example.pl
true.

View File

@@ -0,0 +1,2 @@
# issue 812
args = ["-f", "--no-add-history"]

View File

@@ -0,0 +1 @@
All tests passed

View File

@@ -0,0 +1 @@
args = ["-f", "--no-add-history", "src/tests/acyclic_term.pl", "-f", "-g", "main_quiet"]

View File

@@ -0,0 +1,48 @@
use_module(library(arithmetic)).
use_module(library(assoc)).
use_module(library(atts)).
use_module(library(between)).
use_module(library(charsio)).
use_module(library(clpb)).
use_module(library(clpz)).
use_module(library(cont)).
use_module(library(crypto)).
use_module(library(csv)).
use_module(library(dcgs)).
use_module(library(debug)).
use_module(library(diag)).
use_module(library(dif)).
use_module(library(error)).
use_module(library(ffi)).
use_module(library(files)).
use_module(library(format)).
use_module(library(freeze)).
use_module(library(gensym)).
use_module(library(http/http_open)).
use_module(library(http/http_server)).
use_module(library(iso_ext)).
use_module(library(lambda)).
use_module(library(lists)).
use_module(library(ordsets)).
use_module(library(os)).
use_module(library(pairs)).
use_module(library(pio)).
use_module(library(queues)).
use_module(library(random)).
use_module(library(reif)).
use_module(library(serialization/abnf)).
use_module(library(serialization/json)).
use_module(library(sgml)).
use_module(library(si)).
use_module(library(simplex)).
use_module(library(sockets)).
use_module(library(tabling)).
use_module(library(terms)).
use_module(library(time)).
use_module(library(tls)).
use_module(library(ugraphs)).
use_module(library(uuid)).
use_module(library(wasm)).
use_module(library(when)).
use_module(library(xpath)).
halt.

View File

@@ -0,0 +1,47 @@
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.
true.

View File

@@ -0,0 +1 @@
args = ["-f", "--no-add-history"]

View File

@@ -0,0 +1 @@
All tests passed

View File

@@ -0,0 +1 @@
args = ["-f", "--no-add-history", "src/tests/dif.pl", "-f", "-g", "use_module(library(dif_tests)), dif_tests:main_quiet(dif_tests)"]

View File

@@ -0,0 +1,107 @@
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl1.pl -g halt
error(domain_error(operator_specifier,moin),load/1).
```
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl2.pl -g halt
error(domain_error(operator_priority,4000),load/1).
```
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl3.pl -g halt
error(type_error(list,todo_insert_invalid_term_here),load/1).
```
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl4.pl -g halt
error(domain_error(directive,op/4),load/1).
```
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl5.pl -g halt
error(domain_error(directive,(;)/2),load/1).
```
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl6.pl -g halt
error(domain_error(directive,todo_insert_invalid_term_here),load/1).
```
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl7.pl -g halt
error(domain_error(operator_specifier,todo_insert_invalid_term_here),load/1).
```
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl8.pl -g halt
% Warning: singleton variables Var at line 0 of invalid_decl8.pl
error(domain_error(operator_specifier,todo_insert_invalid_term_here),load/1).
```
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl9.pl -g halt
% Warning: singleton variables Var at line 0 of invalid_decl9.pl
error(type_error(integer,todo_insert_invalid_term_here),load/1).
```
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl10.pl -g halt
```
FIXME I belive the following test should result in a `error(instantiation_error,load/1)` error instead of the current error.
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl11.pl -g halt
% Warning: singleton variables Var at line 0 of invalid_decl11.pl
error(type_error(list,todo_insert_invalid_term_here),load/1).
```
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl12.pl -g halt
error(permission_error(create,operator,{}),load/1).
```
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl13.pl -g halt
error(permission_error(create,operator,{}),load/1).
```
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl14.pl -g halt
error(permission_error(create,operator,'|'),load/1).
```
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl15.pl -g halt
error(permission_error(create,operator,'|'),load/1).
```
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl16.pl -g halt
error(permission_error(modify,operator,','),load/1).
```
```trycmd
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl_issue2467.pl -g halt
% Warning: singleton variables D at line 0 of invalid_decl_issue2467.pl
error(instantiation_error,load/1).
```

View File

@@ -0,0 +1 @@
All tests passed

View File

@@ -0,0 +1 @@
args = ["-f", "--no-add-history", "src/tests/ground.pl", "-f", "-g", "use_module(library(ground_tests)), ground_tests:main_quiet(ground_tests)"]

View File

@@ -0,0 +1,2 @@
[A,A]65
All tests passed

View File

@@ -0,0 +1 @@
args = ["-f", "--no-add-history", "src/tests/nth_partial_strings.pl", "-f", "-g", "use_module(library(nth_partial_strings_tests)),nth_partial_strings_tests:main_quiet(nth_partial_strings_tests)"]

View File

@@ -0,0 +1 @@
1+21+31+2>A+B1+G1+2>41+2>B1+2>31+2>31+2>4ba

View File

@@ -0,0 +1 @@
args = ["-f", "--no-add-history", "src/tests/setup_call_cleanup.pl", "-f", "-g", "halt"]

View File

@@ -0,0 +1 @@
All tests passed

View File

@@ -0,0 +1 @@
args = ["-f", "--no-add-history", "src/tests/term_variables.pl", "-f", "-g", "use_module(library(term_variables_tests)),term_variables_tests:main_quiet(term_variables_tests)"]

View File

@@ -0,0 +1 @@
All tests passed

View File

@@ -0,0 +1 @@
args = ["-f", "--no-add-history", "src/tests/when.pl", "-f", "-g", "use_module(library(when_tests)), when_tests:main_quiet(when_tests)"]

View File

@@ -1,6 +1,3 @@
use assert_cmd::Command;
use std::ffi::OsStr;
pub(crate) trait Expectable {
#[track_caller]
fn assert_eq(self, other: &[u8]);
@@ -29,46 +26,8 @@ impl Expectable for &[u8] {
/// Tests whether the file can be successfully loaded
/// and produces the expected output during it
pub(crate) fn load_module_test<T: Expectable>(file: &str, expected: T) {
use scryer_prolog::machine::mock_wam::*;
use scryer_prolog::Machine;
let mut wam = Machine::with_test_streams();
expected.assert_eq(wam.test_load_file(file).as_slice());
}
pub const SCRYER_PROLOG: &str = "scryer-prolog";
pub fn run_top_level_test_no_args<
S: Into<Vec<u8>>,
O: assert_cmd::assert::IntoOutputPredicate<P>,
P: predicates_core::Predicate<[u8]>,
>(
stdin: S,
expected_stdout: O,
) {
run_top_level_test_with_args::<&[&str], _, _, _, _>(&[], stdin, expected_stdout)
}
/// Test whether scryer-prolog
/// produces the expected output when called with the supplied
/// arguments and fed the supplied input
pub fn run_top_level_test_with_args<
A: IntoIterator<Item = AS>,
S: Into<Vec<u8>>,
O: assert_cmd::assert::IntoOutputPredicate<P>,
AS: AsRef<OsStr>,
P: predicates_core::Predicate<[u8]>,
>(
args: A,
stdin: S,
expected_stdout: O,
) {
Command::cargo_bin(SCRYER_PROLOG)
.unwrap()
.arg("-f")
.arg("--no-add-history")
.args(args)
.write_stdin(stdin)
.assert()
.stdout(expected_stdout.into_output())
.success();
}

View File

@@ -1,169 +1,10 @@
use crate::helper::{load_module_test, run_top_level_test_no_args, run_top_level_test_with_args};
use crate::helper::load_module_test;
use serial_test::serial;
// issue #857
#[test]
fn display_constraints() {
run_top_level_test_no_args(
"\
X = 1.\n\
use_module(library(dif)).\n\
X = 1.\n\
dif(X,1).\n
halt.\n",
" \
X = 1.\n \
true.\n \
X = 1.\n \
dif:dif(X,1).\n\
",
);
}
// issue #852
#[test]
fn do_not_duplicate_path_components() {
run_top_level_test_no_args(
"\
['tests-pl/issue852-throw_e.pl'].\n\
['tests-pl/issue852-throw_e.pl'].\n\
halt.\n\
",
" throw(e).\n throw(e).\n",
);
}
// issue #844
#[test]
fn handle_residual_goal() {
run_top_level_test_no_args(
"\
use_module(library(dif)).\n\
use_module(library(atts)).\n\
-X\\=X.\n\
-X=X.\n\
dif(-X,X).\n\
dif(-X,X), -X=X.\n\
call_residue_vars(dif(-X,X), Vars).\n\
set_prolog_flag(occurs_check, true).\n\
-X\\=X.\n\
dif(-X,X).\n\
halt.\n\
",
" \
true.\n \
true.\n \
false.\n \
X = -X.\n \
dif:dif(-X,X).\n \
false.\n \
Vars = [X], dif:dif(-X,X).\n \
true.\n \
true.\n \
true.\n\
",
)
}
// issue #841
#[test]
fn occurs_check_flag() {
run_top_level_test_with_args(
&["tests-pl/issue841-occurs-check.pl"],
"\
f(X, X).\n\
halt.\n\
",
" false.\n",
)
}
#[test]
fn occurs_check_flag2() {
run_top_level_test_no_args(
"\
set_prolog_flag(occurs_check, true).\n\
X = -X.\n\
asserta(f(X,g(X))).\n\
f(X,X).\n\
X-X = X-g(X).\n\
halt.\n\
",
" \
true.\n \
false.\n \
true.\n \
false.\n \
false.\n\
",
)
}
// issue #839
#[test]
fn op3() {
run_top_level_test_with_args(&["tests-pl/issue839-op3.pl", "-g", "halt"], "", "")
}
// issue #820
#[test]
fn multiple_goals() {
run_top_level_test_with_args(
&["-g", "test", "-g", "halt", "tests-pl/issue820-goals.pl"],
"",
"helloworld\n",
);
}
// issue #820
#[test]
fn compound_goal() {
run_top_level_test_with_args(
&["-g", "test,halt", "tests-pl/issue820-goals.pl"],
"",
"helloworld\n",
)
}
// issue #815
#[test]
fn no_stutter() {
run_top_level_test_no_args(
"write(a), write(b), false.\n\
halt.\n\
",
"ab false.\n",
)
}
/*
// issue #812
#[test] // FIXME: the line number is of by one (should be 4), empty line not accounted for or starting to count at line 0?
fn singleton_warning() {
run_top_level_test_no_args(
"['tests-pl/issue812-singleton-warning.pl'].\n\
halt.\n",
"\
Warning: singleton variables X at line 3 of issue812-singleton-warning.pl\n \
true.\n\
",
);
}
*/
// issue #807
#[test]
fn ignored_constraint() {
run_top_level_test_no_args(
"use_module(library(freeze)), freeze(X,false), X \\=a.\n\
halt.",
" freeze:freeze(X,false).\n",
);
}
// issue #831
#[serial]
#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn call_0() {
load_module_test(
"tests-pl/issue831-call0.pl",
@@ -175,3 +16,11 @@ fn call_0() {
fn issue2588_load_html() {
load_module_test("tests-pl/issue2588.pl", "[element(html,[],[element(head,[],[element(title,[],[[H,e,l,l,o,!]])]),element(body,[],[])])]");
}
// issue #2361
#[serial]
#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn call_qualification() {
load_module_test("tests-pl/issue2361-call-qualified.pl", "");
}

View File

@@ -1,3 +1,28 @@
mod helper;
mod issues;
mod src_tests;
/// To add new cli test copy an existing .toml file in `tests/scryer/cli/issues/` or `tests/scryer/cli/issues/src_tests/`,
/// adjust as necessary the `-f` and `--no-add-history` args should be kept but additional args may be added.
/// For input on stdin add a .stdin file with the same filename.
/// Then to generate new reference output files into dump/ run `TRYCMD=dump cargo test -- cli_test`
/// check that the output in the .stdout and .stderr file is as expected, then move them next to the .toml file.
///
/// If a test does not have a .stderr or .stdout the corresponding output is ignored i.e. any and no output is accepted
///
/// to re-generate all reference output files run `TRYCMD=overwrite cargo test -- cli_test`
/// then check that the changes are as expected e.g. by looking at the `git diff`
#[test]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
#[cfg_attr(
miri,
ignore = "miri isolation, unsupported operation: can't call foreign function"
)]
fn cli_tests() {
trycmd::TestCases::new()
.default_bin_name("scryer-prolog")
.case("tests/scryer/cli/issues/*.toml")
.skip("tests/scryer/cli/issues/singleton_warning.toml") // wrong line number
.case("tests/scryer/cli/src_tests/*.toml")
.case("tests/scryer/cli/src_tests/*.md");
}

View File

@@ -1,32 +1,37 @@
use crate::helper::{load_module_test, run_top_level_test_with_args};
use crate::helper::load_module_test;
use serial_test::serial;
#[serial]
#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn builtins() {
load_module_test("src/tests/builtins.pl", "");
}
#[serial]
#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn call_with_inference_limit() {
load_module_test("src/tests/call_with_inference_limit.pl", "");
}
#[serial]
#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn facts() {
load_module_test("src/tests/facts.pl", "");
}
#[serial]
#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn hello_world() {
load_module_test("src/tests/hello_world.pl", "Hello World!\n");
}
#[serial]
#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn syntax_error() {
load_module_test(
"tests-pl/syntax_error.pl",
@@ -36,18 +41,21 @@ fn syntax_error() {
#[serial]
#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn predicates() {
load_module_test("src/tests/predicates.pl", "");
}
#[serial]
#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn rules() {
load_module_test("src/tests/rules.pl", "");
}
#[serial]
#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn setup_call_cleanup_load() {
load_module_test(
"src/tests/setup_call_cleanup.pl",
@@ -55,59 +63,16 @@ fn setup_call_cleanup_load() {
);
}
#[test]
fn setup_call_cleanup_process() {
run_top_level_test_with_args(
&["src/tests/setup_call_cleanup.pl", "-f", "-g", "halt"],
"",
"1+21+31+2>A+B1+G1+2>41+2>B1+2>31+2>31+2>4ba",
);
}
#[serial]
#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn clpz_load() {
load_module_test("src/tests/clpz/test_clpz.pl", "");
}
#[serial]
#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn iso_conformity_tests() {
load_module_test("tests-pl/iso-conformity-tests.pl", "All tests passed");
}
#[test]
fn dif_tests() {
run_top_level_test_with_args(
&["src/tests/dif.pl", "-f", "-g", "main_quiet"],
"",
"All tests passed",
);
}
#[test]
fn ground_tests() {
run_top_level_test_with_args(
&["src/tests/ground.pl", "-f", "-g", "main_quiet"],
"",
"All tests passed",
);
}
#[test]
fn term_variables_tests() {
run_top_level_test_with_args(
&["src/tests/term_variables.pl", "-f", "-g", "main_quiet"],
"",
"All tests passed",
);
}
#[test]
fn acyclic_term_tests() {
run_top_level_test_with_args(
&["src/tests/acyclic_term.pl", "-f", "-g", "main_quiet"],
"",
"All tests passed",
);
}