]> Repositorios git - scryer-prolog.git/commitdiff
Test corner cases of stream aliasing
authorEmilie Burgun <[email protected]>
Thu, 6 Feb 2025 22:47:22 +0000 (23:47 +0100)
committerEmilie Burgun <[email protected]>
Thu, 6 Feb 2025 22:47:22 +0000 (23:47 +0100)
src/tests/stream-aliasing.pl [new file with mode: 0644]
tests/scryer/cli/src_tests/alias_dropped_stream.stdin [new file with mode: 0644]
tests/scryer/cli/src_tests/alias_dropped_stream.stdout [new file with mode: 0644]
tests/scryer/cli/src_tests/alias_dropped_stream.toml [new file with mode: 0644]
tests/scryer/cli/src_tests/realias_user_output.stdin [new file with mode: 0644]
tests/scryer/cli/src_tests/realias_user_output.stdout [new file with mode: 0644]
tests/scryer/cli/src_tests/realias_user_output.toml [new file with mode: 0644]
tests/scryer/cli/src_tests/set_output_alias.stderr [new file with mode: 0644]
tests/scryer/cli/src_tests/set_output_alias.stdin [new file with mode: 0644]
tests/scryer/cli/src_tests/set_output_alias.toml [new file with mode: 0644]

diff --git a/src/tests/stream-aliasing.pl b/src/tests/stream-aliasing.pl
new file mode 100644 (file)
index 0000000..3b4eb1a
--- /dev/null
@@ -0,0 +1,19 @@
+% NOTE: the tests in this file will need to be changed once
+% `open(stream(S1), read, _, NewOptions)` creates a new stream handle `S2` instead of updating
+% the options in `S1`. In that case, that specific query will need to be updated
+% to instead change the options of `S1`.
+
+alias_dropped_stream :-
+    open("README.md", read, S, [alias(readme)]),
+    open(stream(S), read, _, [alias(not_readme)]),
+    close(S),
+    stream_property(readme, file_name(_)). % Should throw an existence_error
+
+realias_user_output :-
+    current_output(S),
+    open(stream(S), read, _, [alias(not_user_output)]),
+    stream_property(S, alias(user_output)). % Should succeed
+
+set_output_alias :-
+    set_output(user_error),
+    write(user_output, hello). % Should write into stderr, not stdout
diff --git a/tests/scryer/cli/src_tests/alias_dropped_stream.stdin b/tests/scryer/cli/src_tests/alias_dropped_stream.stdin
new file mode 100644 (file)
index 0000000..39dd913
--- /dev/null
@@ -0,0 +1,2 @@
+alias_dropped_stream.
+halt.
diff --git a/tests/scryer/cli/src_tests/alias_dropped_stream.stdout b/tests/scryer/cli/src_tests/alias_dropped_stream.stdout
new file mode 100644 (file)
index 0000000..1291cbc
--- /dev/null
@@ -0,0 +1 @@
+   error(existence_error(stream,readme),stream_property/0).
diff --git a/tests/scryer/cli/src_tests/alias_dropped_stream.toml b/tests/scryer/cli/src_tests/alias_dropped_stream.toml
new file mode 100644 (file)
index 0000000..06611a9
--- /dev/null
@@ -0,0 +1,2 @@
+# Part of issue 2806
+args = ["-f", "--no-add-history", "src/tests/stream-aliasing.pl"]
diff --git a/tests/scryer/cli/src_tests/realias_user_output.stdin b/tests/scryer/cli/src_tests/realias_user_output.stdin
new file mode 100644 (file)
index 0000000..e6b5d91
--- /dev/null
@@ -0,0 +1,2 @@
+realias_user_output.
+halt.
diff --git a/tests/scryer/cli/src_tests/realias_user_output.stdout b/tests/scryer/cli/src_tests/realias_user_output.stdout
new file mode 100644 (file)
index 0000000..d5c4870
--- /dev/null
@@ -0,0 +1 @@
+   true.
diff --git a/tests/scryer/cli/src_tests/realias_user_output.toml b/tests/scryer/cli/src_tests/realias_user_output.toml
new file mode 100644 (file)
index 0000000..06611a9
--- /dev/null
@@ -0,0 +1,2 @@
+# Part of issue 2806
+args = ["-f", "--no-add-history", "src/tests/stream-aliasing.pl"]
diff --git a/tests/scryer/cli/src_tests/set_output_alias.stderr b/tests/scryer/cli/src_tests/set_output_alias.stderr
new file mode 100644 (file)
index 0000000..2b8b2f1
--- /dev/null
@@ -0,0 +1 @@
+hello   true.
diff --git a/tests/scryer/cli/src_tests/set_output_alias.stdin b/tests/scryer/cli/src_tests/set_output_alias.stdin
new file mode 100644 (file)
index 0000000..43ae91e
--- /dev/null
@@ -0,0 +1,2 @@
+set_output_alias.
+halt.
diff --git a/tests/scryer/cli/src_tests/set_output_alias.toml b/tests/scryer/cli/src_tests/set_output_alias.toml
new file mode 100644 (file)
index 0000000..06611a9
--- /dev/null
@@ -0,0 +1,2 @@
+# Part of issue 2806
+args = ["-f", "--no-add-history", "src/tests/stream-aliasing.pl"]