PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/test/shell/test_command_processor.rb

http://github.com/ruby/ruby
Ruby | 69 lines | 56 code | 12 blank | 1 comment | 0 complexity | 44258bfa51d2e601a364a0389473b60f MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, AGPL-3.0
  1. # frozen_string_literal: false
  2. require 'shell'
  3. require 'tmpdir'
  4. class TestShell < Test::Unit::TestCase
  5. end
  6. class TestShell::CommandProcessor < Test::Unit::TestCase
  7. def setup
  8. @tmpdir = Dir.mktmpdir("test_shell")
  9. @shell = Shell.new
  10. @shell.system_path = [@tmpdir]
  11. end
  12. def teardown
  13. Dir.rmdir(@tmpdir)
  14. end
  15. def catch_command_start(tc = Object.new)
  16. @shell.process_controller.singleton_class.class_eval do
  17. define_method(:add_schedule) {|cmd| throw tc, cmd}
  18. end
  19. tc
  20. end
  21. def exeext
  22. RbConfig::CONFIG["EXECUTABLE_EXTS"][/\S+\z/]
  23. end
  24. def test_system_external
  25. name = "foo#{exeext}"
  26. path = File.join(@tmpdir, name)
  27. open(path, "w", 0755) {}
  28. cmd = assert_throw(catch_command_start) {@shell.system(name)}
  29. assert_equal(path, cmd.command)
  30. ensure
  31. File.unlink(path)
  32. end
  33. def test_system_not_found
  34. bug8918 = '[ruby-core:57235] [Bug #8918]'
  35. name = "foo"
  36. path = File.join(@tmpdir, name)
  37. open(path, "w", 0644) {}
  38. assert_raise(Shell::Error::CommandNotFound, bug8918) {
  39. catch(catch_command_start) {@shell.system(name)}
  40. }
  41. ensure
  42. Process.waitall
  43. File.unlink(path)
  44. end
  45. def test_system_directory
  46. bug8918 = '[ruby-core:57235] [Bug #8918]'
  47. name = "foo#{exeext}"
  48. path = File.join(@tmpdir, name)
  49. Dir.mkdir(path)
  50. assert_raise(Shell::Error::CommandNotFound, bug8918) {
  51. catch(catch_command_start) {@shell.system(name)}
  52. }
  53. ensure
  54. Process.waitall
  55. Dir.rmdir(path)
  56. end
  57. end