Permalink
Browse files

tests cleanup

  • Loading branch information...
1 parent 537fac5 commit fef5c419e30da78a7a0309f7841ea716fa1385fe @quix committed Aug 12, 2009
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,67 +0,0 @@
-
-class Jumpstart
- #
- # Lazily-evaluated attributes.
- #
- # An attr_lazy block is evaluated in the context of the instance
- # when the attribute is requested. The same result is then returned
- # for subsequent calls until the attribute is redefined with another
- # attr_lazy block.
- #
- module AttrLazy
- def attr_lazy(name, &block)
- AttrLazy.define_attribute(class << self ; self ; end, name, false, &block)
- end
-
- def attr_lazy_accessor(name, &block)
- AttrLazy.define_attribute(class << self ; self ; end, name, true, &block)
- end
-
- class << self
- def included(mod)
- (class << mod ; self ; end).class_eval do
- def attr_lazy(name, &block)
- AttrLazy.define_attribute(self, name, false, &block)
- end
-
- def attr_lazy_accessor(name, &block)
- AttrLazy.define_attribute(self, name, true, &block)
- end
- end
- end
-
- def define_attribute(klass, name, define_writer, &block)
- klass.class_eval do
- # Factoring this code is possible but convoluted, requiring
- # the definition of a temporary method.
-
- remove_method name rescue nil
- define_method name do
- value = instance_eval(&block)
- (class << self ; self ; end).class_eval do
- remove_method name rescue nil
- define_method name do
- value
- end
- end
- value
- end
-
- if define_writer
- writer = "#{name}="
- remove_method writer rescue nil
- define_method writer do |value|
- (class << self ; self ; end).class_eval do
- remove_method name rescue nil
- define_method name do
- value
- end
- end
- value
- end
- end
- end
- end
- end
- end
-end
View
@@ -1,44 +0,0 @@
-
-require 'rbconfig'
-
-class Jumpstart
- module Ruby
- EXECUTABLE = lambda {
- name = File.join(
- Config::CONFIG["bindir"],
- Config::CONFIG["RUBY_INSTALL_NAME"]
- )
-
- if Config::CONFIG["host"] =~ %r!(mswin|cygwin|mingw)! and
- File.basename(name) !~ %r!\.(exe|com|bat|cmd)\Z!i
- name + Config::CONFIG["EXEEXT"]
- else
- name
- end
- }.call
-
- class << self
- def run(*args)
- cmd = [EXECUTABLE, *args]
- unless system(*cmd)
- cmd_str = cmd.map { |t| "'#{t}'" }.join(", ")
- raise "system(#{cmd_str}) failed with status #{$?.exitstatus}"
- end
- end
-
- def with_warnings(value = true)
- previous = $VERBOSE
- $VERBOSE = value
- begin
- yield
- ensure
- $VERBOSE = previous
- end
- end
-
- def no_warnings(&block)
- with_warnings(nil, &block)
- end
- end
- end
-end
@@ -1,85 +0,0 @@
-
-require 'rbconfig'
-require 'fileutils'
-require 'find'
-
-class Jumpstart
- class SimpleInstaller
- def initialize
- dest_root = Config::CONFIG["sitelibdir"]
- sources = []
- Find.find("./lib") { |source|
- if install_file?(source)
- sources << source
- end
- }
- @spec = sources.inject(Array.new) { |acc, source|
- if source == "./lib"
- acc
- else
- dest = File.join(dest_root, source.sub(%r!\A\./lib!, ""))
-
- install = lambda {
- if File.directory?(source)
- unless File.directory?(dest)
- puts "mkdir #{dest}"
- FileUtils.mkdir(dest)
- end
- else
- puts "install #{source} --> #{dest}"
- FileUtils.install(source, dest)
- end
- }
-
- uninstall = lambda {
- if File.directory?(source)
- if File.directory?(dest)
- puts "rmdir #{dest}"
- FileUtils.rmdir(dest)
- end
- else
- if File.file?(dest)
- puts "rm #{dest}"
- FileUtils.rm(dest)
- end
- end
- }
-
- acc << {
- :source => source,
- :dest => dest,
- :install => install,
- :uninstall => uninstall,
- }
- end
- }
- end
-
- def install_file?(source)
- File.directory?(source) or
- (File.file?(source) and File.extname(source) == ".rb")
- end
-
- def install
- @spec.each { |entry|
- entry[:install].call
- }
- end
-
- def uninstall
- @spec.reverse.each { |entry|
- entry[:uninstall].call
- }
- end
-
- def run(args = ARGV)
- if args.empty?
- install
- elsif args.size == 1 and args.first == "--uninstall"
- uninstall
- else
- raise "unrecognized arguments: #{args.inspect}"
- end
- end
- end
-end
View
@@ -1,35 +0,0 @@
-
-class Jumpstart
- module Util
- module_function
-
- def run_ruby_on_each(*files)
- files.each { |file|
- Ruby.run("-w", file)
- }
- end
-
- def to_camel_case(str)
- str.split('_').map { |t| t.capitalize }.join
- end
-
- def write_file(file)
- contents = yield
- File.open(file, "wb") { |out|
- out.print(contents)
- }
- contents
- end
-
- def replace_file(file)
- old_contents = File.read(file)
- new_contents = yield(old_contents)
- if old_contents != new_contents
- File.open(file, "wb") { |output|
- output.print(new_contents)
- }
- end
- new_contents
- end
- end
-end
View
@@ -1,3 +1,2 @@
-$LOAD_PATH.unshift "devel"
-require 'jumpstart/simple_installer'
+load './devel/jumpstart.rb'
Jumpstart::SimpleInstaller.new.run
@@ -0,0 +1,27 @@
+
+module Quix
+ module InstanceEvalWithArgs
+ module_function
+
+ def with_temp_method(instance, method_name, method_block)
+ (class << instance ; self ; end).class_eval do
+ define_method(method_name, &method_block)
+ begin
+ yield method_name
+ ensure
+ remove_method(method_name)
+ end
+ end
+ end
+
+ def call_temp_method(instance, method_name, *args, &method_block)
+ with_temp_method(instance, method_name, method_block) {
+ instance.send(method_name, *args)
+ }
+ end
+
+ def instance_eval_with_args(instance, *args, &block)
+ call_temp_method(instance, :__temp_method, *args, &block)
+ end
+ end
+end
View
@@ -1,9 +1,11 @@
-require 'rbconfig'
-
module Quix
module Ruby
- EXECUTABLE = lambda {
+ module_function
+
+ def executable
+ require 'rbconfig'
+
name = File.join(
Config::CONFIG["bindir"],
Config::CONFIG["RUBY_INSTALL_NAME"]
@@ -15,30 +17,46 @@ module Ruby
else
name
end
- }.call
+ end
- class << self
- def run(*args)
- cmd = [EXECUTABLE, *args]
- unless system(*cmd)
- cmd_str = cmd.map { |t| "'#{t}'" }.join(", ")
- raise "system(#{cmd_str}) failed with status #{$?.exitstatus}"
- end
+ def run(*args)
+ cmd = [executable, *args]
+ unless system(*cmd)
+ cmd_str = cmd.map { |t| "'#{t}'" }.join(", ")
+ raise "system(#{cmd_str}) failed with status #{$?.exitstatus}"
end
-
- def with_warnings(value = true)
- previous = $VERBOSE
- $VERBOSE = value
- begin
- yield
- ensure
- $VERBOSE = previous
- end
+ end
+
+ def run_code_and_capture(code)
+ IO.popen(%{"#{executable}"}, "r+") { |pipe|
+ pipe.print(code)
+ pipe.flush
+ pipe.close_write
+ pipe.read
+ }
+ end
+
+ def run_file_and_capture(file)
+ unless File.file? file
+ raise "file does not exist: `#{file}'"
end
+ IO.popen(%{"#{executable}" "#{file}"}, "r") { |pipe|
+ pipe.read
+ }
+ end
- def no_warnings(&block)
- with_warnings(nil, &block)
+ def with_warnings(value = true)
+ previous = $VERBOSE
+ $VERBOSE = value
+ begin
+ yield
+ ensure
+ $VERBOSE = previous
end
end
+
+ def no_warnings(&block)
+ with_warnings(nil, &block)
+ end
end
end
View
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + "/common"
+require File.dirname(__FILE__) + '/quix_test_base'
require "quix/ext/array"
View
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + "/common"
+require File.dirname(__FILE__) + '/quix_test_base'
require 'quix/attr_lazy'
View
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + "/common"
+require File.dirname(__FILE__) + '/quix_test_base'
require "quix/attr_scope"
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + "/common"
+require File.dirname(__FILE__) + '/quix_test_base'
require "fileutils"
require "quix/casefold_glob"
View
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + "/common"
+require File.dirname(__FILE__) + '/quix_test_base'
require 'quix/ext/class'
Oops, something went wrong.

0 comments on commit fef5c41

Please sign in to comment.