Top Level Namespace
Defined Under Namespace
Modules: EmacsLisp, Enumerable, IfTest, Math, Test, URLConv, Untar, W3MUtils Classes: Array, AssertFile, ConfigScript, Dir, File, FileContents, GenericContents, IO, Matrix, MylibCommand, Numeric, Object, Proc, RunConfig, ScriptBug, String, StructWithType, Tempfile, Time, URIContents, UnTable, Vector
Constant Summary collapse
- @@__system_to_string_count__ =
0
Instance Method Summary collapse
-
#_getopts_sub(argv, single_opts, *long_opts) ⇒ Object
getopts.
-
#bug!(message = 'must not happen') ⇒ Object
Raises ScriptBug exception.
- #exec_el4r(test_mode = true) ⇒ Object
-
#getopts(single_opts, *long_opts) ⇒ Object
getopts compatibility layer using optparse.rb.
-
#notify_exit ⇒ Object
notify_exit.
-
#show_usage(msg = nil) ⇒ Object
show_usage Prints the script’s first comment block.
-
#system_safe(*x) ⇒ Object
system_safe mswin32 ruby’s ‘system’ workaround.
- #system_to_string(*args) ⇒ Object
-
#vrequire(f) ⇒ Object
vrequire verbose require.
-
#vsystem(cmd) ⇒ Object
vsystem verbose system.
-
#with_temp_dir(dir = Dir.tmpdir+"/tmp_#{$$}") ⇒ Object
Makes a temporary directory and executes a block and cleans the directory.
Instance Method Details
#_getopts_sub(argv, single_opts, *long_opts) ⇒ Object
getopts
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/el4r/el4r-sub.rb', line 190 def _getopts_sub(argv, single_opts, *long_opts) require 'optparse' opt = OptionParser.new (single_opts || "").split(//).each do |single_opt| opt.on("-#{single_opt}"){ eval "$OPT_#{single_opt}=true" } end long_opts.each do |long_opt| have_arg_p = (long_opt[-1,1] == ':') long_opt.chomp!(':') block = lambda{|x| eval "$OPT_#{long_opt}=x"} if have_arg_p if long_opt.length == 1 # -x arg opt.on("-#{long_opt} [ARG]",&block) else # --long arg opt.on("--#{long_opt}=[ARG]",&block) end else # --long opt.on("--#{long_opt}"){ eval "$OPT_#{long_opt}=true"} end end opt.parse! argv end |
#bug!(message = 'must not happen') ⇒ Object
Raises ScriptBug exception.
772 773 774 |
# File 'lib/el4r/el4r-sub.rb', line 772 def bug!( = 'must not happen' ) raise ScriptBug, "\n[SCRIPT BUG] " + end |
#exec_el4r(test_mode = true) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/el4r/exec-el4r.rb', line 23 def exec_el4r(test_mode=true) el4r_root = nil shellargs = [] emacs = nil ruby = nil unittest_args = [] strip_instance_error = "t" load_path = [] show_only = false init = false ARGV. do |o| o.on("-Q", "--init", "load site-start.el and .emacs") { init = true } o.on("-b", "--batch", "batch mode"){ shellargs << "-batch" } o.on("-i", "interactive mode") { shellargs.delete "-batch"} o.on("-e EMACS", "--emacs=EMACS", "set emacs binary [default: #{emacs}]") {|v| emacs = v } o.on("--ruby=RUBY", "set ruby binary [default: #{ruby}]") {|v| ruby = v } o.on("-I load-path", "set load-path") {|v| load_path << v} o.on("-r DIR", "--el4r-root=DIR", "el4r package root directory [for debug]") {|v| ENV['EL4R_ROOT'] = el4r_root = File.(v) } if test_mode o.on("-n NAME", "--name=NAME", "Runs tests matching NAME.", "(patterns may be used).") {|v| unittest_args << "-n" << v} o.on("-t TESTCASE", "--testcase=TESTCASE", "Runs tests in TestCases matching TESTCASE.", "(patterns may be used).") {|v| unittest_args << "-t" << v} o.on("-v", "verbose output"){|v| unittest_args << "-v"} end o.on("--nw", "don't communicate with X, ignoring $DISPLAY", "(emacs -nw)"){|v| shellargs << "--nw"} o.on("-d", "--debug", "debug output"){ strip_instance_error = "nil" } o.on("-l LOGFILE", "--log=LOGFILE", "Specify a log file.") {|v| ENV['EL4R_LOG']=File.(v); ENV['EL4R_PRESERVE_LOG']='1' } o.on("--show", "Show the test information only, for diagnosis.") { show_only = true} o. += " file" o.parse! end load "~/.el4rrc.rb"; conf=__conf__ emacs ||= conf.emacs_program ruby ||= conf.ruby_program basearg = if init [] else if emacs =~ /xemacs/ ["-no-site-file", "-no-init-file"] else ["--no-site-file", "--no-init-file"] end end if el4r_root el4r_el = File.join(el4r_root, conf.el_program_relative) el4r_instance = File.join(el4r_root, conf.instance_program_relative) else el4r_el = conf.el_program el4r_instance = conf.instance_program end unittest_source = ARGV.first # TODO: multiple sources raise "no such file or directory: #{unittest_source}" unless File.exist? unittest_source unittest_args_lisp = "'(" + unittest_args.compact.map{|x| x.dump}.join(" ") + ")" load_path_lisp = "(setq load-path (append '(" + load_path.map{|x| x.dump}.join(" ") + ") load-path))" lisp = format(<<'EOF', el4r_el, ruby, el4r_instance, unittest_source, unittest_args_lisp, strip_instance_error, load_path_lisp) (when noninteractive (defun message (&rest args))) (defun instantly-kill-emacs () (interactive) (kill-emacs 0)) (setq help-msg "q, M-k:quit / C-c: run-test / l, C-l: show-log / SPC,b: scroll") (defun unittest () (interactive) (el4r-run-unittest) (or noninteractive (message help-msg))) (define-key global-map "\C-x\C-c" 'instantly-kill-emacs) (define-derived-mode unittest-mode fundamental-mode "UnitTest" "" (define-key unittest-mode-map "\M-k" 'instantly-kill-emacs) (define-key unittest-mode-map "q" 'instantly-kill-emacs) (define-key unittest-mode-map "\C-c" 'unittest) (define-key unittest-mode-map "\C-l" 'el4r-show-log) (define-key unittest-mode-map "l" 'el4r-show-log) (define-key unittest-mode-map "\M-d" 'edebug-defun) (define-key unittest-mode-map " " 'scroll-up) (define-key unittest-mode-map "b" 'scroll-down) ) (fset 'yes-or-no-p 'y-or-n-p) ;(setq debug-on-error t) ;(setq debug-on-signal t) (setq debug-on-quit t) (setq pop-up-windows nil) (load "%s") (defun el4r-override-variables () (setq el4r-ruby-program "%s") (setq el4r-instance-program "%s") (setq el4r-unittest-file-name "%s") (setq el4r-load-script el4r-unittest-file-name) (setq el4r-unittest-args %s) (setq el4r-coding-system 'euc-jp-unix) ) (defun el4r-load-script () (interactive) (el4r-load el4r-load-script)) (el4r-boot t) (setq el4r-unittest-strip-instance-error %s) (el4r-ruby-eval "self.el4r_is_debug = true") (set-buffer "*scratch*") %s EOF #' if show_only %w[ ruby emacs el4r_el el4r_instance shellargs basearg unittest_source unittest_args load_path ENV['EL4R_ROOT'] ].each do |varname| value = eval(varname).inspect puts "#{varname} = #{value}" end exit end begin el = File.join(Dir.tmpdir, "testrun.el") open(el,"w"){|w| w.write lisp} shellargs << "-l" << el if test_mode shellargs << "-f" << "unittest" else shellargs << "-f" << "el4r-load-script" end args = [emacs]+basearg+shellargs system *args ensure # File.unlink el end end |
#getopts(single_opts, *long_opts) ⇒ Object
getopts compatibility layer using optparse.rb
217 218 219 |
# File 'lib/el4r/el4r-sub.rb', line 217 def getopts(single_opts, *long_opts) _getopts_sub ARGV, single_opts, *long_opts end |
#notify_exit ⇒ Object
notify_exit
590 591 592 593 594 595 |
# File 'lib/el4r/el4r-sub.rb', line 590 def notify_exit # Notify when the program is exited. at_exit do "#$0 exited." end end |
#show_usage(msg = nil) ⇒ Object
show_usagePrints the script’s first comment block.
843 844 845 846 847 848 849 850 851 852 853 |
# File 'lib/el4r/el4r-sub.rb', line 843 def show_usage(msg=nil) name = caller[-1].sub(/:\d+$/, '') $stderr.puts "\nError: #{msg}" if msg $stderr.puts File.open(name) do |f| while line = f.readline and line.sub!(/^# ?/, '') $stderr.puts line end end exit 1 end |
#system_safe(*x) ⇒ Object
system_safemswin32 ruby’s ‘system’ workaround.
876 877 878 879 880 881 |
# File 'lib/el4r/el4r-sub.rb', line 876 def system_safe(*x) begin system *x rescue end end |
#system_to_string(*args) ⇒ Object
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 |
# File 'lib/el4r/el4r-sub.rb', line 538 def system_to_string(*args) begin tmpf = File.join(Dir.tmpdir, "#{$$}-#{@@__system_to_string_count__}") @@__system_to_string_count__ += 1 ret = nil open(tmpf,"w") do |f| IO.redirect(f) { system *args } end File.read(tmpf) ensure FileUtils.rm_f tmpf end end |
#vrequire(f) ⇒ Object
vrequireverbose require
55 56 57 58 59 |
# File 'lib/el4r/el4r-sub.rb', line 55 def vrequire(f) puts "loading " + f + "..." require f puts "loading " + f + "...done" end |
#vsystem(cmd) ⇒ Object
vsystemverbose system
63 64 65 66 |
# File 'lib/el4r/el4r-sub.rb', line 63 def vsystem(cmd) puts cmd system cmd end |
#with_temp_dir(dir = Dir.tmpdir+"/tmp_#{$$}") ⇒ Object
Makes a temporary directory and executes a block and cleans the directory.
468 469 470 471 472 473 474 475 476 477 |
# File 'lib/el4r/el4r-sub.rb', line 468 def with_temp_dir(dir=Dir.tmpdir+"/tmp_#{$$}") require 'fileutils' begin dir = Pathname.new(dir). dir.mkdir Dir.chdir(dir) { yield(dir) } ensure FileUtils.rm_rf(dir) end end |