hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

pty_test.ha (657B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use bufio;
      5 use fmt;
      6 use fs;
      7 use io;
      8 use os;
      9 use strings;
     10 
     11 @test fn pty() void = {
     12 	let pty = openpty()!;
     13 	defer io::close(pty.1)!;
     14 	defer io::close(pty.0)!;
     15 
     16 	assert(fs::exists(os::cwd, ptsname(pty.0)!));
     17 
     18 	for (let i: u16 = 5; i < 100; i += 1) {
     19 		let sz1 = ttysize { rows = i, columns = i };
     20 		set_winsize(pty.1, sz1)!;
     21 		let sz2 = winsize(pty.1)!;
     22 		assert(sz2.rows == sz1.rows);
     23 		assert(sz2.columns == sz1.columns);
     24 	};
     25 
     26 	fmt::fprintln(pty.0, "hello, world")!;
     27 	let s = strings::fromutf8(bufio::read_line(pty.1) as []u8)!;
     28 	defer free(s);
     29 	assert(s == "hello, world");
     30 };