| 1 | module scheme |
| 2 | |
| 3 | import arena |
| 4 | import os |
| 5 | import rand |
| 6 | |
| 7 | // Frozen io32 review; requires the known io33 keyword-registry fix to execute |
| 8 | // Scheme literals/imports. No builds or test execution during authorship. |
| 9 | fn review_files_directory() string { |
| 10 | path := os.join_path(os.vtmp_dir(), 'vile-selected-independent-' + rand.ulid()) |
| 11 | os.mkdir_all(path) or { panic(err.msg()) } |
| 12 | return path |
| 13 | } |
| 14 | |
| 15 | fn review_files_text(mut vm VM, source string) string { |
| 16 | return write(vm.eval(source) or { panic('${source}: ${err.msg()}') }) or { panic(err.msg()) } |
| 17 | } |
| 18 | |
| 19 | fn review_files_put(mut vm VM, port Value, text string) ! { |
| 20 | vm.call(vm.lookup('put-string')!, [port, string_value(text)])! |
| 21 | } |
| 22 | |
| 23 | struct ReviewFilesMatrix { |
| 24 | options FilePortOptions |
| 25 | missing_ok bool |
| 26 | existing string |
| 27 | } |
| 28 | |
| 29 | fn test_review_files_explicit_option_matrix_preserves_rejected_targets_and_never_appends() { |
| 30 | root := review_files_directory() |
| 31 | defer { os.rmdir_all(root) or {} } |
| 32 | mut vm := new() |
| 33 | rows := [ |
| 34 | ReviewFilesMatrix{ options: FilePortOptions{}, missing_ok: true }, |
| 35 | ReviewFilesMatrix{ options: FilePortOptions{ no_create: true }, existing: 'Z' }, |
| 36 | ReviewFilesMatrix{ options: FilePortOptions{ no_fail: true }, missing_ok: true, existing: 'Z' }, |
| 37 | ReviewFilesMatrix{ options: FilePortOptions{ no_create: true, no_fail: true }, existing: 'Z' }, |
| 38 | ReviewFilesMatrix{ options: FilePortOptions{ no_truncate: true }, missing_ok: true }, |
| 39 | ReviewFilesMatrix{ options: FilePortOptions{ no_create: true, no_truncate: true }, existing: 'ZBCDE' }, |
| 40 | ReviewFilesMatrix{ options: FilePortOptions{ no_fail: true, no_truncate: true }, missing_ok: true, existing: 'ZBCDE' }, |
| 41 | ReviewFilesMatrix{ options: FilePortOptions{ no_create: true, no_fail: true, no_truncate: true }, existing: 'ZBCDE' }, |
| 42 | ] |
| 43 | for index, row in rows { |
| 44 | for existing in [false, true] { |
| 45 | path := os.join_path(root, '${index}-${existing}.bin') |
| 46 | if existing { os.write_file(path, 'ABCDE') or { panic(err.msg()) } } |
| 47 | allowed := if existing { row.existing != '' } else { row.missing_ok } |
| 48 | if output := vm.open_file_output_port(path, row.options) { |
| 49 | assert allowed, '${index}: ${existing}' |
| 50 | assert (vm.port_position(output) or { panic(err.msg()) }).whole() == 0 |
| 51 | vm.write_u8(output, `Z`) or { panic(err.msg()) } |
| 52 | vm.close_output_port(output) or { panic(err.msg()) } |
| 53 | assert os.read_file(path) or { panic(err.msg()) } == if existing { |
| 54 | row.existing |
| 55 | } else { |
| 56 | 'Z' |
| 57 | } |
| 58 | } else { |
| 59 | assert !allowed, '${index}: ${existing}: ${err.msg()}' |
| 60 | assert os.exists(path) == existing |
| 61 | if existing { |
| 62 | assert os.read_file(path) or { panic(err.msg()) } == 'ABCDE' |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | fn test_review_files_second_exclusive_open_cannot_truncate_first_open_descriptor_contents() { |
| 70 | root := review_files_directory() |
| 71 | defer { os.rmdir_all(root) or {} } |
| 72 | path := os.join_path(root, 'exclusive.bin') |
| 73 | mut vm := new() |
| 74 | first := vm.open_file_output_port(path, buffer_mode: .none) or { panic(err.msg()) } |
| 75 | vm.write_bytevector(first, bytevector('first'.bytes()), 0, 5) or { panic(err.msg()) } |
| 76 | if _ := vm.open_file_output_port(path) { |
| 77 | assert false |
| 78 | } |
| 79 | if _ := vm.open_file_output_port(path, no_truncate: true) { |
| 80 | assert false |
| 81 | } |
| 82 | assert os.read_file(path) or { panic(err.msg()) } == 'first' |
| 83 | assert (vm.port_position(first) or { panic(err.msg()) }).whole() == 5 |
| 84 | vm.write_u8(first, `!`) or { panic(err.msg()) } |
| 85 | vm.close_output_port(first) or { panic(err.msg()) } |
| 86 | assert os.read_file(path) or { panic(err.msg()) } == 'first!' |
| 87 | } |
| 88 | |
| 89 | fn test_review_files_invalid_host_options_validate_before_create_truncate_or_nul_prefix_open() { |
| 90 | root := review_files_directory() |
| 91 | defer { os.rmdir_all(root) or {} } |
| 92 | path := os.join_path(root, 'safe.bin') |
| 93 | mut vm := new() |
| 94 | for existing in [false, true] { |
| 95 | if existing { os.write_file(path, 'KEEP') or { panic(err.msg()) } } |
| 96 | for options in [ |
| 97 | FilePortOptions{ no_fail: true, buffer_mode: unsafe { PortBufferMode(255) } }, |
| 98 | FilePortOptions{ no_fail: true, transcoder: boolean(true) }, |
| 99 | FilePortOptions{ no_fail: true, transcoder: codec_value(.utf8) }, |
| 100 | FilePortOptions{ no_fail: true, transcoder: Value{ tag: .transcoder, bits: ValueBits{ whole: 128 } } }, |
| 101 | ] { |
| 102 | if _ := vm.open_file_output_port(path, options) { |
| 103 | assert false |
| 104 | } |
| 105 | if _ := vm.open_file_input_port(path, options) { |
| 106 | assert false |
| 107 | } |
| 108 | assert os.exists(path) == existing |
| 109 | if existing { |
| 110 | assert os.read_file(path) or { panic(err.msg()) } == 'KEEP' |
| 111 | } |
| 112 | } |
| 113 | if _ := vm.open_file_output_port(path + '\x00suffix', no_fail: true) { |
| 114 | assert false |
| 115 | } |
| 116 | if _ := vm.open_file_input_port(path + '\x00suffix') { |
| 117 | assert false |
| 118 | } |
| 119 | assert os.exists(path) == existing |
| 120 | if existing { |
| 121 | assert os.read_file(path) or { panic(err.msg()) } == 'KEEP' |
| 122 | } |
| 123 | } |
| 124 | mut uninitialized := VM{} |
| 125 | if _ := uninitialized.open_file_output_port(path, no_fail: true) { |
| 126 | assert false |
| 127 | } |
| 128 | assert os.read_file(path) or { panic(err.msg()) } == 'KEEP' |
| 129 | } |
| 130 | |
| 131 | fn test_review_files_invalid_scheme_optional_values_and_unknown_enum_universe_have_no_effect() { |
| 132 | root := review_files_directory() |
| 133 | defer { os.rmdir_all(root) or {} } |
| 134 | path := os.join_path(root, 'safe.bin') |
| 135 | mut vm := new() |
| 136 | vm.define('path', string_value(path)) or { panic(err.msg()) } |
| 137 | for existing in [false, true] { |
| 138 | if existing { os.write_file(path, 'KEEP') or { panic(err.msg()) } } |
| 139 | for source in [ |
| 140 | '(open-file-output-port path (file-options no-fail) (quote unknown))', |
| 141 | '(open-file-output-port path (file-options no-fail) (buffer-mode none) #t)', |
| 142 | '(open-file-output-port path (file-options no-fail) (buffer-mode none) (utf-16-codec))', |
| 143 | '(open-file-output-port path ((enum-set-constructor (make-enumeration (quote (no-fail unknown)))) (quote (no-fail))))', |
| 144 | '(open-file-input-port path ((enum-set-constructor (make-enumeration (quote (unknown)))) (quote ())))', |
| 145 | '(open-file-output-port path (file-options no-fail) (buffer-mode none) #f 0)', |
| 146 | ] { |
| 147 | if _ := vm.eval(source) { |
| 148 | assert false, source |
| 149 | } |
| 150 | assert os.exists(path) == existing |
| 151 | if existing { |
| 152 | assert os.read_file(path) or { panic(err.msg()) } == 'KEEP' |
| 153 | } |
| 154 | assert vm.active.len == 0 |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | fn test_review_files_input_ignores_creation_flags_and_none_mode_tracks_byte_positions() { |
| 160 | root := review_files_directory() |
| 161 | defer { os.rmdir_all(root) or {} } |
| 162 | path := os.join_path(root, 'input.bin') |
| 163 | os.write_file(path, 'Aλ😀') or { panic(err.msg()) } |
| 164 | mut vm := new() |
| 165 | input := vm.open_file_input_port(path, |
| 166 | no_create: true |
| 167 | no_fail: true |
| 168 | no_truncate: true |
| 169 | buffer_mode: .none |
| 170 | ) or { panic(err.msg()) } |
| 171 | assert (vm.peek_u8(input) or { panic(err.msg()) }).whole() == 65 |
| 172 | assert (vm.port_position(input) or { panic(err.msg()) }).whole() == 0 |
| 173 | assert (vm.read_u8(input) or { panic(err.msg()) }).whole() == 65 |
| 174 | assert (vm.port_position(input) or { panic(err.msg()) }).whole() == 1 |
| 175 | vm.set_port_position(input, integer(3)) or { panic(err.msg()) } |
| 176 | assert (vm.read_u8(input) or { panic(err.msg()) }).whole() == 0xf0 |
| 177 | vm.set_port_position(input, integer(0)) or { panic(err.msg()) } |
| 178 | assert (vm.read_u8(input) or { panic(err.msg()) }).whole() == 65 |
| 179 | vm.close_input_port(input) or { panic(err.msg()) } |
| 180 | assert os.read_file(path) or { panic(err.msg()) } == 'Aλ😀' |
| 181 | missing := os.join_path(root, 'missing.bin') |
| 182 | if _ := vm.open_file_input_port(missing, no_fail: true, no_truncate: true) { |
| 183 | assert false |
| 184 | } |
| 185 | assert !os.exists(missing) |
| 186 | } |
| 187 | |
| 188 | fn test_review_files_buffered_output_position_seek_flush_and_idempotent_descriptor_close() { |
| 189 | root := review_files_directory() |
| 190 | defer { os.rmdir_all(root) or {} } |
| 191 | path := os.join_path(root, 'position.bin') |
| 192 | os.write_file(path, 'ABCDE') or { panic(err.msg()) } |
| 193 | mut vm := new() |
| 194 | output := vm.open_file_output_port(path, no_create: true, no_truncate: true) or { panic(err.msg()) } |
| 195 | stream := output.output_pointer().stream |
| 196 | assert stream.descriptor_only && stream.file.is_opened |
| 197 | vm.write_u8(output, `Z`) or { panic(err.msg()) } |
| 198 | assert (vm.port_position(output) or { panic(err.msg()) }).whole() == 1 |
| 199 | assert os.read_file(path) or { panic(err.msg()) } == 'ABCDE' |
| 200 | vm.set_port_position(output, integer(3)) or { panic(err.msg()) } |
| 201 | assert os.read_file(path) or { panic(err.msg()) } == 'ZBCDE' |
| 202 | vm.write_u8(output, `!`) or { panic(err.msg()) } |
| 203 | vm.close_output_port(output) or { panic(err.msg()) } |
| 204 | assert !stream.file.is_opened |
| 205 | assert os.read_file(path) or { panic(err.msg()) } == 'ZBC!E' |
| 206 | next_path := os.join_path(root, 'next.bin') |
| 207 | next := vm.open_file_output_port(next_path, buffer_mode: .none) or { panic(err.msg()) } |
| 208 | vm.close_output_port(output) or { panic(err.msg()) } |
| 209 | stream.close() or { panic(err.msg()) } |
| 210 | vm.write_u8(next, 42) or { panic(err.msg()) } |
| 211 | vm.close_output_port(next) or { panic(err.msg()) } |
| 212 | assert os.read_bytes(next_path) or { panic(err.msg()) } == [u8(42)] |
| 213 | } |
| 214 | |
| 215 | fn test_review_files_transcoded_line_buffering_uses_source_lf_not_encoded_byte_0a() { |
| 216 | root := review_files_directory() |
| 217 | defer { os.rmdir_all(root) or {} } |
| 218 | path := os.join_path(root, 'line.bin') |
| 219 | mut vm := new() |
| 220 | output := vm.open_file_output_port(path, |
| 221 | buffer_mode: .line |
| 222 | transcoder: transcoder_value(.utf16, .cr, .raise) |
| 223 | ) or { panic(err.msg()) } |
| 224 | review_files_put(mut vm, output, '\u010a') or { panic(err.msg()) } |
| 225 | assert os.read_bytes(path) or { panic(err.msg()) } == []u8{} |
| 226 | review_files_put(mut vm, output, '\n') or { panic(err.msg()) } |
| 227 | assert os.read_bytes(path) or { panic(err.msg()) } == [u8(1), 10, 0, 13] |
| 228 | assert file_output_buffer_mode(mut vm, [output]) or { panic(err.msg()) }.text() == 'line' |
| 229 | vm.close_output_port(output) or { panic(err.msg()) } |
| 230 | assert file_output_buffer_mode(mut vm, [output]) or { panic(err.msg()) }.text() == 'line' |
| 231 | } |
| 232 | |
| 233 | @[heap] |
| 234 | struct ReviewFilesLineSink { |
| 235 | mut: |
| 236 | bytes []u8 |
| 237 | writes int |
| 238 | flushes int |
| 239 | chunk int = 4096 |
| 240 | write_fail_at int = -1 |
| 241 | flush_fail_at int = -1 |
| 242 | } |
| 243 | |
| 244 | fn (mut sink ReviewFilesLineSink) write(bytes []u8) !int { |
| 245 | sink.writes++ |
| 246 | if sink.writes == sink.write_fail_at { return failure('deliberate write failure') } |
| 247 | count := if bytes.len < sink.chunk { bytes.len } else { sink.chunk } |
| 248 | for index in 0 .. count { sink.bytes << bytes[index] } |
| 249 | return count |
| 250 | } |
| 251 | |
| 252 | fn (mut sink ReviewFilesLineSink) flush() ! { |
| 253 | sink.flushes++ |
| 254 | if sink.flushes == sink.flush_fail_at { return failure('deliberate flush failure') } |
| 255 | } |
| 256 | |
| 257 | fn review_files_attached_line(mut vm VM, sink &ReviewFilesLineSink, codec CodecKind, eol EolStyle) Value { |
| 258 | binary := vm.output_port(sink, binary: true) or { panic(err.msg()) } |
| 259 | // This is the same mode carried by selected file constructors. A host sink |
| 260 | // makes acknowledgment/flush boundaries deterministic without a blocking pipe. |
| 261 | binary.output_pointer().buffer_mode = .line |
| 262 | return vm.transcoded_port(binary, transcoder_value(codec, eol, .raise)) or { panic(err.msg()) } |
| 263 | } |
| 264 | |
| 265 | fn test_review_files_line_flush_error_after_short_write_ack_does_not_replay_encoded_batch() { |
| 266 | mut vm := new() |
| 267 | mut sink := &ReviewFilesLineSink{ chunk: 1, flush_fail_at: 1 } |
| 268 | output := review_files_attached_line(mut vm, sink, .utf16, .cr) |
| 269 | mut failed := false |
| 270 | review_files_put(mut vm, output, 'Ω\n') or { failed = true } |
| 271 | assert failed && sink.bytes == [u8(3), 0xa9, 0, 13] |
| 272 | assert !output.output_pointer().busy |
| 273 | vm.flush_output_port(output) or { panic(err.msg()) } |
| 274 | assert sink.bytes == [u8(3), 0xa9, 0, 13] |
| 275 | review_files_put(mut vm, output, 'B') or { panic(err.msg()) } |
| 276 | vm.close_output_port(output) or { panic(err.msg()) } |
| 277 | assert sink.bytes == [u8(3), 0xa9, 0, 13, 0, 66] |
| 278 | } |
| 279 | |
| 280 | fn test_review_files_short_write_error_then_flush_error_retries_only_unaccepted_suffix() { |
| 281 | mut vm := new() |
| 282 | mut sink := &ReviewFilesLineSink{ chunk: 1, write_fail_at: 2, flush_fail_at: 1 } |
| 283 | output := review_files_attached_line(mut vm, sink, .utf8, .lf) |
| 284 | mut failed := false |
| 285 | review_files_put(mut vm, output, '😀') or { failed = true } |
| 286 | assert failed && sink.bytes == [u8(0xf0)] |
| 287 | failed = false |
| 288 | vm.flush_output_port(output) or { failed = true } |
| 289 | assert failed && sink.bytes == [u8(0xf0), 0x9f, 0x98, 0x80] |
| 290 | vm.flush_output_port(output) or { panic(err.msg()) } |
| 291 | assert sink.bytes == [u8(0xf0), 0x9f, 0x98, 0x80] |
| 292 | review_files_put(mut vm, output, '\n') or { panic(err.msg()) } |
| 293 | assert sink.bytes == [u8(0xf0), 0x9f, 0x98, 0x80, 10] |
| 294 | vm.close_output_port(output) or { panic(err.msg()) } |
| 295 | } |
| 296 | |
| 297 | fn test_review_files_encoder_error_flushes_prior_converted_line_without_replaying_after_flush_error() { |
| 298 | mut vm := new() |
| 299 | mut sink := &ReviewFilesLineSink{ chunk: 1, flush_fail_at: 1 } |
| 300 | output := review_files_attached_line(mut vm, sink, .latin1, .crnel) |
| 301 | mut failed := false |
| 302 | review_files_put(mut vm, output, 'A\nλZ') or { failed = true } |
| 303 | assert failed && sink.bytes == [u8(65), 13, 0x85] |
| 304 | assert sink.flushes == 1 && !output.output_pointer().busy |
| 305 | vm.flush_output_port(output) or { panic(err.msg()) } |
| 306 | assert sink.bytes == [u8(65), 13, 0x85] |
| 307 | review_files_put(mut vm, output, 'B') or { panic(err.msg()) } |
| 308 | vm.close_output_port(output) or { panic(err.msg()) } |
| 309 | assert sink.bytes == [u8(65), 13, 0x85, 66] |
| 310 | } |
| 311 | |
| 312 | fn test_review_files_binary_line_mode_flush_failure_does_not_resend_accepted_bytes() { |
| 313 | mut vm := new() |
| 314 | mut sink := &ReviewFilesLineSink{ chunk: 1, flush_fail_at: 1 } |
| 315 | output := vm.output_port(sink, binary: true) or { panic(err.msg()) } |
| 316 | output.output_pointer().buffer_mode = .line |
| 317 | mut failed := false |
| 318 | vm.write_bytevector(output, bytevector('A\nB'.bytes()), 0, 3) or { failed = true } |
| 319 | assert failed && sink.bytes == 'A\nB'.bytes() |
| 320 | vm.flush_output_port(output) or { panic(err.msg()) } |
| 321 | vm.write_u8(output, `C`) or { panic(err.msg()) } |
| 322 | assert sink.bytes == 'A\nBC'.bytes() |
| 323 | vm.close_output_port(output) or { panic(err.msg()) } |
| 324 | } |
| 325 | |
| 326 | fn test_review_files_owned_descriptor_is_released_after_failed_close_flush_with_or_without_transcoder() { |
| 327 | $if linux { |
| 328 | if !os.exists('/dev/full') { return } |
| 329 | mut vm := new() |
| 330 | for attached in [false, true] { |
| 331 | binary := vm.open_file_output_port('/dev/full', |
| 332 | no_fail: true |
| 333 | no_truncate: true |
| 334 | ) or { panic(err.msg()) } |
| 335 | fd := binary.output_pointer().stream.file.fd |
| 336 | output := if attached { |
| 337 | vm.transcoded_port(binary, transcoder_value(.utf16, .cr, .raise)) or { panic(err.msg()) } |
| 338 | } else { |
| 339 | binary |
| 340 | } |
| 341 | if attached { |
| 342 | review_files_put(mut vm, output, 'A') or { panic(err.msg()) } |
| 343 | } else { |
| 344 | vm.write_u8(output, 65) or { panic(err.msg()) } |
| 345 | } |
| 346 | mut failed := false |
| 347 | vm.close_output_port(output) or { failed = true } |
| 348 | assert failed && output.output_pointer().closed && !output.output_pointer().busy |
| 349 | if _ := file_write_bytes(fd, [u8(0)]) { |
| 350 | assert false |
| 351 | } else { |
| 352 | assert err.code() == 9, err.msg() // Linux EBADF, not ENOSPC. |
| 353 | } |
| 354 | vm.close_output_port(output) or { panic(err.msg()) } |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | fn test_review_files_imported_hygienic_literals_compatible_enum_sets_and_shadowing() { |
| 360 | root := review_files_directory() |
| 361 | defer { os.rmdir_all(root) or {} } |
| 362 | path := os.join_path(root, 'alias.bin') |
| 363 | os.write_file(path, 'ABCDE') or { panic(err.msg()) } |
| 364 | mut vm := new() |
| 365 | vm.define('path', string_value(path)) or { panic(err.msg()) } |
| 366 | open := vm.lookup('open-file-output-port') or { panic(err.msg()) } |
| 367 | vm.define('open-file-output-port', integer(0)) or { panic(err.msg()) } |
| 368 | assert review_files_text(mut vm, ' |
| 369 | (import (prefix (only (rnrs io ports) open-file-output-port file-options buffer-mode output-port-buffer-mode) f:)) |
| 370 | (define-syntax safe-output |
| 371 | (syntax-rules () ((_ where) |
| 372 | (f:open-file-output-port where (f:file-options no-create no-truncate) (f:buffer-mode none))))) |
| 373 | (define p (let ((no-create 0) (no-truncate 1) (none 2) |
| 374 | (file-options #f) (buffer-mode #f)) (safe-output path))) |
| 375 | (put-u8 p 90) (close-port p) |
| 376 | (list (f:output-port-buffer-mode p) |
| 377 | (let ((f:file-options (lambda (n) (+ n 1)))) (f:file-options 41)))') == '(none 42)' |
| 378 | assert eqv(open, vm.lookup('f:open-file-output-port') or { panic(err.msg()) }) |
| 379 | assert os.read_file(path) or { panic(err.msg()) } == 'ZBCDE' |
| 380 | assert review_files_text(mut vm, " |
| 381 | (define opts ((enum-set-constructor (make-enumeration '(no-truncate no-fail))) '(no-truncate no-fail))) |
| 382 | (define q (f:open-file-output-port path opts (f:buffer-mode none))) |
| 383 | (put-u8 q 81) (close-port q) |
| 384 | (enum-set->list (f:file-options no-fail no-fail no-truncate))") == '(no-fail no-truncate)' |
| 385 | assert os.read_file(path) or { panic(err.msg()) } == 'QBCDE' |
| 386 | } |
| 387 | |
| 388 | fn test_review_files_cold_literal_results_survive_borrowed_arena_free_and_remain_valid_options() { |
| 389 | root := review_files_directory() |
| 390 | defer { os.rmdir_all(root) or {} } |
| 391 | path := os.join_path(root, 'cold.bin') |
| 392 | os.write_file(path, 'ABCDE') or { panic(err.msg()) } |
| 393 | mut vm := new() |
| 394 | mut exported_options := unspecified() |
| 395 | mut exported_mode := unspecified() |
| 396 | mut region := arena.new(chunk_size: 1048576) |
| 397 | region.push() |
| 398 | exported_options = vm.eval('(file-options no-create no-truncate)') or { panic(err.msg()) } |
| 399 | exported_mode = vm.eval('(buffer-mode none)') or { panic(err.msg()) } |
| 400 | assert !region.owns(exported_options.enumeration_pointer()) |
| 401 | region.pop() |
| 402 | region.free() |
| 403 | gc_collect() |
| 404 | vm.define('saved-options', exported_options) or { panic(err.msg()) } |
| 405 | vm.define('saved-mode', exported_mode) or { panic(err.msg()) } |
| 406 | vm.define('path', string_value(path)) or { panic(err.msg()) } |
| 407 | assert review_files_text(mut vm, ' |
| 408 | (define p (open-file-output-port path saved-options saved-mode)) |
| 409 | (put-u8 p 90) (close-port p) |
| 410 | (list (enum-set->list saved-options) saved-mode)') == '((no-create no-truncate) none)' |
| 411 | assert os.read_file(path) or { panic(err.msg()) } == 'ZBCDE' |
| 412 | } |
| 413 | |
| 414 | fn test_review_files_buffer_mode_queries_validate_owner_and_preserve_closed_metadata() { |
| 415 | mut vm := new() |
| 416 | mut foreign := new() |
| 417 | output := vm.open_output_string() or { panic(err.msg()) } |
| 418 | query := vm.lookup('output-port-buffer-mode') or { panic(err.msg()) } |
| 419 | assert (vm.call(query, [output]) or { panic(err.msg()) }).text() == 'none' |
| 420 | vm.close_output_port(output) or { panic(err.msg()) } |
| 421 | assert (vm.call(query, [output]) or { panic(err.msg()) }).text() == 'none' |
| 422 | if _ := foreign.call(foreign.lookup('output-port-buffer-mode') or { panic(err.msg()) }, [output]) { |
| 423 | assert false |
| 424 | } |
| 425 | if _ := vm.call(query, []) { |
| 426 | assert false |
| 427 | } |
| 428 | if _ := vm.call(query, [integer(0)]) { |
| 429 | assert false |
| 430 | } |
| 431 | input := vm.open_input_string('') or { panic(err.msg()) } |
| 432 | if _ := vm.call(query, [input]) { |
| 433 | assert false |
| 434 | } |
| 435 | vm.close_input_port(input) or { panic(err.msg()) } |
| 436 | assert review_files_text(mut vm, '(list (buffer-mode? (quote none)) (buffer-mode? (quote bogus)) (buffer-mode? 0))') == '(#t #f #f)' |
| 437 | } |
| 438 | |