mirror of
https://github.com/lihop/godot-xterm.git
synced 2025-05-03 20:14:22 +02:00
Add new PTY node (replaces Pseudoterminal node)
Uses fork of node-pty native code for forking pseudoterminals. Uses libuv pipe handle to communicate with the child process. - Paves the way for cross-platform (Linux, macOS and Windows) support. - Renames Pseudoterminal to PTY (which is much easier to type and spell :D). - Better performance than the old Pseudoterminal node. Especially when streaming large amounts of data such as running the `yes` command. - Allows setting custom file, args, initial window size, cwd, env vars (including important ones such as TERM and COLORTERM) and uid/gid on Linux and macOS. - Returns process exit code and terminating signal.
This commit is contained in:
parent
bfa561357e
commit
0dd2378387
36 changed files with 1268 additions and 442 deletions
117
test/integration/unix/pty_unix.test.gd
Normal file
117
test/integration/unix/pty_unix.test.gd
Normal file
|
@ -0,0 +1,117 @@
|
|||
extends "res://addons/gut/test.gd"
|
||||
# WARNING: These test can only be run on the "Unix" platforms (X11, Server, and OSX).
|
||||
# Some of the tests also rely on listing the files in /dev/pts. If you open or close
|
||||
# terminals while these tests are running, it may cause inaccurate results.
|
||||
|
||||
const PTYUnixNative := preload("res://addons/godot_xterm/nodes/pty/unix/pty_unix.gdns")
|
||||
const PTYUnix := preload("res://addons/godot_xterm/nodes/pty/unix/pty_unix.gd")
|
||||
|
||||
|
||||
func before_all():
|
||||
assert(
|
||||
OS.get_name() in ["X11", "Server", "OSX"], "Unix only tests cannot be run on this platform."
|
||||
)
|
||||
|
||||
|
||||
class TestFork:
|
||||
extends "res://addons/gut/test.gd"
|
||||
|
||||
const PTYUnix := preload("res://addons/godot_xterm/nodes/pty/unix/pty_unix.gd")
|
||||
|
||||
var sh_path: String
|
||||
|
||||
func before_all():
|
||||
var output = []
|
||||
var exit_code = OS.execute("command", PoolStringArray(["-v", "sh"]), true, output)
|
||||
assert(exit_code == 0, "sh is required for these tests.")
|
||||
sh_path = output[0].strip_edges()
|
||||
|
||||
func test_fork_creates_new_pts():
|
||||
var num_pts = Helper._get_pts().size()
|
||||
|
||||
var pty = PTYUnix.new()
|
||||
add_child_autofree(pty)
|
||||
var err = pty.fork(sh_path)
|
||||
assert_eq(err, OK)
|
||||
|
||||
var new_num_pts = Helper._get_pts().size()
|
||||
assert_eq(new_num_pts, num_pts + 1)
|
||||
|
||||
|
||||
class TestOpen:
|
||||
extends "res://addons/gut/test.gd"
|
||||
|
||||
func test_open_creates_new_pts():
|
||||
var num_pts = Helper._get_pts().size()
|
||||
|
||||
var result = PTYUnixNative.new().open(0, 0)
|
||||
assert_eq(result[0], OK)
|
||||
|
||||
var new_num_pts = Helper._get_pts().size()
|
||||
assert_eq(new_num_pts, num_pts + 1)
|
||||
|
||||
func test_pty_has_correct_name():
|
||||
var original_pts = Helper._get_pts()
|
||||
|
||||
var result = PTYUnixNative.new().open(0, 0)
|
||||
assert_eq(result[0], OK)
|
||||
|
||||
var new_pts = Helper._get_pts()
|
||||
for pt in original_pts:
|
||||
new_pts.erase(pt)
|
||||
assert_true(result[1].pty in new_pts)
|
||||
|
||||
func test_pty_has_correct_win_size():
|
||||
var cols = 7684
|
||||
var rows = 9314
|
||||
|
||||
var result = PTYUnixNative.new().open(cols, rows)
|
||||
assert_eq(result[0], OK)
|
||||
|
||||
var winsize = Helper._get_winsize(result[1].master)
|
||||
assert_eq(winsize.cols, cols)
|
||||
assert_eq(winsize.rows, rows)
|
||||
|
||||
|
||||
class Helper:
|
||||
static func _get_pts() -> Array:
|
||||
var dir := Directory.new()
|
||||
|
||||
if dir.open("/dev/pts") != OK or dir.list_dir_begin(true, true) != OK:
|
||||
assert(false, "Could not open /dev/pts.")
|
||||
|
||||
var pts := []
|
||||
var file_name := dir.get_next()
|
||||
|
||||
while file_name != "":
|
||||
if file_name.is_valid_integer():
|
||||
pts.append("/dev/pts/%s" % file_name)
|
||||
file_name = dir.get_next()
|
||||
|
||||
return pts
|
||||
|
||||
static func _get_winsize(fd: int) -> Dictionary:
|
||||
var output = []
|
||||
|
||||
assert(
|
||||
OS.execute("command", ["-v", "python"], true, output) == 0,
|
||||
"Python must be installed to run this test."
|
||||
)
|
||||
var python_path = output[0].strip_edges()
|
||||
|
||||
var exit_code = OS.execute(
|
||||
python_path,
|
||||
[
|
||||
"-c",
|
||||
(
|
||||
"import struct, fcntl, termios; print(struct.unpack('hh', fcntl.ioctl(%d, termios.TIOCGWINSZ, '1234')))"
|
||||
% fd
|
||||
)
|
||||
],
|
||||
true,
|
||||
output
|
||||
)
|
||||
assert(exit_code == 0, "Failed to run python command for this test.")
|
||||
|
||||
var size = str2var("Vector2" + output[0].strip_edges())
|
||||
return {rows = int(size.x), cols = int(size.y)}
|
30
test/integration/uv_utils/uv_utils.test.gd
Normal file
30
test/integration/uv_utils/uv_utils.test.gd
Normal file
|
@ -0,0 +1,30 @@
|
|||
extends "res://addons/gut/test.gd"
|
||||
|
||||
const LibuvUtils := preload("res://addons/godot_xterm/nodes/pty/libuv_utils.gd")
|
||||
|
||||
|
||||
class TestGetOSEnviron:
|
||||
extends "res://addons/gut/test.gd"
|
||||
|
||||
const EMPTY_VAR = "GODOT_XTERM_TEST_EMPTY_ENV_VAR"
|
||||
const TEST_VAR = "GODOT_XTERM_TEST_ENV_VAR"
|
||||
const TEST_VAL = "TEST123"
|
||||
|
||||
var env: Dictionary
|
||||
|
||||
func before_each():
|
||||
assert(OS.set_environment(EMPTY_VAR, ""))
|
||||
assert(OS.set_environment(TEST_VAR, TEST_VAL))
|
||||
env = LibuvUtils.get_os_environ()
|
||||
|
||||
func test_has_empty_var():
|
||||
assert_has(env, EMPTY_VAR)
|
||||
|
||||
func test_empty_var_has_empty_val():
|
||||
assert_eq(env[EMPTY_VAR], "")
|
||||
|
||||
func test_has_test_var():
|
||||
assert_has(env, TEST_VAR)
|
||||
|
||||
func test_test_var_has_correct_val():
|
||||
assert_eq(env[TEST_VAR], TEST_VAL)
|
Loading…
Add table
Add a link
Reference in a new issue