Skip to content

Commit 7f0cc42

Browse files
Windows (#27)
* Additions for windows * clean up * cleanup * Review updates * Changed pipe test to be slow
1 parent e4cd984 commit 7f0cc42

File tree

8 files changed

+85
-51
lines changed

8 files changed

+85
-51
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup constants
2020
shell: bash
2121
run: |
22-
TOIT_VERSION=v2.0.0-alpha.21
22+
TOIT_VERSION=v2.0.0-alpha.40
2323
echo "TOIT_VERSION=$TOIT_VERSION" >> $GITHUB_ENV
2424
export DOWNLOAD_DIR="${{ github.workspace }}/downloads"
2525
echo "DOWNLOAD_DIR=$DOWNLOAD_DIR" >> $GITHUB_ENV

src/directory.toit

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ realpath path:
135135
// Relative paths must be prepended with the current directory, and we can't
136136
// let the C realpath routine do that for us, because it doesn't understand
137137
// what our current directory is.
138-
if not path.starts_with "/": path = "$cwd/$path"
138+
if platform == PLATFORM_WINDOWS:
139+
if not path.starts_with "\\" or path.size <= 2 or path[1..2] != ":\\":
140+
path = "$cwd\\$path"
141+
else:
142+
if not path.starts_with "/": path = "$cwd/$path"
139143
#primitive.file.realpath
140144

141145
// Get the current working directory. Like the 'pwd' command, this works by

src/pipe.toit

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,10 @@ If the program run by the shell dies with a signal then the exit value is 128 +
326326
the signal number.
327327
*/
328328
system command -> int?:
329-
return run_program ["/bin/sh", "-c", command]
329+
if platform == PLATFORM_WINDOWS:
330+
return run_program ["cmd", "/s", "/c", command]
331+
else:
332+
return run_program ["/bin/sh", "-c", command]
330333

331334
run_program command arg1 -> int?:
332335
return run_program [command, arg1]

tests/fail.cmake

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,3 @@
1616
set(FAILING_TESTS
1717
)
1818

19-
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "MSYS")
20-
list(APPEND FAILING_TESTS
21-
${TEST_PREFIX}/tests/file_test.toit
22-
${TEST_PREFIX}/tests/pipe_test.toit
23-
${TEST_PREFIX}/tests/pipe2_test.toit
24-
${TEST_PREFIX}/tests/fork_stress_test_slow.toit
25-
)
26-
endif()
27-

tests/file_test.toit

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ main:
3232
expect_file_not_found: file.Stream "mkfxz.not_there" file.RDONLY
3333
expect_invalid_argument: file.Stream "any name" file.CREAT // Can't create a file without permissions.
3434
35-
open_file := file.Stream.for_read "/dev/null"
35+
nul_device := (platform == PLATFORM_WINDOWS ? "\\\\.\\NUL" : "/dev/null")
36+
open_file := file.Stream.for_read nul_device
3637
byte_array := open_file.read
3738
expect (not byte_array)
3839
open_file.close
3940
expect_already_closed: open_file.close
4041

41-
open_file = file.Stream "/dev/null" file.RDONLY
42+
open_file = file.Stream nul_device file.RDONLY
4243
byte_array = open_file.read
4344
expect (not byte_array)
4445
open_file.close
@@ -69,7 +70,7 @@ main:
6970
test_out.write test_contents
7071
test_out.close
7172

72-
for i := 0; i < 10000; i++:
73+
10000.repeat:
7374
file.read_content filename
7475

7576
read_back := (file.read_content filename).to_string
@@ -120,28 +121,31 @@ main:
120121

121122
expect (not file.size filename)
122123

123-
try:
124-
file.write_content test_contents --path=filename --permissions=(6 << 6)
125-
read_back := (file.read_content filename).to_string
126-
expect_equals test_contents read_back
127-
stats := file.stat filename
128-
// We can't require that the permissions are exactly the same (as the umask
129-
// might clear some bits).
130-
expect_equals (6 << 6) ((6 << 6) | stats[file.ST_MODE])
131-
finally:
132-
file.delete filename
124+
// Permissions does not quite work on windows
125+
if platform != PLATFORM_WINDOWS:
126+
try:
127+
file.write_content test_contents --path=filename --permissions=(6 << 6)
128+
read_back := (file.read_content filename).to_string
129+
expect_equals test_contents read_back
130+
stats := file.stat filename
131+
// We can't require that the permissions are exactly the same (as the umask
132+
// might clear some bits).
133+
expect_equals (6 << 6) ((6 << 6) | stats[file.ST_MODE])
134+
finally:
135+
file.delete filename
133136

134137
expect (not file.size filename)
135138

136139
cwd_path := cwd
137140

138-
chdir dirname
141+
path_sep := platform == PLATFORM_WINDOWS ? "\\" : "/"
139142

140-
expect_equals "$cwd_path/$dirname" cwd
143+
chdir dirname
144+
expect_equals "$cwd_path$path_sep$dirname" cwd
141145

142-
expect_equals "$cwd_path/$dirname" (realpath ".")
146+
expect_equals "$cwd_path$path_sep$dirname" (realpath ".")
143147
expect_equals "$cwd_path" (realpath "..")
144-
expect_equals "$cwd_path/$dirname" (realpath "../$dirname")
148+
expect_equals "$cwd_path$path_sep$dirname" (realpath "../$dirname")
145149
expect_equals "$cwd_path" (realpath "../$dirname/..")
146150
expect_equals null (realpath "fætter");
147151

tests/fork_stress_test_slow.toit

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import host.pipe
66
import reader show BufferedReader
77
import monitor
88
import expect show *
9+
import writer show Writer
910

1011
class Stress:
1112
executable ::= ?
@@ -29,11 +30,12 @@ class Stress:
2930
pipe.dont_wait_for pid
3031
channel.send "$id: forked"
3132

33+
pipe_writer := Writer to
3234
// Stress pipes.
3335
LINES_COUNT ::= 500
3436
for i := 0; i < LINES_COUNT; i++:
35-
to.write "line$i\n"
36-
to.close
37+
pipe_writer.write "line$i\n"
38+
pipe_writer.close
3739

3840
reader := BufferedReader from
3941
read_counter := 0
@@ -51,7 +53,7 @@ class Stress:
5153
logs := []
5254

5355
main:
54-
stress := Stress "/bin/cat"
56+
stress := Stress "cat"
5557

5658
now_us := Time.monotonic_us
5759
counter := 0

tests/pipe2_test.toit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ test_exit_signal sleep_time/int:
3737
pipe.PIPE_CREATED // stdin
3838
pipe.PIPE_CREATED // stdiout
3939
pipe.PIPE_CREATED // stderr
40-
"/bin/cat"
41-
["/bin/cat"]
40+
"cat"
41+
["cat"]
4242

4343
pid := pipes[3]
4444

tests/pipe_test.toit renamed to tests/pipe_test_slow.toit

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,42 @@ expect_error name [code]:
1515

1616
expect_file_not_found cmd [code]:
1717
if (cmd.index_of " ") == -1:
18-
expect_error "Error trying to run '$cmd' using \$PATH: No such file or directory" code
18+
if platform == PLATFORM_WINDOWS:
19+
expect_error "Error trying to run '$cmd' using \$PATH: FILE_NOT_FOUND" code
20+
else:
21+
expect_error "Error trying to run '$cmd' using \$PATH: No such file or directory" code
1922
else:
20-
expect_error "Error trying to run executable with a space in the filename: '$cmd': No such file or directory" code
23+
if platform == PLATFORM_WINDOWS:
24+
expect_error "Error trying to run executable with a space in the filename: '$cmd': FILE_NOT_FOUND" code
25+
else:
26+
expect_error "Error trying to run executable with a space in the filename: '$cmd': No such file or directory" code
27+
28+
if_windows windows unix:
29+
if platform == PLATFORM_WINDOWS: return windows
30+
return unix
2131

2232
main:
2333
// This test does not work on ESP32 since you can't launch subprocesses.
24-
if platform == "FreeRTOS": return
34+
if platform == PLATFORM_FREERTOS: return
2535

2636
print " ** Some child processes will print errors on stderr during **"
2737
print " ** this test. This is harmless and expected. **"
28-
2938
pipe_large_file
3039
write_closed_stdin_exception
3140

3241
expect_equals
3342
0
3443
pipe.system "true"
3544

45+
simple_ls_command := if_windows "dir %ComSpec%" "ls /bin/sh"
3646
expect_equals
3747
0
38-
pipe.system "ls /bin/sh"
48+
pipe.system
49+
simple_ls_command
3950

4051
// run_program does not parse the command line, splitting at spaces, so it's
4152
// looking for a single program of the name "ls /bin/sh".
42-
expect_file_not_found "ls /bin/sh": pipe.run_program "ls /bin/sh"
53+
expect_file_not_found simple_ls_command: pipe.run_program simple_ls_command
4354

4455
// There's no such program as ll.
4556
expect_file_not_found "ll": pipe.run_program "ll" "/bin/sh"
@@ -68,6 +79,7 @@ main:
6879
expect_file_not_found no_exist_cmd : pipe.to no_exist_cmd
6980

7081
tmpdir := mkdtemp "/tmp/toit_file_test_"
82+
old_current_directory := cwd
7183

7284
try:
7385
chdir tmpdir
@@ -88,12 +100,19 @@ main:
88100
chdir dirname
89101
go_up = true
90102

91-
p = pipe.from "shasum" filename
92103
output := ""
93-
while byte_array := p.read:
94-
output += byte_array.to_string
104+
if platform == PLATFORM_WINDOWS:
105+
p = pipe.from "certutil" "-hashfile" filename
106+
while byte_array := p.read:
107+
output += byte_array.to_string
108+
109+
expect output == "SHA1 hash of $filename:\r\n2dcc8e172c72f3d6937d49be7cf281067d257a62\r\nCertUtil: -hashfile command completed successfully.\r\n"
110+
else:
111+
p = pipe.from "shasum" filename
112+
while byte_array := p.read:
113+
output += byte_array.to_string
95114

96-
expect output == "2dcc8e172c72f3d6937d49be7cf281067d257a62 $filename\n"
115+
expect output == "2dcc8e172c72f3d6937d49be7cf281067d257a62 $filename\n"
97116

98117
chdir ".."
99118
go_up = false
@@ -107,15 +126,26 @@ main:
107126
finally:
108127
rmdir --recursive tmpdir
109128

110-
expect_error "shasum: exited with status 1":
111-
p := pipe.from "shasum" "file_that_doesn't exist"
112-
while p.read:
113-
// nothing
129+
chdir old_current_directory
130+
131+
if platform == PLATFORM_WINDOWS:
132+
expect_error "certutil: exited with status 2":
133+
p := pipe.from "certutil" "file_that_doesn't exist"
134+
while p.read:
135+
// Do nothing.
136+
137+
expect_error "certutil: exited with status 2":
138+
sum := pipe.backticks "certutil" "file_that_doesn't exist"
139+
else:
140+
expect_error "shasum: exited with status 1":
141+
p := pipe.from "shasum" "file_that_doesn't exist"
142+
while p.read:
143+
// Do nothing.
114144
115-
expect_error "shasum: exited with status 1":
116-
sum := pipe.backticks "shasum" "file_that_doesn't exist"
145+
expect_error "shasum: exited with status 1":
146+
sum := pipe.backticks "shasum" "file_that_doesn't exist"
117147

118-
tar_exit_code := (platform == "Linux") ? 2 : 1
148+
tar_exit_code := (platform == PLATFORM_LINUX) ? 2 : 1
119149
expect_error "tar: exited with status $tar_exit_code":
120150
p := pipe.to "tar" "-xvf" "-" "foo.txt"
121151
p.close // Close without sending a valid tar file.

0 commit comments

Comments
 (0)