Skip to content

Commit d28fbc8

Browse files
committed
Bring the esctest test suite, it was finally time to bring it
over and automate it. Thanks AI! The old test suite based on Python 2.7 stopped working on recent MacOS, and I had been driving blind, and I did not like that. So this fixes that, and in the process, it spotted that the recent fix for color parsing was not quite complete and introduced an error, we needed to use the current terminator for escape sequences, not hardcode to BEL.
1 parent e468331 commit d28fbc8

7 files changed

Lines changed: 118 additions & 135 deletions

File tree

.github/workflows/xcode.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ on:
88

99
env:
1010
DEVELOPER_DIR: /Applications/Xcode_16.4.app/Contents/Developer
11-
# for testing - Removed, as this is no longer a python 2.7 on new systems
12-
# I need to update esctest to 3.0
13-
#PYTHON_BIN: /usr/local/bin/python
1411

1512
jobs:
1613
build:
@@ -24,6 +21,7 @@ jobs:
2421
uses: actions/checkout@v4
2522
with:
2623
repository: migueldeicaza/esctest
24+
ref: python3
2725
path: esctest
2826

2927
- name: List all files, because this is driving me insane, this does not repro anywhere but github
@@ -45,6 +43,5 @@ jobs:
4543
- name: Coverage
4644
run: |
4745
swift test --enable-code-coverage
48-
BINDIR=`swift build --show-bin-path`
49-
TESTDIR=`find $BINDIR -name '*.xctest'`
50-
xcrun llvm-cov report $TESTDIR/Contents/MacOS/SwiftTermPackageTests --instr-profile=.build/debug/codecov/default.profdata -use-color
46+
BINDIR=$(swift build --show-bin-path)
47+
xcrun llvm-cov report "$BINDIR/SwiftTermPackageTests.xctest/Contents/MacOS/SwiftTermPackageTests" --instr-profile=.build/debug/codecov/default.profdata -use-color

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ DerivedData
1010
.build
1111
.DS_Store
1212
*~
13+
esctest/

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,11 @@ build-fuzzer:
4747

4848
run-fuzzer:
4949
./.build/debug/SwiftTermFuzz ../SwiftTermFuzzerCorpus -rss_limit_mb=40480 -jobs=12
50+
51+
clone-esctest:
52+
@if [ -d esctest ]; then \
53+
echo "esctest directory already exists, updating..."; \
54+
cd esctest && git fetch && git checkout python3 && git pull; \
55+
else \
56+
git clone --branch python3 https://github.com/migueldeicaza/esctest.git esctest; \
57+
fi

Sources/SwiftTerm/Terminal.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1877,7 +1877,7 @@ open class Terminal {
18771877
}
18781878

18791879
func reportColor (oscCode: Int, color: Color) {
1880-
sendResponse(cc.OSC, "\(oscCode);\(color.formatAsXcolor ())", ControlCodes.BEL)
1880+
sendResponse(cc.OSC, "\(oscCode);\(color.formatAsXcolor ())", cc.ST)
18811881
}
18821882

18831883
// This handles both setting the foreground, but spill into background and cursor color

Tests/SwiftTermTests/BufferTests.swift

Lines changed: 53 additions & 75 deletions
Large diffs are not rendered by default.

Tests/SwiftTermTests/SwiftTermTests.swift

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,35 @@ import Testing
55
@testable import SwiftTerm
66

77
final class SwiftTermTests {
8-
static var esctest = "esctest/esctest/esctest.py"
8+
static let esctest = "esctest/esctest/esctest.py"
99
static let queue: DispatchQueue = {
1010
let queue = DispatchQueue(label: "Runner", qos: .userInteractive, attributes: .concurrent, autoreleaseFrequency: .inherit, target: nil)
11-
if !FileManager.default.fileExists(atPath: esctest) {
12-
esctest = "/Users/miguel/cvs/SwiftTerm/esctest/esctest/esctest.py"
13-
}
1411
// Ignore SIGCHLD
1512
signal(SIGCHLD, SIG_IGN)
1613
return queue
1714
}()
1815
let termConfig = "--expected-terminal xterm --xterm-checksum=334"
1916
let logfile = NSTemporaryDirectory() + "log"
2017

21-
func python27Bin() -> String? {
18+
func pythonBin() -> String? {
2219
// Check environment variable first
23-
if let python27 = getenv("PYTHON_BIN") {
24-
return String(validatingUTF8: python27)
20+
if let pythonEnv = getenv("PYTHON_BIN") {
21+
return String(validatingUTF8: pythonEnv)
2522
}
26-
23+
24+
// Check common Python 3 locations
25+
let candidates = [
26+
"/usr/bin/python3",
27+
"/usr/local/bin/python3",
28+
"/opt/homebrew/bin/python3"
29+
]
30+
31+
for candidate in candidates {
32+
if FileManager.default.isExecutableFile(atPath: candidate) {
33+
return candidate
34+
}
35+
}
36+
2737
return nil
2838
}
2939

@@ -35,8 +45,8 @@ final class SwiftTermTests {
3545
return nil
3646
}
3747

38-
guard let python27 = python27Bin() else {
39-
print("Skipping test - Python executable not found")
48+
guard let python = pythonBin() else {
49+
print("Skipping test - Python 3 executable not found")
4050
return nil
4151
}
4252

@@ -59,7 +69,7 @@ final class SwiftTermTests {
5969
}
6070
print ("Starting \(SwiftTermTests.esctest) with \(args)")
6171
args.insert(SwiftTermTests.esctest, at: 0)
62-
t.process.startProcess(executable: python27, args: args, environment: nil)
72+
t.process.startProcess(executable: python, args: args, environment: nil)
6373

6474
psem.wait ()
6575
print ("Does the file exist? \(FileManager.default.fileExists (atPath: logfile))")

Tests/SwiftTermTests/UnicodeTests.swift

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ final class SwiftTermUnicode {
152152
#expect(char0_0 == "👩‍❤️‍👨")
153153
}
154154

155-
func testCJKCharacterPositioning ()
155+
@Test func testCJKCharacterPositioning ()
156156
{
157157
let h = HeadlessTerminal (queue: SwiftTermTests.queue) { exitCode in }
158158
let t = h.terminal!
@@ -162,23 +162,23 @@ final class SwiftTermUnicode {
162162
t.feed (text: "あいう")
163163

164164
// Verify character positions
165-
XCTAssertEqual(t.getCharacter(col: 0, row: 0), "")
166-
XCTAssertEqual(t.getCharacter(col: 1, row: 0), "\u{0}") // placeholder
167-
XCTAssertEqual(t.getCharacter(col: 2, row: 0), "")
168-
XCTAssertEqual(t.getCharacter(col: 3, row: 0), "\u{0}") // placeholder
169-
XCTAssertEqual(t.getCharacter(col: 4, row: 0), "")
170-
XCTAssertEqual(t.getCharacter(col: 5, row: 0), "\u{0}") // placeholder
165+
#expect(t.getCharacter(col: 0, row: 0) == "")
166+
#expect(t.getCharacter(col: 1, row: 0) == "\u{0}") // placeholder
167+
#expect(t.getCharacter(col: 2, row: 0) == "")
168+
#expect(t.getCharacter(col: 3, row: 0) == "\u{0}") // placeholder
169+
#expect(t.getCharacter(col: 4, row: 0) == "")
170+
#expect(t.getCharacter(col: 5, row: 0) == "\u{0}") // placeholder
171171

172172
// Verify character widths
173-
XCTAssertEqual(t.getCharData(col: 0, row: 0)?.width, 2)
174-
XCTAssertEqual(t.getCharData(col: 2, row: 0)?.width, 2)
175-
XCTAssertEqual(t.getCharData(col: 4, row: 0)?.width, 2)
173+
#expect(t.getCharData(col: 0, row: 0)?.width == 2)
174+
#expect(t.getCharData(col: 2, row: 0)?.width == 2)
175+
#expect(t.getCharData(col: 4, row: 0)?.width == 2)
176176

177177
// Cursor should be at column 6 after 3 double-width characters
178-
XCTAssertEqual(t.buffer.x, 6)
178+
#expect(t.buffer.x == 6)
179179
}
180180

181-
func testCJKMixedWithAscii ()
181+
@Test func testCJKMixedWithAscii ()
182182
{
183183
let h = HeadlessTerminal (queue: SwiftTermTests.queue) { exitCode in }
184184
let t = h.terminal!
@@ -187,59 +187,48 @@ final class SwiftTermUnicode {
187187
t.feed (text: "aあbいc")
188188

189189
// 'a' at col 0 (width 1)
190-
XCTAssertEqual(t.getCharacter(col: 0, row: 0), "a")
191-
XCTAssertEqual(t.getCharData(col: 0, row: 0)?.width, 1)
190+
#expect(t.getCharacter(col: 0, row: 0) == "a")
191+
#expect(t.getCharData(col: 0, row: 0)?.width == 1)
192192

193193
// 'あ' at col 1 (width 2)
194-
XCTAssertEqual(t.getCharacter(col: 1, row: 0), "")
195-
XCTAssertEqual(t.getCharData(col: 1, row: 0)?.width, 2)
194+
#expect(t.getCharacter(col: 1, row: 0) == "")
195+
#expect(t.getCharData(col: 1, row: 0)?.width == 2)
196196

197197
// 'b' at col 3 (width 1)
198-
XCTAssertEqual(t.getCharacter(col: 3, row: 0), "b")
199-
XCTAssertEqual(t.getCharData(col: 3, row: 0)?.width, 1)
198+
#expect(t.getCharacter(col: 3, row: 0) == "b")
199+
#expect(t.getCharData(col: 3, row: 0)?.width == 1)
200200

201201
// 'い' at col 4 (width 2)
202-
XCTAssertEqual(t.getCharacter(col: 4, row: 0), "")
203-
XCTAssertEqual(t.getCharData(col: 4, row: 0)?.width, 2)
202+
#expect(t.getCharacter(col: 4, row: 0) == "")
203+
#expect(t.getCharData(col: 4, row: 0)?.width == 2)
204204

205205
// 'c' at col 6 (width 1)
206-
XCTAssertEqual(t.getCharacter(col: 6, row: 0), "c")
207-
XCTAssertEqual(t.getCharData(col: 6, row: 0)?.width, 1)
206+
#expect(t.getCharacter(col: 6, row: 0) == "c")
207+
#expect(t.getCharData(col: 6, row: 0)?.width == 1)
208208

209209
// Cursor should be at column 7
210-
XCTAssertEqual(t.buffer.x, 7)
210+
#expect(t.buffer.x == 7)
211211
}
212212

213-
func testChineseCharacterPositioning ()
213+
@Test func testChineseCharacterPositioning ()
214214
{
215215
let h = HeadlessTerminal (queue: SwiftTermTests.queue) { exitCode in }
216216
let t = h.terminal!
217217

218218
// Test Chinese characters (also double-width)
219219
t.feed (text: "中文字")
220220

221-
XCTAssertEqual(t.getCharacter(col: 0, row: 0), "")
222-
XCTAssertEqual(t.getCharacter(col: 2, row: 0), "")
223-
XCTAssertEqual(t.getCharacter(col: 4, row: 0), "")
221+
#expect(t.getCharacter(col: 0, row: 0) == "")
222+
#expect(t.getCharacter(col: 2, row: 0) == "")
223+
#expect(t.getCharacter(col: 4, row: 0) == "")
224224

225225
// All should be width 2
226-
XCTAssertEqual(t.getCharData(col: 0, row: 0)?.width, 2)
227-
XCTAssertEqual(t.getCharData(col: 2, row: 0)?.width, 2)
228-
XCTAssertEqual(t.getCharData(col: 4, row: 0)?.width, 2)
226+
#expect(t.getCharData(col: 0, row: 0)?.width == 2)
227+
#expect(t.getCharData(col: 2, row: 0)?.width == 2)
228+
#expect(t.getCharData(col: 4, row: 0)?.width == 2)
229229

230-
XCTAssertEqual(t.buffer.x, 6)
230+
#expect(t.buffer.x == 6)
231231
}
232-
233-
static var allTests = [
234-
("testCombiningCharacters", testCombiningCharacters),
235-
("testEmoji", testEmoji),
236-
("testEmojiWithModifierBase", testEmojiWithModifierBase),
237-
("testEmojiZWJSequence", testEmojiZWJSequence),
238-
("testEmojiZWJSequenceSimple", testEmojiZWJSequenceSimple),
239-
("testCJKCharacterPositioning", testCJKCharacterPositioning),
240-
("testCJKMixedWithAscii", testCJKMixedWithAscii),
241-
("testChineseCharacterPositioning", testChineseCharacterPositioning),
242-
]
243232
@Test func testZwJSequencePreservesVariationSelector16() {
244233
let h = HeadlessTerminal (queue: SwiftTermTests.queue) { exitCode in }
245234
let t = h.terminal!

0 commit comments

Comments
 (0)