TestPty 0.1.0
dotnet add package TestPty --version 0.1.0
NuGet\Install-Package TestPty -Version 0.1.0
<PackageReference Include="TestPty" Version="0.1.0" />
<PackageVersion Include="TestPty" Version="0.1.0" />
<PackageReference Include="TestPty" />
paket add TestPty --version 0.1.0
#r "nuget: TestPty, 0.1.0"
#:package TestPty@0.1.0
#addin nuget:?package=TestPty&version=0.1.0
#tool nuget:?package=TestPty&version=0.1.0
test-pty
Drive a terminal program from a C# test: give it a pseudo-terminal, send it keys, and assert on what it drew.
Two things separate this from the shell-script and Python drivers it replaces. It synchronises on output rather than on sleeps — every wait is for text to appear or the screen to settle, with a timeout — so a test cannot pass or fail because a machine was busy. And it interprets the escape sequences into a virtual screen, so a test asserts that a cell says what it should rather than matching a byte stream with cursor moves embedded in it.
using PtySession pty = PtySession.Start(new PtyOptions("sh", ["-i"])
{
Size = (80, 24),
Environment = new Dictionary<string, string>(StringComparer.Ordinal) { ["PS1"] = "$ " },
});
await pty.WaitFor("$ ");
pty.Send("printf 'working'" + Keys.Enter);
await pty.WaitFor("working");
pty.Send("printf '\\rdone '" + Keys.Enter);
await pty.WaitForIdle();
Assert.Contains("done", pty.Screen.ToText(), StringComparison.Ordinal);
That example is not illustrative: it is the body of RealProgramTests.The_readme_example_works, so
it is compiled and run by the suite. If you change one, change the other.
Unix only. The child runs under forkpty, with a real controlling terminal, so a Ctrl-C you send
arrives as a signal rather than as a byte nobody acts on.
Test-only. Nothing here ships inside a product.
What you get
PtySession |
The façade. Send, WaitFor, WaitForScreen, WaitForIdle, WaitForExit, Resize, Screen, PlainText, RawCapture, SaveCapture. |
Screen |
A grid of cells with a cursor. Row, Cell, ToText, CursorRow, CursorColumn, plus IsCursorVisible, IsAlternateScreenActive and UnhandledSequences. |
Keys |
CtrlC, Enter, Up, Home, Delete and the rest, written once rather than in every consumer's tests. |
PtyOptions |
Program and arguments, working directory, environment, size, TERM, the default timeout, and where to write a capture when a wait fails. |
PtyTimeoutException |
What was waited for, for how long, and the screen as it stood. A timeout that does not show the screen wastes the failure. |
Both waits and the screen are deliberately shallow: WaitFor searches the decoded byte stream, and
Screen answers what was drawn. Use the stream for a shell, the screen for a TUI.
Status
Working and under test on macOS arm64 and Ubuntu 24.04 aarch64: 97 cases, nothing skipped, and the suite holds over twenty consecutive runs on both.
There is no Windows support. A ConPTY backend was written and then removed rather than shipped
without ever having been executed; PtyBackends.Create() says so if you try. The reasoning, and what
bringing it back would cost, is in Phase 3 of plans/pty-test-harness.md — which remains the source
of truth for what is done and what is not.
Used by
- sharp-shell — the interactive line editor
- duetui — the Terminal.Gui front end, replacing
non-ai/support/pty-drive.py
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0 | 89 | 11/11/2026 |