From 52df8e16b3ae4cdafe55d0ee58d685733c150365 Mon Sep 17 00:00:00 2001 From: mahiro21h Date: Sun, 29 Dec 2024 14:03:06 +0300 Subject: [PATCH] add a test to check if read_until_delimiter() raises EOF --- stdlib/test/builtin/test_issue_3908.mojo | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 stdlib/test/builtin/test_issue_3908.mojo diff --git a/stdlib/test/builtin/test_issue_3908.mojo b/stdlib/test/builtin/test_issue_3908.mojo new file mode 100644 index 0000000000..3e468a428f --- /dev/null +++ b/stdlib/test/builtin/test_issue_3908.mojo @@ -0,0 +1,28 @@ +# ===----------------------------------------------------------------------=== # +# Copyright (c) 2024, Modular Inc. All rights reserved. +# +# Licensed under the Apache License v2.0 with LLVM Exceptions: +# https://llvm.org/LICENSE.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ===----------------------------------------------------------------------=== # +# RUN: echo -n | %mojo %s + +from builtin.io import _fdopen +from testing import testing + + +fn test_read_until_delimiter_raises_eof() raises: + var stdin = _fdopen["r"](0) + with testing.assert_raises(contains="EOF"): + # Assign to a variable to silence a warning about unused String value + # if an error wasn't raised. + var unused = stdin.read_until_delimiter("\n") + + +fn main() raises: + test_read_until_delimiter_raises_eof()