Skip to content

Commit 658cddd

Browse files
committed
finish expect refactor
1 parent 2c78595 commit 658cddd

4 files changed

Lines changed: 132 additions & 198 deletions

File tree

ci/expect_scripts/env.exp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ source ./ci/expect_scripts/shared-code.exp
1010
spawn $env(TESTS_DIR)env
1111

1212
expect "Testing Env module functions..." {
13-
expect -re "Testing Env.cwd!:" {
13+
expect "Testing Env.cwd!:" {
1414
# Match cwd path that has ArbitraryBytes with non-empty list of integers
1515
expect -re {cwd: /[^\r\n]*\r\n} {
1616

17-
expect -re "Testing Env.exe_path!:" {
17+
expect "Testing Env.exe_path!:" {
1818
# Match exe_path with any valid format
1919
expect -re {exe_path: /[^\r\n]*\r\n} {
2020

21-
expect -re "Testing Env.platform!:" {
21+
expect "Testing Env.platform!:" {
2222
# Match platform info with any arch and OS
2323
# Literal braces in regex need to be escaped: \{ and \}
2424
expect -re {Current platform:\{arch: \w+, os: \w+\}} {
2525

26-
expect -re "Testing Env.dict!:" {
26+
expect "Testing Env.dict!:" {
2727
# Match environment variables count as non-zero number
2828
expect -re {Environment variables count: (\d+)} {
2929
set env_count $expect_out(1,string)
@@ -35,7 +35,7 @@ expect "Testing Env module functions..." {
3535
# Literal brackets [], parentheses (), and quotes "" need escaping or careful handling
3636
expect -re {Sample environment variables:\[\("\w+", ".*"\)(, \("\w+", ".*"\))*\]} {
3737

38-
expect -re "Testing Env.set_cwd!:" {
38+
expect "Testing Env.set_cwd!:" {
3939
# Match changed directory path with non-empty list of integers
4040
expect -re {Changed current directory to: /[^\r\n]*\r\n} {
4141

ci/expect_scripts/file.exp

Lines changed: 57 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -9,108 +9,63 @@ source ./ci/expect_scripts/shared-code.exp
99

1010
spawn $env(TESTS_DIR)file
1111

12-
expect "Testing some File functions..." {
13-
expect "This will create and manipulate test files in the current directory." {
14-
15-
# Test File.write_bytes! and File.read_bytes!
16-
expect "Testing File.write_bytes! and File.read_bytes!:" {
17-
expect "Bytes in test_bytes.txt: \\\[72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33\\\]" {
18-
19-
# Test File.write!
20-
expect "Testing File.write!:" {
21-
expect "Content of test_write.json: {\"some\":\"json stuff\"}" {
22-
23-
# Test File.is_file!
24-
expect "Testing File.is_file!:" {
25-
expect "✓ test_bytes.txt is confirmed to be a file" {
26-
27-
# Test File.is_sym_link!
28-
expect "Testing File.is_sym_link!:" {
29-
expect "✓ test_bytes.txt is not a symbolic link" {
30-
expect "✓ test_symlink.txt is a symbolic link" {
31-
32-
# Test File.type!
33-
expect "Testing File.type!:" {
34-
expect "test_bytes.txt file type: IsFile" {
35-
expect ". file type: IsDir" {
36-
expect "test_symlink.txt file type: IsSymLink" {
37-
38-
# Test File.open_reader_with_capacity!
39-
expect "Testing File.open_reader_with_capacity!:" {
40-
expect "✓ Successfully opened reader with 3 byte capacity" {
41-
42-
# Test reading lines from file
43-
expect "Reading lines from file:" {
44-
expect "Line 1: First line" {
45-
expect "" {
46-
expect "Line 2: Second line" {
47-
expect "" {
48-
49-
# Test File.hard_link!
50-
expect "Testing File.hard_link!:" {
51-
expect "✓ Successfully created hard link: test_link_to_original.txt" {
52-
expect "Hard link inodes should be equal: Bool.true" {
53-
expect "✓ Hard link contains same content as original" {
54-
55-
# Test File.rename!
56-
expect "Testing File.rename!:" {
57-
expect "✓ Successfully renamed test_rename_original.txt to test_rename_new.txt" {
58-
expect "✓ Original file test_rename_original.txt no longer exists" {
59-
expect "✓ Renamed file test_rename_new.txt exists" {
60-
expect "✓ Renamed file has correct content" {
61-
62-
# Test File.exists!
63-
expect "Testing File.exists!:" {
64-
expect "✓ File.exists! returns true for a file that exists" {
65-
expect "✓ File.exists! returns false for a file that does not exist" {
66-
67-
expect "I ran all file function tests." {
68-
69-
expect "Cleaning up test files..." {
70-
expect "✓ Deleted all files." {
71-
72-
# Final completion message
73-
74-
expect eof {
75-
check_exit_and_segfault
76-
}
77-
}
78-
}
79-
}
80-
}
81-
}
82-
}
83-
}
84-
}
85-
}
86-
}
87-
}
88-
}
89-
}
90-
}
91-
}
92-
}
93-
}
94-
}
95-
}
96-
}
97-
}
98-
}
99-
}
100-
}
101-
}
102-
}
103-
}
104-
}
105-
}
106-
}
107-
}
108-
}
109-
}
110-
}
111-
}
112-
}
12+
set expected_output [normalize_output "
13+
Testing some File functions...
14+
This will create and manipulate test files in the current directory.
15+
16+
Testing File.write_bytes! and File.read_bytes!:
17+
Bytes in test_bytes.txt: \\\[72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33\\\]
18+
19+
Testing File.write!:
20+
Content of test_write.json: {\"some\":\"json stuff\"}
21+
22+
Testing File.is_file!:
23+
✓ test_bytes.txt is confirmed to be a file
24+
25+
Testing File.is_sym_link!:
26+
✓ test_bytes.txt is not a symbolic link
27+
✓ test_symlink.txt is a symbolic link
28+
29+
Testing File.type!:
30+
test_bytes.txt file type: IsFile
31+
. file type: IsDir
32+
test_symlink.txt file type: IsSymLink
33+
34+
Testing File.open_reader_with_capacity!:
35+
✓ Successfully opened reader with 3 byte capacity
36+
37+
Reading lines from file:
38+
Line 1: First line
39+
40+
Line 2: Second line
41+
42+
43+
Testing File.hard_link!:
44+
✓ Successfully created hard link: test_link_to_original.txt
45+
Hard link inodes should be equal: Bool.true
46+
✓ Hard link contains same content as original
47+
48+
Testing File.rename!:
49+
✓ Successfully renamed test_rename_original.txt to test_rename_new.txt
50+
✓ Original file test_rename_original.txt no longer exists
51+
✓ Renamed file test_rename_new.txt exists
52+
✓ Renamed file has correct content
53+
54+
Testing File.exists!:
55+
✓ File.exists! returns true for a file that exists
56+
✓ File.exists! returns false for a file that does not exist
57+
58+
I ran all file function tests.
59+
60+
Cleaning up test files...
61+
✓ Deleted all files.
62+
"]
63+
64+
expect -re $expected_output {
65+
expect eof {
66+
check_exit_and_segfault
67+
}
11368
}
11469

115-
puts stderr "\nExpect script failed: output was different from expected value. uncomment `exp_internal 1` to debug."
70+
puts stderr "\nExpect script failed: output was not as expected. Diff the output with expected_output in this script. Alternatively, uncomment `exp_internal 1` to debug."
11671
exit 1

ci/expect_scripts/sqlite.exp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ set env(DB_PATH) $env(TESTS_DIR)test.db
1111

1212
spawn $env(TESTS_DIR)sqlite
1313

14-
expect -exact "Rows: {col_bytes: \[72, 101, 108, 108, 111\], col_f32: 78.9, col_f64: 123.456, col_i16: 1234, col_i32: 123456, col_i8: 123, col_nullable_bytes: (NotNull \[119, 111, 114, 108, 100\]), col_nullable_f32: (NotNull 12.34), col_nullable_f64: (NotNull 456.789), col_nullable_i16: (NotNull 5678), col_nullable_i32: (NotNull 456789), col_nullable_i64: (NotNull 987654321), col_nullable_i8: (NotNull 56), col_nullable_str: (NotNull \"nullable text\"), col_nullable_u16: (NotNull 8765), col_nullable_u32: (NotNull 987654), col_nullable_u64: (NotNull 123456789), col_nullable_u8: (NotNull 78), col_text: \"example text\", col_u16: 4321, col_u32: 654321, col_u8: 234}\r\n{col_bytes: \[119, 111, 114, 108, 100\], col_f32: 23.45, col_f64: 456.789, col_i16: 5678, col_i32: 789012, col_i8: 45, col_nullable_bytes: Null, col_nullable_f32: (NotNull 67.89), col_nullable_f64: Null, col_nullable_i16: Null, col_nullable_i32: (NotNull 123456), col_nullable_i64: Null, col_nullable_i8: Null, col_nullable_str: Null, col_nullable_u16: Null, col_nullable_u32: (NotNull 654321), col_nullable_u64: Null, col_nullable_u8: Null, col_text: \"sample text\", col_u16: 9876, col_u32: 1234567, col_u8: 123}\r\n" {
15-
expect "Row count: 2\r\n" {
16-
expect -exact "Updated rows: \[\"Updated text 1\", \"Updated text 2\"\]\r\n" {
17-
expect -exact "Tagged value test: \[(String \"example text\"), (String \"sample text\")\]\r\n" {
18-
expect "Error: Mismatch: Data type mismatch\r\n" {
19-
expect "Success!\r\n" {
20-
expect eof {
21-
check_exit_and_segfault
22-
}
23-
}
24-
}
25-
}
26-
}
27-
}
28-
}
29-
#}
14+
set expected_output [normalize_output "
15+
Rows: {col_bytes: \\\[72, 101, 108, 108, 111\\\], col_f32: 78.9, col_f64: 123.456, col_i16: 1234, col_i32: 123456, col_i8: 123, col_nullable_bytes: (NotNull \\\[119, 111, 114, 108, 100\\\]), col_nullable_f32: (NotNull 12.34), col_nullable_f64: (NotNull 456.789), col_nullable_i16: (NotNull 5678), col_nullable_i32: (NotNull 456789), col_nullable_i64: (NotNull 987654321), col_nullable_i8: (NotNull 56), col_nullable_str: (NotNull \"nullable text\"), col_nullable_u16: (NotNull 8765), col_nullable_u32: (NotNull 987654), col_nullable_u64: (NotNull 123456789), col_nullable_u8: (NotNull 78), col_text: \"example text\", col_u16: 4321, col_u32: 654321, col_u8: 234}
16+
{col_bytes: \\\[119, 111, 114, 108, 100\\\], col_f32: 23.45, col_f64: 456.789, col_i16: 5678, col_i32: 789012, col_i8: 45, col_nullable_bytes: Null, col_nullable_f32: (NotNull 67.89), col_nullable_f64: Null, col_nullable_i16: Null, col_nullable_i32: (NotNull 123456), col_nullable_i64: Null, col_nullable_i8: Null, col_nullable_str: Null, col_nullable_u16: Null, col_nullable_u32: (NotNull 654321), col_nullable_u64: Null, col_nullable_u8: Null, col_text: \"sample text\", col_u16: 9876, col_u32: 1234567, col_u8: 123}
17+
Row count: 2
18+
Updated rows: \\\[\"Updated text 1\", \"Updated text 2\"\\\]
19+
Tagged value test: \\\[(String \"example text\"), (String \"sample text\")\\\]
20+
Error: Mismatch: Data type mismatch
21+
Success!
22+
"]
23+
24+
expect $expected_output {
25+
expect eof {
26+
check_exit_and_segfault
27+
}
28+
}
29+
3030

3131
puts stderr "\nExpect script failed: output was different from expected value. uncomment `exp_internal 1` to debug."
3232
exit 1

0 commit comments

Comments
 (0)