#!/bin/sh # Interactive input regression tests for TNT. PORT=${PORT:-12347} PASS=0 FAIL=0 BIN="../tnt" SERVER_PID="" STATE_DIR=$(mktemp -d "${TMPDIR:-/tmp}/tnt-input-test.XXXXXX") cleanup() { if [ -n "$SERVER_PID" ]; then kill "$SERVER_PID" 2>/dev/null || true wait "$SERVER_PID" 2>/dev/null || true fi rm -rf "$STATE_DIR" } trap cleanup EXIT if ! command -v expect >/dev/null 2>&1; then echo "expect not installed; skipping interactive input tests" exit 0 fi if [ ! -f "$BIN" ]; then echo "Error: Binary $BIN not found. Run make first." exit 1 fi SSH_OPTS="-e none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -p $PORT" echo "=== TNT Interactive Input Tests ===" TNT_LANG=zh TNT_RATE_LIMIT=0 "$BIN" -p "$PORT" -d "$STATE_DIR" >"$STATE_DIR/server.log" 2>&1 & SERVER_PID=$! SERVER_READY=0 for _ in 1 2 3 4 5; do if ! kill -0 "$SERVER_PID" 2>/dev/null; then echo "x Server failed to start" sed -n '1,120p' "$STATE_DIR/server.log" exit 1 fi if grep -q "TNT chat server listening" "$STATE_DIR/server.log"; then SERVER_READY=1 break fi sleep 1 done if [ "$SERVER_READY" -eq 1 ]; then echo "✓ server started" PASS=$((PASS + 1)) else echo "x Server did not become ready" sed -n '1,120p' "$STATE_DIR/server.log" exit 1 fi EXPECT_SCRIPT="$STATE_DIR/bracketed-paste.expect" cat >"$EXPECT_SCRIPT" <"$STATE_DIR/expect.log" 2>&1; then if grep -q 'tester|line1 line2 line3' "$STATE_DIR/messages.log" && ! grep -q 'tester|line1$' "$STATE_DIR/messages.log"; then echo "✓ bracketed paste becomes one message" PASS=$((PASS + 1)) else echo "x bracketed paste message log unexpected" cat "$STATE_DIR/messages.log" 2>/dev/null || true FAIL=$((FAIL + 1)) fi else echo "x bracketed paste client failed" sed -n '1,120p' "$STATE_DIR/expect.log" sed -n '1,120p' "$STATE_DIR/server.log" FAIL=$((FAIL + 1)) fi LONG_SCRIPT="$STATE_DIR/long-paste.expect" cat >"$LONG_SCRIPT" <"$STATE_DIR/long-paste.log" 2>&1; then long_line=$(grep 'longer|' "$STATE_DIR/messages.log" | tail -1) content=${long_line#*|} content=${content#*|} content_len=$(printf '%s' "$content" | wc -c | tr -d ' ') if [ "$content_len" -eq 1023 ]; then echo "✓ overlong paste is capped at message limit" PASS=$((PASS + 1)) else echo "x overlong paste length unexpected: $content_len" FAIL=$((FAIL + 1)) fi else echo "x overlong paste client failed" sed -n '1,120p' "$STATE_DIR/long-paste.log" sed -n '1,120p' "$STATE_DIR/server.log" FAIL=$((FAIL + 1)) fi SUPPORT_SCRIPT="$STATE_DIR/support.expect" cat >"$SUPPORT_SCRIPT" <"$STATE_DIR/support.log" 2>&1; then echo "✓ :support renders quick guide" PASS=$((PASS + 1)) else echo "x :support command failed" sed -n '1,160p' "$STATE_DIR/support.log" sed -n '1,120p' "$STATE_DIR/server.log" FAIL=$((FAIL + 1)) fi UNKNOWN_SCRIPT="$STATE_DIR/unknown-command.expect" cat >"$UNKNOWN_SCRIPT" <"$STATE_DIR/unknown-command.log" 2>&1; then echo "✓ mistyped command suggests nearest command" PASS=$((PASS + 1)) else echo "x mistyped command suggestion failed" sed -n '1,160p' "$STATE_DIR/unknown-command.log" sed -n '1,120p' "$STATE_DIR/server.log" FAIL=$((FAIL + 1)) fi echo "" echo "PASSED: $PASS" echo "FAILED: $FAIL" [ "$FAIL" -eq 0 ] && echo "All tests passed" || echo "Some tests failed" exit "$FAIL"