File-oriented testing

inspired by #2191 but for the `run_top_level_test_with_args`s and  `run_top_level_test_no_args instead of the `load_module_test`s
This commit is contained in:
Skgland
2023-12-04 22:00:52 +01:00
committed by Bennet Bleßmann
parent eddcdaabef
commit 1c52de9ab1
62 changed files with 427 additions and 239 deletions

View File

@@ -0,0 +1 @@
helloworld

View File

@@ -0,0 +1,3 @@
# issue 820
args = ["-f", "--no-add-history", "-g", "test,halt", "tests-pl/issue820-goals.pl"]
binary = true

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,3 @@
# issue 857
args = ["-f", "--no-add-history"]
binary = true

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,11 @@
use_module(library(dif)).
use_module(library(atts)).
-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,3 @@
# issue 844
args = ["-f", "--no-add-history"]
binary = true

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,3 @@
# issue 807
args = ["-f", "--no-add-history"]
binary = true

View File

@@ -0,0 +1 @@
helloworld

View File

@@ -0,0 +1,3 @@
# issue 820
args = ["-f", "--no-add-history", "-g", "test", "-g", "halt", "tests-pl/issue820-goals.pl"]
binary = true

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,3 @@
# issue 841
args = ["-f", "--no-add-history", "tests-pl/issue841-occurs-check.pl"]
binary = true

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,3 @@
# issue 841
args = ["-f", "--no-add-history"]
binary = true

View File

View File

View File

@@ -0,0 +1,3 @@
# issue 839
args = ["-f", "--no-add-history", "tests-pl/issue839-op3.pl", "-g", "halt"]
binary = true

View File

@@ -0,0 +1,2 @@
['tests-pl/issue812-singleton-warning.pl'].
halt.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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,2 @@
args = ["-f", "--no-add-history", "src/tests/setup_call_cleanup.pl", "-f", "-g", "halt"]
binary = true

View File

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

View File

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

View File

@@ -37,17 +37,6 @@ pub(crate) fn load_module_test<T: Expectable>(file: &str, expected: T) {
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

View File

@@ -1,165 +1,6 @@
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]

View File

@@ -1,3 +1,17 @@
mod helper;
mod issues;
mod src_tests;
/// to generate new reference output files into dump/ run `TRYCMD=dump cargo test -- cli_test`
/// check that the output is as expected, then move them next to the .toml file
///
/// to re-generate 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]
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");
}

View File

@@ -55,15 +55,6 @@ 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]
fn clpz_load() {
@@ -75,39 +66,3 @@ fn clpz_load() {
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",
);
}