yamatanooroti 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f7c72bc6c902dd8b5cdf5d02183954cba1180960c702e5642c208b074e2ccd5
4
- data.tar.gz: d5dfea77ef4a055e0e278fa7447d96e1c473ce7aa4108062c99e3fc1d3e3d499
3
+ metadata.gz: 92dcb67921820e4dedad1aed9de7d18c062f623c9b73c4a05427049111217f4a
4
+ data.tar.gz: 5683fb3c7544c67dc4c1f024df1b8fd9953c6378be0826a6f834191cf5c694e8
5
5
  SHA512:
6
- metadata.gz: d4242ac34c419417a1e8035968b26f4587d6d5c332852a73dad9d413b0b06447b1cd0969272b344bd3bc4a26fc4934e2a156cfc740d44fe53344f4d1f130048a
7
- data.tar.gz: 1f2679e02d8183d15c5ded5baa273d6ca1b4b299335145a4141066c3f315a0277623ca64caa1e0f5bdffe205280ce2b9b27cfe7b1f728c71e03f8293d7211b1c
6
+ metadata.gz: 6c614da80dcaf5b4ff0799be9be726fa0ea61fcc8ae1f53a4219e61cb17a86d3dee3e9e3fce5663b7224493b53ee0f379359859f448b10963306959647169c16
7
+ data.tar.gz: 0e2d1c4d031666509d85c5abc5a8d0f847d3c50392aec52df6f920269ebdff7fb99ac0442c1e582e8edd06f74f124dc9de559a5db8bc271510b331afbdc0f53b
@@ -1,3 +1,3 @@
1
1
  class Yamatanooroti
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -5,6 +5,7 @@ require 'pty'
5
5
  module Yamatanooroti::VTermTestCaseModule
6
6
  def start_terminal(height, width, command, wait: 0.1)
7
7
  @wait = wait
8
+ @result = nil
8
9
 
9
10
  @pty_output, @pty_input, @pid = PTY.spawn(*command)
10
11
 
@@ -27,6 +28,7 @@ module Yamatanooroti::VTermTestCaseModule
27
28
  sync
28
29
  @pty_input.close
29
30
  sync
31
+ Process.kill('KILL', @pid)
30
32
  end
31
33
 
32
34
  private def sync
@@ -45,17 +47,23 @@ module Yamatanooroti::VTermTestCaseModule
45
47
  end
46
48
  end
47
49
 
48
- def assert_screen(expected_lines)
49
- actual_lines = []
50
+ def result
51
+ return @result if @result
52
+ @result = []
50
53
  rows, cols = @vterm.size
51
54
  rows.times do |r|
52
- actual_lines << ''
55
+ @result << ''
53
56
  cols.times do |c|
54
57
  cell = @screen.cell_at(r, c)
55
- actual_lines.last << cell.char if cell.char
58
+ @result.last << cell.char if cell.char
56
59
  end
57
- actual_lines.last.gsub!(/ *$/, '')
60
+ @result.last.gsub!(/ *$/, '')
58
61
  end
62
+ @result
63
+ end
64
+
65
+ def assert_screen(expected_lines)
66
+ actual_lines = result
59
67
  case expected_lines
60
68
  when Array
61
69
  assert_equal(expected_lines, actual_lines)
@@ -0,0 +1,70 @@
1
+ require 'test-unit'
2
+ require 'vterm'
3
+ require 'pty'
4
+
5
+ module Yamatanooroti::VTermTestCaseModule
6
+ def start_terminal(height, width, command, wait: 0.1)
7
+ @wait = wait
8
+
9
+ @pty_output, @pty_input, @pid = PTY.spawn(*command)
10
+
11
+ @vterm = VTerm.new(height, width)
12
+ @vterm.set_utf8(true)
13
+
14
+ @screen = @vterm.screen
15
+ @screen.reset(true)
16
+
17
+ sync
18
+ end
19
+
20
+ def write(str)
21
+ sync
22
+ @pty_input.write(str)
23
+ sync
24
+ end
25
+
26
+ def close
27
+ sync
28
+ @pty_input.close
29
+ sync
30
+ end
31
+
32
+ private def sync
33
+ loop do
34
+ sleep @wait
35
+ chunk = @pty_output.read_nonblock(1024)
36
+ @vterm.write(chunk)
37
+ chunk = @vterm.read
38
+ @pty_input.write(chunk)
39
+ rescue Errno::EAGAIN, Errno::EWOULDBLOCK
40
+ break
41
+ rescue Errno::EIO # EOF
42
+ break
43
+ rescue IO::EAGAINWaitReadable # emtpy buffer
44
+ break
45
+ end
46
+ end
47
+
48
+ def assert_screen(expected_lines)
49
+ actual_lines = []
50
+ rows, cols = @vterm.size
51
+ rows.times do |r|
52
+ actual_lines << ''
53
+ cols.times do |c|
54
+ cell = @screen.cell_at(r, c)
55
+ actual_lines.last << cell.char if cell.char
56
+ end
57
+ actual_lines.last.gsub!(/ *$/, '')
58
+ end
59
+ case expected_lines
60
+ when Array
61
+ assert_equal(expected_lines, actual_lines)
62
+ when String
63
+ assert_equal(expected_lines, actual_lines.join("\n").sub(/\n*\z/, "\n"))
64
+ end
65
+ end
66
+ end
67
+
68
+ class Yamatanooroti::VTermTestCase < Test::Unit::TestCase
69
+ include Yamatanooroti::VTermTestCaseModule
70
+ end
@@ -212,10 +212,10 @@ module Yamatanooroti::WindowsTestCaseModule
212
212
 
213
213
  private def setup_console(height, width)
214
214
 
215
- result = DL.FreeConsole
216
- error_message(result, 'FreeConsole')
217
- result = DL.AllocConsole
218
- error_message(result, 'AllocConsole')
215
+ r = DL.FreeConsole
216
+ error_message(r, 'FreeConsole')
217
+ r = DL.AllocConsole
218
+ error_message(r, 'AllocConsole')
219
219
  @output_handle = DL.GetStdHandle(DL::STD_OUTPUT_HANDLE)
220
220
 
221
221
  =begin
@@ -228,8 +228,8 @@ module Yamatanooroti::WindowsTestCaseModule
228
228
  font.FontFamily = 0
229
229
  font.FontWeight = 0
230
230
  font.FaceName[0] = "\x00".ord
231
- result = DL.SetCurrentConsoleFontEx(@output_handle, 0, font)
232
- error_message(result, 'SetCurrentConsoleFontEx')
231
+ r = DL.SetCurrentConsoleFontEx(@output_handle, 0, font)
232
+ error_message(r, 'SetCurrentConsoleFontEx')
233
233
  =end
234
234
 
235
235
  rect = DL::SMALL_RECT.malloc
@@ -237,16 +237,16 @@ module Yamatanooroti::WindowsTestCaseModule
237
237
  rect.Top = 0
238
238
  rect.Right = width - 1
239
239
  rect.Bottom = height - 1
240
- result = DL.SetConsoleWindowInfo(@output_handle, 1, rect)
241
- error_message(result, 'SetConsoleWindowInfo')
240
+ r = DL.SetConsoleWindowInfo(@output_handle, 1, rect)
241
+ error_message(r, 'SetConsoleWindowInfo')
242
242
 
243
243
  size = DL.GetSystemMetrics(DL::SM_CYMIN) * 65536 + DL.GetSystemMetrics(DL::SM_CXMIN)
244
- result = DL.SetConsoleScreenBufferSize(@output_handle, size)
245
- error_message(result, 'SetConsoleScreenBufferSize')
244
+ r = DL.SetConsoleScreenBufferSize(@output_handle, size)
245
+ error_message(r, 'SetConsoleScreenBufferSize')
246
246
 
247
247
  size = height * 65536 + width
248
- result = DL.SetConsoleScreenBufferSize(@output_handle, size)
249
- error_message(result, 'SetConsoleScreenBufferSize')
248
+ r = DL.SetConsoleScreenBufferSize(@output_handle, size)
249
+ error_message(r, 'SetConsoleScreenBufferSize')
250
250
  end
251
251
 
252
252
  private def mb2wc(str)
@@ -289,19 +289,19 @@ module Yamatanooroti::WindowsTestCaseModule
289
289
  (@pi.to_ptr + 0)[0, DL::PROCESS_INFORMATION.size] = "\x00" * DL::PROCESS_INFORMATION.size
290
290
  @startup_info_ex = DL::STARTUPINFOW.malloc
291
291
  (@startup_info_ex.to_ptr + 0)[0, DL::STARTUPINFOW.size] = "\x00" * DL::STARTUPINFOW.size
292
- result = DL.CreateProcessW(
292
+ r = DL.CreateProcessW(
293
293
  Fiddle::NULL, converted_command,
294
294
  Fiddle::NULL, Fiddle::NULL, 0, 0, Fiddle::NULL, Fiddle::NULL,
295
295
  @startup_info_ex, @pi
296
296
  )
297
- error_message(result, 'CreateProcessW')
297
+ error_message(r, 'CreateProcessW')
298
298
  sleep @wait
299
299
  rescue => e
300
300
  pp e
301
301
  end
302
302
 
303
- private def error_message(result, method_name)
304
- return if not result.zero?
303
+ private def error_message(r, method_name)
304
+ return if not r.zero?
305
305
  err = DL.GetLastError
306
306
  string = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
307
307
  DL.FormatMessage(
@@ -349,8 +349,8 @@ module Yamatanooroti::WindowsTestCaseModule
349
349
  r.dwControlKeyState = 0
350
350
  end
351
351
  written_size = Fiddle::Pointer.malloc(Fiddle::SIZEOF_DWORD, DL::FREE)
352
- result = DL.WriteConsoleInputW(DL.GetStdHandle(DL::STD_INPUT_HANDLE), records, str.size * 2, written_size)
353
- error_message(result, 'WriteConsoleInput')
352
+ r = DL.WriteConsoleInputW(DL.GetStdHandle(DL::STD_INPUT_HANDLE), records, str.size * 2, written_size)
353
+ error_message(r, 'WriteConsoleInput')
354
354
  end
355
355
 
356
356
  private def free_resources
@@ -358,27 +358,28 @@ module Yamatanooroti::WindowsTestCaseModule
358
358
  pe = DL::PROCESSENTRY32W.malloc
359
359
  (pe.to_ptr + 0)[0, DL::PROCESSENTRY32W.size] = "\x00" * DL::PROCESSENTRY32W.size
360
360
  pe.dwSize = DL::PROCESSENTRY32W.size
361
- result = DL.Process32FirstW(h_snap, pe)
362
- error_message(result, "Process32First")
363
- result = DL.FreeConsole()
364
- #error_message(result, "FreeConsole")
365
- result = DL.AttachConsole(DL::ATTACH_PARENT_PROCESS)
366
- error_message(result, 'AttachConsole')
361
+ r = DL.Process32FirstW(h_snap, pe)
362
+ error_message(r, "Process32First")
367
363
  loop do
368
364
  #log "a #{pe.th32ParentProcessID.inspect} -> #{pe.th32ProcessID.inspect} #{wc2mb(pe.szExeFile.pack('S260')).unpack('Z*').pack('Z*')}"
369
365
  if pe.th32ParentProcessID == DL.GetCurrentProcessId
370
366
  h_child_proc = DL.OpenProcess(DL::PROCESS_ALL_ACCESS, 0, pe.th32ProcessID)
371
367
  if (h_child_proc)
372
- result = DL.TerminateProcess(h_child_proc, 0)
373
- error_message(result, "TerminateProcess")
374
- result = DL.CloseHandle(h_child_proc)
375
- error_message(result, "CloseHandle")
368
+ r = DL.TerminateProcess(h_child_proc, 0)
369
+ error_message(r, "TerminateProcess")
370
+ r = DL.CloseHandle(h_child_proc)
371
+ error_message(r, "CloseHandle")
376
372
  end
377
373
  end
378
374
  break if DL.Process32NextW(h_snap, pe).zero?
379
375
  end
380
- result = DL.TerminateThread(@pi.hThread, 0)
381
- error_message(result, "TerminateThread")
376
+ r = DL.TerminateThread(@pi.hThread, 0)
377
+ error_message(r, "TerminateThread")
378
+ sleep @wait
379
+ r = DL.FreeConsole()
380
+ #error_message(r, "FreeConsole")
381
+ r = DL.AttachConsole(DL::ATTACH_PARENT_PROCESS)
382
+ error_message(r, 'AttachConsole')
382
383
  end
383
384
 
384
385
  def close
@@ -390,8 +391,8 @@ module Yamatanooroti::WindowsTestCaseModule
390
391
  region.Top = 0
391
392
  region.Right = @width
392
393
  region.Bottom = @height
393
- result = DL.ReadConsoleOutputW(@output_handle, char_info_matrix, @height * 65536 + @width, 0, region)
394
- error_message(result, "ReadConsoleOutputW")
394
+ r = DL.ReadConsoleOutputW(@output_handle, char_info_matrix, @height * 65536 + @width, 0, region)
395
+ error_message(r, "ReadConsoleOutputW")
395
396
  @result = []
396
397
  prev_c = nil
397
398
  @height.times do |y|
@@ -413,6 +414,10 @@ module Yamatanooroti::WindowsTestCaseModule
413
414
  free_resources
414
415
  end
415
416
 
417
+ def result
418
+ @result
419
+ end
420
+
416
421
  def assert_screen(expected_lines)
417
422
  case expected_lines
418
423
  when Array
@@ -426,6 +431,7 @@ module Yamatanooroti::WindowsTestCaseModule
426
431
  @height = height
427
432
  @width = width
428
433
  @wait = wait
434
+ @result = nil
429
435
  setup_console(height, width)
430
436
  launch(command.join(' '))
431
437
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yamatanooroti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-21 00:00:00.000000000 Z
11
+ date: 2020-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: " Yamatanooroti is a multi-platform real(?) terminal test framework.\n"
42
56
  email:
43
57
  - aycabta@gmail.com
@@ -50,6 +64,7 @@ files:
50
64
  - lib/yamatanooroti.rb
51
65
  - lib/yamatanooroti/version.rb
52
66
  - lib/yamatanooroti/vterm.rb
67
+ - lib/yamatanooroti/vterm.rb.orig
53
68
  - lib/yamatanooroti/windows.rb
54
69
  homepage: https://github.com/aycabta/yamatanooroti
55
70
  licenses: