From 236c4cfb0bc0396247198d7778585e5decbca01c Mon Sep 17 00:00:00 2001 From: Simon Chiang Date: Fri, 7 May 2010 15:38:07 -0600 Subject: [PATCH 01/14] updated some tests for ruby 1.8.6 --- tap/doc/Examples/Tapfile | 2 +- tap/test/doc/examples/tapfile_test.rb | 24 +++++++------ tap/test/tap/env_test.rb | 52 ++++++++++++++------------- 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/tap/doc/Examples/Tapfile b/tap/doc/Examples/Tapfile index 633fe363..ce240be1 100644 --- a/tap/doc/Examples/Tapfile +++ b/tap/doc/Examples/Tapfile @@ -111,7 +111,7 @@ Workflows work just like tasks: a b c Singleton tasks can be used to create dependency-based workflows that function -much like rake tasks in practice: +much like rake tasks in practice (requires ruby > 1.8.6): % tap c a diff --git a/tap/test/doc/examples/tapfile_test.rb b/tap/test/doc/examples/tapfile_test.rb index e3bd9853..01071e51 100644 --- a/tap/test/doc/examples/tapfile_test.rb +++ b/tap/test/doc/examples/tapfile_test.rb @@ -114,18 +114,20 @@ def process(thing) /\Awork :sort_file, :reverse => false do |config|\ntask :goodnight, :msg => 'goodnight' do |config, thing|/, :env => default_env.merge('TAPFILE' => 'tapfile') - sh_test %q{ - % tap c - a - b - c - }, :env => default_env.merge('TAPFILE' => 'tapfile') + if RUBY_VERSION > '1.8.6' + sh_test %q{ + % tap c + a + b + c + }, :env => default_env.merge('TAPFILE' => 'tapfile') - sh_test %q{ - % tap b -- a - a - b - }, :env => default_env.merge('TAPFILE' => 'tapfile') + sh_test %q{ + % tap b -- a + a + b + }, :env => default_env.merge('TAPFILE' => 'tapfile') + end end def test_first_node_is_input_node_when_undeclared diff --git a/tap/test/tap/env_test.rb b/tap/test/tap/env_test.rb index b2ccbd02..337620cc 100644 --- a/tap/test/tap/env_test.rb +++ b/tap/test/tap/env_test.rb @@ -67,6 +67,10 @@ def test_path_returns_collection_of_paths_for_type # match test # + def assert_constants(expected, constants) + assert_equal expected, constants.collect {|const| const.const_name } + end + def test_match_matches_constants_by_const_name env.constants.concat [ Constant.new('A'), @@ -75,11 +79,11 @@ def test_match_matches_constants_by_const_name Constant.new('C') ] - assert_equal ['A'], env.match('A').map(&:const_name) - assert_equal ['A'], env.match('::A').map(&:const_name) - assert_equal ['C'], env.match('C').map(&:const_name) - assert_equal ['A::B::C'], env.match('A::B::C').map(&:const_name) - assert_equal ['A::B::C'], env.match('::A::B::C').map(&:const_name) + assert_constants ['A'], env.match('A') + assert_constants ['A'], env.match('::A') + assert_constants ['C'], env.match('C') + assert_constants ['A::B::C'], env.match('A::B::C') + assert_constants ['A::B::C'], env.match('::A::B::C') end def test_match_matches_constants_by_path_matching @@ -90,17 +94,17 @@ def test_match_matches_constants_by_path_matching Constant.new('C') ] - assert_equal ['A'], env.match('a').map(&:const_name) - assert_equal ['A'], env.match('/a').map(&:const_name) - assert_equal ['A::B'], env.match('b').map(&:const_name) - assert_equal ['A::B'], env.match('a/b').map(&:const_name) - assert_equal ['A::B'], env.match('/a/b').map(&:const_name) - assert_equal ['A::B::C'], env.match('a:c').map(&:const_name) - assert_equal ['A::B::C'], env.match('/a/b/c:').map(&:const_name) - assert_equal ['A::B::C'], env.match(':/a/b/c').map(&:const_name) - assert_equal ['C'], env.match('c:').map(&:const_name) - assert_equal ['C'], env.match('/c:').map(&:const_name) - assert_equal ['A::B::C', 'C'], env.match('c').map(&:const_name) + assert_constants ['A'], env.match('a') + assert_constants ['A'], env.match('/a') + assert_constants ['A::B'], env.match('b') + assert_constants ['A::B'], env.match('a/b') + assert_constants ['A::B'], env.match('/a/b') + assert_constants ['A::B::C'], env.match('a:c') + assert_constants ['A::B::C'], env.match('/a/b/c:') + assert_constants ['A::B::C'], env.match(':/a/b/c') + assert_constants ['C'], env.match('c:') + assert_constants ['C'], env.match('/c:') + assert_constants ['A::B::C', 'C'], env.match('c') end def test_match_filters_by_type_if_specified @@ -109,9 +113,9 @@ def test_match_filters_by_type_if_specified Constant.new('B::A').register_as('two') ] - assert_equal ['A'], env.match('a', 'one').map(&:const_name) - assert_equal ['B::A'], env.match('a', 'two').map(&:const_name) - assert_equal ['A', 'B::A'], env.match('a', ['one', 'two']).map(&:const_name) + assert_constants ['A'], env.match('a', 'one') + assert_constants ['B::A'], env.match('a', 'two') + assert_constants ['A', 'B::A'], env.match('a', ['one', 'two']) end def test_match_filters_by_inline_type_if_specified @@ -120,9 +124,9 @@ def test_match_filters_by_inline_type_if_specified Constant.new('B::A').register_as('two') ] - assert_equal ['A'], env.match('a::one').map(&:const_name) - assert_equal ['B::A'], env.match('a::two').map(&:const_name) - assert_equal ['B::A'], env.match('a::two', 'one').map(&:const_name) + assert_constants ['A'], env.match('a::one') + assert_constants ['B::A'], env.match('a::two') + assert_constants ['B::A'], env.match('a::two', 'one') end def test_path_matching_only_matches_along_word_breaks @@ -139,8 +143,8 @@ def test_match_stringifies_inputs Constant.new('A') ] - assert_equal ['A'], env.match('a').map(&:const_name) - assert_equal ['A'], env.match(:a).map(&:const_name) + assert_constants ['A'], env.match('a') + assert_constants ['A'], env.match(:a) end # From 4889a9f6b885493c06d1e3c921c13e7392761cdd Mon Sep 17 00:00:00 2001 From: Simon Chiang Date: Fri, 7 May 2010 15:54:04 -0600 Subject: [PATCH 02/14] updated Test::Unit shim to be a bit more robust --- tap-test/lib/tap/test/unit.rb | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/tap-test/lib/tap/test/unit.rb b/tap-test/lib/tap/test/unit.rb index 066ef531..4c85d963 100644 --- a/tap-test/lib/tap/test/unit.rb +++ b/tap-test/lib/tap/test/unit.rb @@ -41,38 +41,35 @@ def method_name # tricky than in the Mini::Test Test::Unit. class Test::Unit::TestCase class << self - alias tap_original_test_case_inherited inherited - - def inherited(child) - super - tap_original_test_case_inherited(child) - child.instance_variable_set(:@skip_messages, []) - child.instance_variable_set(:@run_test_suite, true) - end - # Causes a test suite to be skipped. If a message is given, it will # print and notify the user the test suite has been skipped. def skip_test(msg=nil) - @run_test_suite = false - @skip_messages << msg + @skip_test_suite = true + skip_messages << msg end - + alias :original_suite :suite # Modifies the default suite method to skip the suit unless # run_test_suite is true. If the test is skipped, the skip_messages # will be printed along with the default 'Skipping ' message. def suite # :nodoc: - if @run_test_suite - original_suite - else - skip_message = @skip_messages.compact.join(', ') + if (@skip_test_suite ||= false) + skip_message = skip_messages.compact.join(', ') puts "Skipping #{name}#{skip_message.empty? ? '' : ': ' + skip_message}" # return an empty test suite of the appropriate name Test::Unit::TestSuite.new(name) + else + original_suite end end + + protected + + def skip_messages # :nodoc: + @skip_messages ||= [] + end end end From d27edad0856cef86c0f555bf017df45850c85266 Mon Sep 17 00:00:00 2001 From: Simon Chiang Date: Fri, 7 May 2010 16:20:17 -0600 Subject: [PATCH 03/14] version tap-test-0.6.1 --- tap-test/History | 4 ++++ tap-test/lib/tap/test/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tap-test/History b/tap-test/History index 107cf574..8afd9c0c 100644 --- a/tap-test/History +++ b/tap-test/History @@ -1,3 +1,7 @@ +== 0.6.1 / 2010-0-07 + +* updated Test::Unit shim to be a little more robust + == 0.6.0 / 2010-05-02 This release removes crufty methods that are rarely used and diff --git a/tap-test/lib/tap/test/version.rb b/tap-test/lib/tap/test/version.rb index d79b3de8..b8bf795b 100644 --- a/tap-test/lib/tap/test/version.rb +++ b/tap-test/lib/tap/test/version.rb @@ -2,7 +2,7 @@ module Tap module Test MAJOR = 0 MINOR = 6 - TINY = 0 + TINY = 1 VERSION="#{MAJOR}.#{MINOR}.#{TINY}" end From 3f7dc72f282066ae8a7c119555359bae6453c402 Mon Sep 17 00:00:00 2001 From: Simon Chiang Date: Mon, 10 May 2010 12:12:47 -0600 Subject: [PATCH 04/14] updated generator templates --- .../lib/tap/generator/generators/generator.rb | 2 +- .../generators/generator/resource.erb | 20 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tap-gen/lib/tap/generator/generators/generator.rb b/tap-gen/lib/tap/generator/generators/generator.rb index 271144ee..db9bdb97 100644 --- a/tap-gen/lib/tap/generator/generators/generator.rb +++ b/tap-gen/lib/tap/generator/generators/generator.rb @@ -17,7 +17,7 @@ def manifest(m, const_name) # (note it's easier to do this as a file since erb is # added, and would have to be escaped in a template) m.file path('templates', const.path, 'template_file.erb') do |file| - file << "# A sample template file.\nkey: <%= key %>\n" + file << "# A sample template file.\nkey: <%= format key %>\n" end const diff --git a/tap-gen/templates/tap/generator/generators/generator/resource.erb b/tap-gen/templates/tap/generator/generators/generator/resource.erb index 96b03296..d713810b 100644 --- a/tap-gen/templates/tap/generator/generators/generator/resource.erb +++ b/tap-gen/templates/tap/generator/generators/generator/resource.erb @@ -8,16 +8,24 @@ class <%= const.name %> < Tap::Generator::Base config :key, 'value' # a sample config - # The generator will receive the inputs on the command line, and - # m, a Manifest object that records the actions of this method. + helper do + # helper methods are available in templates + def format(value) + value.upcase + end + end + + # Manifest (m) records methods to be run by the generator. The inputs are + # generator inputs from the command line. Any method on self may be recorded + # in the manifest. The most common methods are demonstrated below. def manifest(m, *inputs) # make a directory - # m.directory 'path' + # m.directory 'dir' # make a file - # m.file 'path' do |file| - # file << content + # m.file 'file.txt' do |file| + # file << 'content' # end # template a file in the templates directory using ERB. @@ -26,7 +34,7 @@ class <%= const.name %> < Tap::Generator::Base m.template "<%= const.const_name.underscore %>_file.txt", 'template_file.erb', config.to_hash # do something only on generate/destroy - # on(:generate) {} + # on(:generate) { `chmod 644 #{path('file.txt')}` } end end <% module_nest(const.nesting, ' ') { target } end %> From 1efa7a74c768d89b4fb76ede6e2cae37eef1f561 Mon Sep 17 00:00:00 2001 From: Simon Chiang Date: Mon, 10 May 2010 12:48:31 -0600 Subject: [PATCH 05/14] updated the generate/destroy documentation --- tap-gen/lib/tap/generator/destroy.rb | 4 +++- tap-gen/lib/tap/generator/generate.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tap-gen/lib/tap/generator/destroy.rb b/tap-gen/lib/tap/generator/destroy.rb index 00a64a72..9e9cf0be 100644 --- a/tap-gen/lib/tap/generator/destroy.rb +++ b/tap-gen/lib/tap/generator/destroy.rb @@ -5,7 +5,9 @@ module Generator # ::mixin run generators in reverse # - # A mixin defining how to run manifest actions in reverse. + # Run a generator in 'destroy' mode. The first argument identifies the + # generator and subsequent arguments are passed as inputs. + #. module Destroy extend Lazydoc::Attributes lazy_attr(:desc, 'mixin') diff --git a/tap-gen/lib/tap/generator/generate.rb b/tap-gen/lib/tap/generator/generate.rb index c9751047..6261d5bb 100644 --- a/tap-gen/lib/tap/generator/generate.rb +++ b/tap-gen/lib/tap/generator/generate.rb @@ -6,7 +6,9 @@ module Generator # ::mixin run generators # - # A mixin defining how to run manifest actions. + # Run a generator in 'generate' mode. The first argument identifies the + # generator and subsequent arguments are passed as inputs. + # module Generate extend Lazydoc::Attributes lazy_attr(:desc, 'mixin') From 3dd8d9a1c7c826496e2a3ee023f6f7fac22d32c2 Mon Sep 17 00:00:00 2001 From: Simon Chiang Date: Tue, 18 May 2010 22:14:00 -0600 Subject: [PATCH 06/14] updated generator templates --- tap-gen/templates/tap/generator/generators/generator/test.erb | 2 +- tap-gen/test/tap/generator/generators/generator_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tap-gen/templates/tap/generator/generators/generator/test.erb b/tap-gen/templates/tap/generator/generators/generator/test.erb index 9b8f8ae3..0e69a1e7 100644 --- a/tap-gen/templates/tap/generator/generators/generator/test.erb +++ b/tap-gen/templates/tap/generator/generators/generator/test.erb @@ -20,7 +20,7 @@ class <%= const.name %>Test < Test::Unit::TestCase # check the content as necessary assert_equal %q{ # A sample template file. -key: value +key: VALUE }, "\n" + g.preview['<%= const.const_name.underscore %>_file.txt'] end end \ No newline at end of file diff --git a/tap-gen/test/tap/generator/generators/generator_test.rb b/tap-gen/test/tap/generator/generators/generator_test.rb index 78035cdb..918be826 100644 --- a/tap-gen/test/tap/generator/generators/generator_test.rb +++ b/tap-gen/test/tap/generator/generators/generator_test.rb @@ -39,7 +39,7 @@ def test_generator_generator assert_equal %q{ # A sample template file. -key: value +key: VALUE }, "\n" + c.preview['const_name_file.txt'] end end \ No newline at end of file From 6a1d6f28133d5d7e02cbfda76b79682266be7d40 Mon Sep 17 00:00:00 2001 From: Simon Chiang Date: Tue, 18 May 2010 22:53:33 -0600 Subject: [PATCH 07/14] created rake tasks for setup and testing of a newly-cloned repo --- .gitignore | 1 + Gemfile | 40 +++++++++++++++++++++++++++ Rakefile | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tap/Rakefile | 77 ---------------------------------------------------- tapfile | 20 +------------- 5 files changed, 119 insertions(+), 96 deletions(-) create mode 100644 Gemfile create mode 100644 Rakefile delete mode 100644 tap/Rakefile diff --git a/.gitignore b/.gitignore index 4aff79b7..fd1875b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store +.bundle pkg rdoc backup diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..22604beb --- /dev/null +++ b/Gemfile @@ -0,0 +1,40 @@ +############################################################################# +# Dependencies in this Gemfile are managed through the gemspecs for each +# module. Add/remove depenencies there, rather than editing this file ex: +# +# Gem::Specification.new do |s| +# ... +# s.add_dependency("rack") +# s.add_development_dependency("rack-test") +# end +# +############################################################################# + +source :gemcutter +path '.', :glob => '{configurable,lazydoc}/*.gemspec' + +$:.unshift File.expand_path('../lazydoc/lib', __FILE__) +$:.unshift File.expand_path('../configurable/lib', __FILE__) + +# +# Setup gemspec dependencies +# + +%w{ + tap + tap-gen + tap-tasks + tap-test +}.each do |project| + project_path = File.expand_path("../#{project}", __FILE__) + Dir.chdir(project_path) do + gemspec = eval(File.read("#{project_path}/#{project}.gemspec")) + + gemspec.dependencies.each do |dep| + group = dep.type == :development ? :development : :default + gem dep.name, dep.requirement, :group => group + end + + gem(gemspec.name, gemspec.version, :path => project_path) + end +end diff --git a/Rakefile b/Rakefile new file mode 100644 index 00000000..234463bc --- /dev/null +++ b/Rakefile @@ -0,0 +1,77 @@ +require 'rake' + +def gemspec(name) + path = File.expand_path("#{name}.gemspec") + eval(File.read(path), binding, path, 0) +end + +# +# Dependency tasks +# + +desc 'Checkout submodules' +task :submodules do + output = `git submodule status 2>&1` + + if output =~ /^-/m + puts "Missing submodules:\n#{output}" + sh "git submodule init" + sh "git submodule update" + puts + end +end + +desc 'Bundle dependencies' +task :bundle => :submodules do + output = `bundle check 2>&1` + + unless $?.to_i == 0 + puts output + puts "bundle install 2>&1" + system "bundle install 2>&1" + puts + end +end + +# +# Test tasks +# + +desc "Run tests" +task :test => :bundle do + %w{ + tap + tap-gen + tap-tasks + tap-test + }.each do |name| + pwd = Dir.pwd + begin + Dir.chdir(name) + + libs = ['lib'] + unless ENV['gems'] + libs << '../configurable/lib' + libs << '../lazydoc/lib' + end + + gemspec(name).dependencies.each do |dep| + libs << File.join('..', dep.name, 'lib') + end + + cmd = ['ruby', '-w', '-e', 'ARGV.each {|test| load test}'] + libs.uniq.each {|lib| cmd.concat ['-I', lib] } + cmd.concat Dir.glob("test/**/*_test.rb") + sh(*cmd) + ensure + Dir.chdir(pwd) + end + end + + puts %q{ +All tests pass. Try testing using tap itself: + + % ./tapexe test --all + +} +end \ No newline at end of file diff --git a/tap/Rakefile b/tap/Rakefile deleted file mode 100644 index 8e58103e..00000000 --- a/tap/Rakefile +++ /dev/null @@ -1,77 +0,0 @@ -require 'rake' - -# -# Dependency tasks -# - -desc 'Checkout submodules' -task :submodules do - Dir.chdir('..') do - output = `git submodule status 2>&1` - - if output =~ /^-/m - puts "Missing submodules:\n#{output}" - sh "git submodule init" - sh "git submodule update" - puts - end - end -end - -# -# Test tasks -# - -def test(tests) - libs = ['lib'] - unless ENV['gems'] - libs << '../configurable/lib' - libs << '../lazydoc/lib' - libs << '../tap/lib' - libs << '../tap-test/lib' - end - - cmd = ['ruby', '-w', '-e', 'ARGV.each {|test| load test}'] - libs.each {|lib| cmd.concat ['-I', lib] } - cmd.concat(tests) - sh(*cmd) -end - -def test_section(type) - test Dir["test/tap/#{type}*_test.rb", "test/tap/#{type}/**/*_test.rb"].uniq -end - -desc 'Run the tests' -task :default => :test - -desc 'Run the tests' -task :test => %w{ - test:tap - test:doc -} - -namespace :test do - desc 'run root tests' - task(:root) { test_section :root } - - desc 'run app tests' - task(:app) { test_section :app } - - desc 'run signals tests' - task(:signals) { test_section :signals } - - desc 'run env tests' - task(:env) { test_section :env } - - desc 'run parser tests' - task(:parser) { test_section :parser } - - desc 'run all tap tests' - task(:tap => :submodules) { test(Dir['test/tap/**/*_test.rb'] + Dir['test/*_test.rb']) } - - desc 'run documentation tests' - task(:doc => :submodules) { test Dir['test/doc/**/*_test.rb'] } - - desc 'run benchmark tests' - task(:benchmark => :submodules) { test Dir['test/benchmark/**/*_benchmark.rb'] } -end \ No newline at end of file diff --git a/tapfile b/tapfile index ac0f0d0c..ae0e7f73 100644 --- a/tapfile +++ b/tapfile @@ -17,24 +17,6 @@ def gemspec(name) end end -# -# Dependency tasks -# - -singleton do - desc 'Checkout submodules' - task :submodules do - output = `git submodule status 2>&1` - - if output =~ /^-/m - puts "Missing submodules:\n#{output}" - sh "git submodule init" - sh "git submodule update" - puts - end - end -end - # # Tasks # @@ -135,7 +117,7 @@ task(:gem, end desc 'Run tests.' -task({:test => :submodules}, {:all => false}) do |config, name| +task(:test, {:all => false}) do |config, name| libs = %W{ ../configurable/lib ../lazydoc/lib From 4004ceda2d2de60d1954714ec0bf5fcb041f0377 Mon Sep 17 00:00:00 2001 From: Simon Chiang Date: Tue, 18 May 2010 23:03:10 -0600 Subject: [PATCH 08/14] ensured configurable submodule is setup by rakefile --- Gemfile | 3 --- Rakefile | 33 +++++++++++++++++++++------------ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Gemfile b/Gemfile index 22604beb..122ae18a 100644 --- a/Gemfile +++ b/Gemfile @@ -13,9 +13,6 @@ source :gemcutter path '.', :glob => '{configurable,lazydoc}/*.gemspec' -$:.unshift File.expand_path('../lazydoc/lib', __FILE__) -$:.unshift File.expand_path('../configurable/lib', __FILE__) - # # Setup gemspec dependencies # diff --git a/Rakefile b/Rakefile index 234463bc..5ba583ab 100644 --- a/Rakefile +++ b/Rakefile @@ -5,19 +5,33 @@ def gemspec(name) eval(File.read(path), binding, path, 0) end +def chdir(dir) + pwd = Dir.pwd + begin + Dir.chdir(dir) + yield + ensure + Dir.chdir(pwd) + end +end + # # Dependency tasks # desc 'Checkout submodules' task :submodules do - output = `git submodule status 2>&1` + %w{. configurable}.each do |name| + chdir(name) do + output = `git submodule status 2>&1` - if output =~ /^-/m - puts "Missing submodules:\n#{output}" - sh "git submodule init" - sh "git submodule update" - puts + if output =~ /^-/m + puts "Missing submodules:\n#{output}" + sh "git submodule init" + sh "git submodule update" + puts + end + end end end @@ -45,10 +59,7 @@ task :test => :bundle do tap-tasks tap-test }.each do |name| - pwd = Dir.pwd - begin - Dir.chdir(name) - + chdir(name) do libs = ['lib'] unless ENV['gems'] libs << '../configurable/lib' @@ -63,8 +74,6 @@ task :test => :bundle do libs.uniq.each {|lib| cmd.concat ['-I', lib] } cmd.concat Dir.glob("test/**/*_test.rb") sh(*cmd) - ensure - Dir.chdir(pwd) end end From e7f5c174ff48bdf869d0313c1c26c307a18eaf35 Mon Sep 17 00:00:00 2001 From: Simon Chiang Date: Wed, 19 May 2010 22:41:11 -0600 Subject: [PATCH 09/14] enabled bundler for testing of each module --- Gemfile | 29 ++++++++++++++--------------- Rakefile | 14 ++------------ configurable | 2 +- lazydoc | 2 +- tap-gen/tap-gen.gemspec | 9 +++++++-- tap-tasks/tap-tasks.gemspec | 9 +++++++-- tap-test/tap-test.gemspec | 6 +++++- tap/tap.gemspec | 11 ++++++++--- tapfile | 34 +++++++++++++++++++++------------- 9 files changed, 66 insertions(+), 50 deletions(-) diff --git a/Gemfile b/Gemfile index 122ae18a..fa4ca491 100644 --- a/Gemfile +++ b/Gemfile @@ -11,27 +11,26 @@ ############################################################################# source :gemcutter -path '.', :glob => '{configurable,lazydoc}/*.gemspec' +path '.', :glob => '*/*.gemspec' # # Setup gemspec dependencies # -%w{ - tap - tap-gen - tap-tasks - tap-test -}.each do |project| - project_path = File.expand_path("../#{project}", __FILE__) - Dir.chdir(project_path) do - gemspec = eval(File.read("#{project_path}/#{project}.gemspec")) +pattern = File.expand_path("../tap*/*.gemspec", __FILE__) +Dir.glob(pattern).each do |gemspec_path| + project_dir = File.dirname(gemspec_path) + project_grp = File.basename(project_dir) - gemspec.dependencies.each do |dep| - group = dep.type == :development ? :development : :default - gem dep.name, dep.requirement, :group => group - end + Dir.chdir(project_dir) do + group project_grp do + gemspec = eval File.read(gemspec_path) + + gemspec.dependencies.each do |dep| + gem dep.name, dep.requirement + end - gem(gemspec.name, gemspec.version, :path => project_path) + gem gemspec.name, gemspec.version + end end end diff --git a/Rakefile b/Rakefile index 5ba583ab..8d27b5b9 100644 --- a/Rakefile +++ b/Rakefile @@ -60,18 +60,8 @@ task :test => :bundle do tap-test }.each do |name| chdir(name) do - libs = ['lib'] - unless ENV['gems'] - libs << '../configurable/lib' - libs << '../lazydoc/lib' - end - - gemspec(name).dependencies.each do |dep| - libs << File.join('..', dep.name, 'lib') - end - - cmd = ['ruby', '-w', '-e', 'ARGV.each {|test| load test}'] - libs.uniq.each {|lib| cmd.concat ['-I', lib] } + cmd = ['ruby', '-rubygems', '-e', "require 'bundler';Bundler.setup '#{name}'.to_sym"] + cmd.concat ['-w', '-e', 'ARGV.each {|test| load test}'] cmd.concat Dir.glob("test/**/*_test.rb") sh(*cmd) end diff --git a/configurable b/configurable index 0b7adce4..17c6f608 160000 --- a/configurable +++ b/configurable @@ -1 +1 @@ -Subproject commit 0b7adce4677b8fadb7b51e77dd457d6f983b26c3 +Subproject commit 17c6f6089743423dfe952e64fb1603850149602f diff --git a/lazydoc b/lazydoc index f9a7fed5..177c24f3 160000 --- a/lazydoc +++ b/lazydoc @@ -1 +1 @@ -Subproject commit f9a7fed5ab44081661f8428f4bfaf2db28dfe4bc +Subproject commit 177c24f3d39b3a33a791cf1671dc74140ef2e7d4 diff --git a/tap-gen/tap-gen.gemspec b/tap-gen/tap-gen.gemspec index 9df72b1e..f39f4d4d 100644 --- a/tap-gen/tap-gen.gemspec +++ b/tap-gen/tap-gen.gemspec @@ -6,6 +6,10 @@ require 'tap/version' require 'tap/test/version' require 'tap/generator/version' +$:.shift +$:.shift +$:.shift + Gem::Specification.new do |s| s.name = 'tap-gen' s.version = Tap::Generator::VERSION @@ -16,11 +20,12 @@ Gem::Specification.new do |s| s.summary = 'Generators for Tap' s.require_path = 'lib' s.rubyforge_project = 'tap' - s.add_dependency('tap', ">= #{Tap::VERSION}") - s.add_development_dependency('tap-test', ">= #{Tap::Test::VERSION}") s.has_rdoc = true s.rdoc_options.concat %W{--main README -S -N --title Tap-Generator} + s.add_dependency('tap', ">= #{Tap::VERSION}") + s.add_development_dependency('tap-test', ">= #{Tap::Test::VERSION}") + # list extra rdoc files here. s.extra_rdoc_files = %W{ History diff --git a/tap-tasks/tap-tasks.gemspec b/tap-tasks/tap-tasks.gemspec index fd4b4358..9cf035f0 100644 --- a/tap-tasks/tap-tasks.gemspec +++ b/tap-tasks/tap-tasks.gemspec @@ -6,6 +6,10 @@ require 'tap/version' require 'tap/test/version' require 'tap/tasks/version' +$:.shift +$:.shift +$:.shift + Gem::Specification.new do |s| s.name = 'tap-tasks' s.version = Tap::Tasks::VERSION @@ -16,11 +20,12 @@ Gem::Specification.new do |s| s.summary = 'A set of standard Tap tasks' s.require_path = 'lib' s.rubyforge_project = 'tap' - s.add_dependency('tap', ">= #{Tap::VERSION}") - s.add_development_dependency('tap-test', ">= #{Tap::Test::VERSION}") s.has_rdoc = true s.rdoc_options.concat %W{--main README -S -N --title Tap-Tasks} + s.add_dependency('tap', ">= #{Tap::VERSION}") + s.add_development_dependency('tap-test', ">= #{Tap::Test::VERSION}") + # list extra rdoc files here. s.extra_rdoc_files = %W{ History diff --git a/tap-test/tap-test.gemspec b/tap-test/tap-test.gemspec index 83acaaa5..2f8344c7 100644 --- a/tap-test/tap-test.gemspec +++ b/tap-test/tap-test.gemspec @@ -4,6 +4,9 @@ $:.unshift File.expand_path('../../tap-test/lib', __FILE__) require 'tap/version' require 'tap/test/version' +$:.shift +$:.shift + Gem::Specification.new do |s| s.name = 'tap-test' s.version = Tap::Test::VERSION @@ -14,10 +17,11 @@ Gem::Specification.new do |s| s.summary = 'Test modules for Tap' s.require_path = 'lib' s.rubyforge_project = 'tap' - s.add_dependency('tap', ">= #{Tap::VERSION}") s.has_rdoc = true s.rdoc_options.concat %W{--main README -S -N --title Tap-Test} + s.add_dependency('tap', ">= #{Tap::VERSION}") + # list extra rdoc files here. s.extra_rdoc_files = %W{ History diff --git a/tap/tap.gemspec b/tap/tap.gemspec index f7f7b418..fe77fcde 100644 --- a/tap/tap.gemspec +++ b/tap/tap.gemspec @@ -6,6 +6,10 @@ require 'tap/version' require 'tap/test/version' require 'configurable/version' +$:.shift +$:.shift +$:.shift + Gem::Specification.new do |s| s.name = 'tap' s.version = Tap::VERSION @@ -18,11 +22,12 @@ Gem::Specification.new do |s| s.rubyforge_project = 'tap' s.bindir = 'bin' s.executables = 'tap' - s.add_dependency('configurable', ">= #{Configurable::VERSION}") - s.add_development_dependency('tap-test', ">= #{Tap::Test::VERSION}") s.has_rdoc = true s.rdoc_options.concat %W{--main README -S -N --title Tap\s(Task\sApplication)} - + + s.add_dependency('configurable', ">= #{Configurable::VERSION}") + s.add_development_dependency('tap-test', ">= #{Tap::Test::VERSION}") + s.extra_rdoc_files = %W{ README MIT-LICENSE diff --git a/tapfile b/tapfile index ae0e7f73..30d39ed5 100644 --- a/tapfile +++ b/tapfile @@ -17,6 +17,24 @@ def gemspec(name) end end +# +# Dependency Tasks +# + +singleton do + desc 'Bundle dependencies' + task :bundle do + output = `bundle check 2>&1` + + unless $?.to_i == 0 + puts output + puts "bundle install 2>&1" + system "bundle install 2>&1" + puts + end + end +end + # # Tasks # @@ -117,19 +135,9 @@ task(:gem, end desc 'Run tests.' -task(:test, {:all => false}) do |config, name| - libs = %W{ - ../configurable/lib - ../lazydoc/lib - ../#{name}/lib - } - - gemspec(name).dependencies.each do |dep| - libs << File.join('..', dep.name, 'lib') - end - - cmd = ['ruby', '-w', '-e', 'ARGV.each {|test| load test}'] - libs.uniq.each {|lib| cmd.concat ['-I', lib] } +task({:test => :bundle}, {:all => false}) do |config, name| + cmd = ['ruby', '-rubygems', '-e', "require 'bundler';Bundler.setup '#{name}'.to_sym"] + cmd.concat ['-w', '-e', 'ARGV.each {|test| load test}'] cmd.concat Dir.glob("test/**/*_test.rb") with_env('ALL' => config.all.to_s) { sh(*cmd) } From 0fcf487f935c45faf16509699dc3287a81b23c80 Mon Sep 17 00:00:00 2001 From: Simon Chiang Date: Thu, 20 May 2010 21:27:52 -0600 Subject: [PATCH 10/14] sketched out tap-server setup --- Rakefile | 1 + tap-server/Rakefile | 104 --------------------------- tap-server/lib/tap/server/version.rb | 9 +++ tap-server/tap-server.gemspec | 35 ++++++--- tap-server/test/test_helper.rb | 15 +--- tapfile | 1 + 6 files changed, 37 insertions(+), 128 deletions(-) delete mode 100644 tap-server/Rakefile create mode 100644 tap-server/lib/tap/server/version.rb diff --git a/Rakefile b/Rakefile index 8d27b5b9..47db13fe 100644 --- a/Rakefile +++ b/Rakefile @@ -58,6 +58,7 @@ task :test => :bundle do tap-gen tap-tasks tap-test + tap-server }.each do |name| chdir(name) do cmd = ['ruby', '-rubygems', '-e', "require 'bundler';Bundler.setup '#{name}'.to_sym"] diff --git a/tap-server/Rakefile b/tap-server/Rakefile deleted file mode 100644 index 6d0ff8b6..00000000 --- a/tap-server/Rakefile +++ /dev/null @@ -1,104 +0,0 @@ -require 'rake' -require 'rake/testtask' -require 'rake/rdoctask' -require 'rake/gempackagetask' - -# -# Gem specification -# - -def gemspec - data = File.read('tap-server.gemspec') - spec = nil - Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join - spec -end - -Rake::GemPackageTask.new(gemspec) do |pkg| - pkg.need_tar = true -end - -desc 'Prints the gemspec manifest.' -task :print_manifest do - # collect files from the gemspec, labeling - # with true or false corresponding to the - # file existing or not - files = gemspec.files.inject({}) do |files, file| - files[File.expand_path(file)] = [File.exists?(file), file] - files - end - - # gather non-rdoc/pkg files for the project - # and add to the files list if they are not - # included already (marking by the absence - # of a label) - Dir.glob("**/*").each do |file| - next if file =~ /^(rdoc|pkg|test|results|schema|log)/ || File.directory?(file) - - path = File.expand_path(file) - files[path] = ["", file] unless files.has_key?(path) - end - - # sort and output the results - files.values.sort_by {|exists, file| file }.each do |entry| - puts "%-5s %s" % entry - end -end - -# -# Documentation tasks -# - -desc 'Generate documentation.' -Rake::RDocTask.new(:rdoc) do |rdoc| - spec = gemspec - - rdoc.rdoc_dir = 'rdoc' - rdoc.options.concat(spec.rdoc_options) - rdoc.rdoc_files.include( spec.extra_rdoc_files ) - - files = spec.files.select {|file| file =~ /^lib.*\.rb$/} - rdoc.rdoc_files.include( files ) - - require 'cdoc' - rdoc.template = 'cdoc/cdoc_html_template' - rdoc.options << '--fmt' << 'cdoc' -end - -desc "Publish RDoc to RubyForge" -task :publish_rdoc => [:rdoc] do - require 'yaml' - - config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml"))) - host = "#{config["username"]}@rubyforge.org" - - rsync_args = "-v -c -r" - remote_dir = "/var/www/gforge-projects/tap/tap-server" - local_dir = "rdoc" - - sh %{rsync #{rsync_args} #{local_dir}/ #{host}:#{remote_dir}} -end - -# -# Test tasks -# - -desc 'Default: Run tests.' -task :default => :test - -desc 'Run tests.' -Rake::TestTask.new(:test) do |t| - t.libs = ['lib'] - unless ENV['gems'] - t.libs << '../lazydoc/lib' - t.libs << '../configurable/lib' - t.libs << '../rack/lib' - t.libs << '../tap/lib' - t.libs << '../tap-test/lib' - end - - t.test_files = Dir.glob( File.join('test', 'tap/**/*_test.rb') ) - - t.verbose = true - t.warning = true -end \ No newline at end of file diff --git a/tap-server/lib/tap/server/version.rb b/tap-server/lib/tap/server/version.rb new file mode 100644 index 00000000..85effc54 --- /dev/null +++ b/tap-server/lib/tap/server/version.rb @@ -0,0 +1,9 @@ +module Tap + module Server + MAJOR = 0 + MINOR = 6 + TINY = 0 + + VERSION="#{MAJOR}.#{MINOR}.#{TINY}" + end +end \ No newline at end of file diff --git a/tap-server/tap-server.gemspec b/tap-server/tap-server.gemspec index 533aa28e..4e0e0d96 100644 --- a/tap-server/tap-server.gemspec +++ b/tap-server/tap-server.gemspec @@ -1,18 +1,33 @@ +$:.unshift File.expand_path('../../tap/lib', __FILE__) +$:.unshift File.expand_path('../../tap-test/lib', __FILE__) +$:.unshift File.expand_path('../../tap-server/lib', __FILE__) + +require 'tap/version' +require 'tap/test/version' +require 'tap/server/version' + +$:.shift +$:.shift +$:.shift + Gem::Specification.new do |s| - s.name = "tap-server" - s.version = "0.6.0" - s.author = "Simon Chiang" - s.email = "simon.a.chiang@gmail.com" - s.homepage = "http://tap.rubyforge.org" + s.name = 'tap-server' + s.version = Tap::Server::VERSION + s.author = 'Simon Chiang' + s.email = 'simon.a.chiang@gmail.com' + s.homepage = File.join(Tap::WEBSITE, 'tap-server') s.platform = Gem::Platform::RUBY - s.summary = "A web interface for tap." - s.require_path = "lib" - s.rubyforge_project = "tap" - s.add_dependency("tap", ">= 0.19.0") - s.add_dependency("rack", ">= 1.0 ") + s.summary = 'A web interface for tap.' + s.require_path = 'lib' + s.rubyforge_project = 'tap' s.has_rdoc = true s.rdoc_options.concat %W{--main README -S -N --title Tap\sServer} + s.add_dependency('tap', ">= #{Tap::VERSION}") + s.add_dependency('rack', '>= 1.0') + s.add_dependency('em-websocket') + s.add_development_dependency('tap-test', ">= #{Tap::Test::VERSION}") + s.extra_rdoc_files = %W{ README MIT-LICENSE diff --git a/tap-server/test/test_helper.rb b/tap-server/test/test_helper.rb index 37719105..a86539a1 100644 --- a/tap-server/test/test_helper.rb +++ b/tap-server/test/test_helper.rb @@ -1,17 +1,4 @@ -# setup testing with submodules -begin - require 'tap/test/unit' -rescue(LoadError) - puts %Q{ -Tests probably cannot be run because the submodules have -not been initialized. Use these commands and try again: - - % git submodule init - % git submodule update - -} - raise -end +require 'tap/test/unit' unless Object.const_defined?(:TEST_ROOT) TEST_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../") diff --git a/tapfile b/tapfile index 30d39ed5..b9e52951 100644 --- a/tapfile +++ b/tapfile @@ -48,6 +48,7 @@ class ModuleTask < Tap::Task tap-test tap-tasks tap-gen + tap-server } if names.empty? names.each do |name| From 46ff3559ade3914f7a7070786590d3328b89c6bf Mon Sep 17 00:00:00 2001 From: Simon Chiang Date: Thu, 20 May 2010 22:05:58 -0600 Subject: [PATCH 11/14] updated test setup such that bundler figures out dependencies but is not used in the actual tests --- README.rdoc | 18 ++++++++++++++++++ Rakefile | 16 ++++++++++++++-- tapfile | 38 +++++++++++++++++++++++++++----------- 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/README.rdoc b/README.rdoc index cab4698f..8375cc14 100755 --- a/README.rdoc +++ b/README.rdoc @@ -156,6 +156,24 @@ Tap is available as a gem on Gemcutter[http://gemcutter.org/gems/tap]. % gem install tap +== Development + +Tap is setup for easy development. Clone the repo and then run the tests; all +dependencies will be setup for you. Bundler[http://gembundler.com/] is +required. + + % git clone git@github.com:bahuvrihi/tap.git + % cd tap + % rake test + +Afterwards you can develop Tap using tap. Specify one or more modules to test, +or specify none to test them all. See the tapfile for the actual tasks being +run. + + % ./tapexe test [tap,tap-test,...] + +Patches welcome. + == Info Developer:: {Simon Chiang}[http://bahuvrihi.wordpress.com] diff --git a/Rakefile b/Rakefile index 47db13fe..a8a6f8bf 100644 --- a/Rakefile +++ b/Rakefile @@ -51,6 +51,18 @@ end # Test tasks # +def libs(*groups) + groups.collect! {|group| group.to_sym } + + require 'bundler' + specs = Bundler.load.send(:specs_for, groups) + specs.collect {|spec| spec.load_paths }.flatten.uniq +end + +def load_paths(*groups) + libs(*groups).collect {|lib| ['-I', lib] }.flatten +end + desc "Run tests" task :test => :bundle do %w{ @@ -61,8 +73,8 @@ task :test => :bundle do tap-server }.each do |name| chdir(name) do - cmd = ['ruby', '-rubygems', '-e', "require 'bundler';Bundler.setup '#{name}'.to_sym"] - cmd.concat ['-w', '-e', 'ARGV.each {|test| load test}'] + cmd = ['ruby', '-w', '-e', 'ARGV.each {|test| load test}'] + cmd.concat load_paths(name) cmd.concat Dir.glob("test/**/*_test.rb") sh(*cmd) end diff --git a/tapfile b/tapfile index b9e52951..01bfaf7c 100644 --- a/tapfile +++ b/tapfile @@ -40,18 +40,21 @@ end # class ModuleTask < Tap::Task + DEFAULT_NAMES = %w{ + tap + tap-test + tap-tasks + tap-gen + tap-server + } + def call(names) - pwd = Dir.pwd - - names = %w{ - tap - tap-test - tap-tasks - tap-gen - tap-server - } if names.empty? + if names.empty? + names = DEFAULT_NAMES + end names.each do |name| + pwd = Dir.pwd begin Dir.chdir(name) process(name) @@ -60,6 +63,19 @@ class ModuleTask < Tap::Task end end end + + def libs(*groups) + groups.collect! {|group| group.to_sym } + + require 'rubygems' + require 'bundler' + specs = Bundler.load.send(:specs_for, groups) + specs.collect {|spec| spec.load_paths }.flatten.uniq + end + + def load_paths(*groups) + libs(*groups).collect {|lib| ['-I', lib] }.flatten + end end baseclass ModuleTask @@ -137,8 +153,8 @@ end desc 'Run tests.' task({:test => :bundle}, {:all => false}) do |config, name| - cmd = ['ruby', '-rubygems', '-e', "require 'bundler';Bundler.setup '#{name}'.to_sym"] - cmd.concat ['-w', '-e', 'ARGV.each {|test| load test}'] + cmd = ['ruby', '-w', '-e', 'ARGV.each {|test| load test}'] + cmd.concat config.load_paths(name) cmd.concat Dir.glob("test/**/*_test.rb") with_env('ALL' => config.all.to_s) { sh(*cmd) } From 64b6a541d7206984e5ca698d1c8b8b0db821e488 Mon Sep 17 00:00:00 2001 From: Simon Chiang Date: Thu, 20 May 2010 22:23:47 -0600 Subject: [PATCH 12/14] moved load_paths helper to Gemfile --- Gemfile | 14 ++++++++++++++ Rakefile | 17 ++++------------- tapfile | 19 +++++-------------- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/Gemfile b/Gemfile index fa4ca491..a9b70950 100644 --- a/Gemfile +++ b/Gemfile @@ -34,3 +34,17 @@ Dir.glob(pattern).each do |gemspec_path| end end end + +# +# Test helper +# + +module ::Bundler + class Runtime < Environment + def load_paths(*groups) + groups.collect! {|group| group.to_sym } + libs = specs_for(groups).collect {|spec| spec.load_paths }.flatten.uniq + libs.collect {|lib| ['-I', lib] }.flatten + end + end +end \ No newline at end of file diff --git a/Rakefile b/Rakefile index a8a6f8bf..7b2e60fd 100644 --- a/Rakefile +++ b/Rakefile @@ -51,20 +51,11 @@ end # Test tasks # -def libs(*groups) - groups.collect! {|group| group.to_sym } - - require 'bundler' - specs = Bundler.load.send(:specs_for, groups) - specs.collect {|spec| spec.load_paths }.flatten.uniq -end - -def load_paths(*groups) - libs(*groups).collect {|lib| ['-I', lib] }.flatten -end - desc "Run tests" task :test => :bundle do + require 'bundler' + bundler = Bundler.load + %w{ tap tap-gen @@ -74,7 +65,7 @@ task :test => :bundle do }.each do |name| chdir(name) do cmd = ['ruby', '-w', '-e', 'ARGV.each {|test| load test}'] - cmd.concat load_paths(name) + cmd.concat bundler.load_paths(name) cmd.concat Dir.glob("test/**/*_test.rb") sh(*cmd) end diff --git a/tapfile b/tapfile index 01bfaf7c..6d6e27d8 100644 --- a/tapfile +++ b/tapfile @@ -63,19 +63,6 @@ class ModuleTask < Tap::Task end end end - - def libs(*groups) - groups.collect! {|group| group.to_sym } - - require 'rubygems' - require 'bundler' - specs = Bundler.load.send(:specs_for, groups) - specs.collect {|spec| spec.load_paths }.flatten.uniq - end - - def load_paths(*groups) - libs(*groups).collect {|lib| ['-I', lib] }.flatten - end end baseclass ModuleTask @@ -153,8 +140,12 @@ end desc 'Run tests.' task({:test => :bundle}, {:all => false}) do |config, name| + require 'rubygems' + require 'bundler' + bundler = Bundler.load + cmd = ['ruby', '-w', '-e', 'ARGV.each {|test| load test}'] - cmd.concat config.load_paths(name) + cmd.concat bundler.load_paths(name) cmd.concat Dir.glob("test/**/*_test.rb") with_env('ALL' => config.all.to_s) { sh(*cmd) } From 83137a1ffde34123e4a84c633213adb703787d7d Mon Sep 17 00:00:00 2001 From: Simon Chiang Date: Sat, 22 May 2010 17:25:46 -0600 Subject: [PATCH 13/14] removed pq --- Rakefile | 1 - tap/History | 4 ++++ tap/lib/tap/app.rb | 11 ----------- tap/lib/tap/tasks/prompt.rb | 2 +- tap/lib/tap/tasks/stream.rb | 2 +- tap/test/tap/app_signals_test.rb | 17 ----------------- tap/test/tap/app_test.rb | 17 ----------------- tapfile | 1 - 8 files changed, 6 insertions(+), 49 deletions(-) diff --git a/Rakefile b/Rakefile index 7b2e60fd..0f3d7a61 100644 --- a/Rakefile +++ b/Rakefile @@ -61,7 +61,6 @@ task :test => :bundle do tap-gen tap-tasks tap-test - tap-server }.each do |name| chdir(name) do cmd = ['ruby', '-w', '-e', 'ARGV.each {|test| load test}'] diff --git a/tap/History b/tap/History index a59fabe9..de8f1a46 100644 --- a/tap/History +++ b/tap/History @@ -1,3 +1,7 @@ +== + +* removed pq + == 1.3.0 / 2010-04-02 * various improvements to declarations diff --git a/tap/lib/tap/app.rb b/tap/lib/tap/app.rb index d7944f33..5e2f100f 100644 --- a/tap/lib/tap/app.rb +++ b/tap/lib/tap/app.rb @@ -127,11 +127,6 @@ def build(spec={}, app=current) obj.enq obj.obj(spec['var']), spec['input'] end - define_signal :pq do |input| # priority-enques an object - spec = convert_to_hash(input, ['var'], 'input') - obj.pq obj.obj(spec['var']), spec['input'] - end - signal_hash :set, # set or unset objects :signature => ['var', 'class'], :remainder => 'spec', @@ -270,12 +265,6 @@ def enq(task, input=[]) task end - # Priority-enques (unshifts) the task with the input. Returns the task. - def pq(task, input=[]) - queue.unshift(task, input) - task - end - # Sets the object to the specified variable and returns obj. Provide nil # as obj to un-set a variable (in which case the existing object is # returned). diff --git a/tap/lib/tap/tasks/prompt.rb b/tap/lib/tap/tasks/prompt.rb index 2907b204..78581652 100644 --- a/tap/lib/tap/tasks/prompt.rb +++ b/tap/lib/tap/tasks/prompt.rb @@ -57,7 +57,7 @@ def trap(sig) case gets.strip when /^y(es)?$/i puts "waiting for break..." - app.pq(self, []) + app.enq(self, []) call_prompt = false break diff --git a/tap/lib/tap/tasks/stream.rb b/tap/lib/tap/tasks/stream.rb index c3ae8fe9..d07b67d4 100644 --- a/tap/lib/tap/tasks/stream.rb +++ b/tap/lib/tap/tasks/stream.rb @@ -57,7 +57,7 @@ def complete?(io, last) # Reques self with io to the top of the queue. def reque(io) - app.pq(self, [io]) + app.enq(self, [io]) end end end diff --git a/tap/test/tap/app_signals_test.rb b/tap/test/tap/app_signals_test.rb index 754a1cce..3c7f86bf 100644 --- a/tap/test/tap/app_signals_test.rb +++ b/tap/test/tap/app_signals_test.rb @@ -43,23 +43,6 @@ def test_enq_raises_error_for_unknown_obj assert_equal "no object set to: 0", err.message end - # - # pq test - # - - def test_pq_priority_enques_obj_with_inputs - n = lambda {} - app.set(0, n) - signal :pq, [0, 1,2,3] - signal :pq, [0, 4,5,6] - assert_equal [[n, [4,5,6]], [n, [1,2,3]]], app.queue.to_a - end - - def test_pq_raises_error_for_unknown_obj - err = assert_raises(RuntimeError) { signal(:pq, [0]) } - assert_equal "no object set to: 0", err.message - end - # # set test # diff --git a/tap/test/tap/app_test.rb b/tap/test/tap/app_test.rb index 3d1209b1..77e3eedc 100644 --- a/tap/test/tap/app_test.rb +++ b/tap/test/tap/app_test.rb @@ -200,23 +200,6 @@ def test_enq_returns_enqued_node assert_equal n, app.enq(n, :a) end - # - # pq test - # - - def test_pq_unshifts_node_onto_queue - n = lambda {} - assert_equal 0, app.queue.size - app.pq(n, :a) - app.pq(n, :b) - assert_equal [[n, :b], [n, :a]], app.queue.to_a - end - - def test_pq_returns_enqued_node - n = lambda {} - assert_equal n, app.pq(n, :a) - end - # # set test # diff --git a/tapfile b/tapfile index 6d6e27d8..f4adb05a 100644 --- a/tapfile +++ b/tapfile @@ -45,7 +45,6 @@ class ModuleTask < Tap::Task tap-test tap-tasks tap-gen - tap-server } def call(names) From bca823c910138288c189f9e44521c433b64b26c8 Mon Sep 17 00:00:00 2001 From: Simon Chiang Date: Sat, 22 May 2010 20:40:30 -0600 Subject: [PATCH 14/14] simpified, minimized Queue api --- Rakefile | 6 +- tap/History | 1 + tap/lib/tap/app.rb | 10 +-- tap/lib/tap/app/queue.rb | 47 +++---------- tap/lib/tap/parser.rb | 2 +- tap/test/tap/app/queue_test.rb | 107 ------------------------------ tap/test/tap/app_signals_test.rb | 9 ++- tap/test/tap/app_test.rb | 33 ++------- tap/test/tap/joins/gate_test.rb | 16 +---- tap/test/tap/joins/switch_test.rb | 4 +- tap/test/tap/joins/sync_test.rb | 4 +- 11 files changed, 40 insertions(+), 199 deletions(-) delete mode 100644 tap/test/tap/app/queue_test.rb diff --git a/Rakefile b/Rakefile index 0f3d7a61..d4fa6f6c 100644 --- a/Rakefile +++ b/Rakefile @@ -56,12 +56,14 @@ task :test => :bundle do require 'bundler' bundler = Bundler.load - %w{ + modules = ENV['MODULE'] ||= %q{ tap tap-gen tap-tasks tap-test - }.each do |name| + } + + modules.split.each do |name| chdir(name) do cmd = ['ruby', '-w', '-e', 'ARGV.each {|test| load test}'] cmd.concat bundler.load_paths(name) diff --git a/tap/History b/tap/History index de8f1a46..e4b66b2e 100644 --- a/tap/History +++ b/tap/History @@ -1,6 +1,7 @@ == * removed pq +* simplified queue api == 1.3.0 / 2010-04-02 diff --git a/tap/lib/tap/app.rb b/tap/lib/tap/app.rb index 5e2f100f..a40c6efd 100644 --- a/tap/lib/tap/app.rb +++ b/tap/lib/tap/app.rb @@ -1,4 +1,5 @@ require 'logger' +require 'monitor' require 'tap/env' require 'tap/app/state' require 'tap/app/stack' @@ -261,7 +262,7 @@ def log(action='', msg=nil, level=Logger::INFO) # Enques the task with the input. Returns the task. def enq(task, input=[]) - queue.enq(task, input) + queue.enq [task, input] task end @@ -499,7 +500,6 @@ def run end rescue(TerminateError) # gracefully fail for termination errors - queue.unshift(*job) ensure synchronize { @state = State::READY } end @@ -575,8 +575,10 @@ def serialize(bare=true) order = [] # collect enque signals to setup queue - signals = queue.to_a.collect do |(task, input)| - {'sig' => 'enq', 'args' => {'var' => var(task), 'input' => input}} + signals = [] + while queue.size > 0 + task, input = queue.deq + signals << {'sig' => 'enq', 'args' => {'var' => var(task), 'input' => input}} end # collect and trace application objects diff --git a/tap/lib/tap/app/queue.rb b/tap/lib/tap/app/queue.rb index b10f45d1..3d9665db 100644 --- a/tap/lib/tap/app/queue.rb +++ b/tap/lib/tap/app/queue.rb @@ -1,27 +1,21 @@ -require 'monitor' - module Tap class App - # Queue allows thread-safe enqueing and dequeing of tasks and inputs for - # execution. + # Queue allows enqueing and dequeing of tasks and inputs for execution. # # === API # # The following methods are required in alternative implementations of an # applicaton queue, where a job is a [task, input] array: # - # enq(task, input) # pushes the job onto the queue - # unshift(task, input) # unshifts the job onto the queue + # enq # pushes the job onto the queue # deq # shifts a job off the queue # size # returns the number of jobs in the queue # clear # clears the queue, returns current jobs - # synchronize # yields to the block - # to_a # returns the queue as an array # # Note that synchronize must be implemented even if it does nothing but # yield to the block. - class Queue < Monitor + class Queue # Creates a new Queue def initialize @@ -30,45 +24,24 @@ def initialize end # Enqueues the task and input. - def enq(task, input) - synchronize do - @queue.push [task, input] - end - end - - # Enqueues the task and input, but to the top of the queue. - def unshift(task, input) - synchronize do - @queue.unshift [task, input] - end + def enq(obj) + @queue.push obj end # Dequeues the next job. Returns nil if the queue is empty. def deq - synchronize { @queue.shift } + @queue.shift end # Returns the number of enqueued jobs. def size - synchronize do - @queue.size - end + @queue.size end - # Clears self and returns an array of the currently enqueued jobs. + # Clears self. def clear - synchronize do - current = @queue - @queue = [] - current - end - end - - # Returns the enqueued jobs as an array. - def to_a - synchronize do - @queue.dup - end + @queue = [] + self end end end diff --git a/tap/lib/tap/parser.rb b/tap/lib/tap/parser.rb index 27721d99..821372b8 100644 --- a/tap/lib/tap/parser.rb +++ b/tap/lib/tap/parser.rb @@ -158,7 +158,7 @@ def spec(type, args=next_args) # :nodoc: def block(type, app) # :nodoc: case type when :enq - lambda {|obj, args| app.queue.enq(obj, args); obj } + lambda {|obj, args| app.enq(obj, args); obj } when :exe lambda {|obj, args| app.exe(obj, args); obj } else diff --git a/tap/test/tap/app/queue_test.rb b/tap/test/tap/app/queue_test.rb deleted file mode 100644 index 85eddaba..00000000 --- a/tap/test/tap/app/queue_test.rb +++ /dev/null @@ -1,107 +0,0 @@ -require File.expand_path('../../../test_helper', __FILE__) -require 'tap/app/queue' - -class QueueTest < Test::Unit::TestCase - Queue = Tap::App::Queue - - attr_accessor :m, :queue - - def setup - @m = :method - @queue = Queue.new - end - - # - # initialization tests - # - - def test_initialize - q = Queue.new - assert_equal 0, q.size - end - - # - # enq test - # - - def test_enq_pushes_task_and_input_onto_queue - assert_equal [], queue.to_a - - queue.enq(m, :a) - assert_equal [[m, :a]], queue.to_a - - queue.enq(m, :b) - assert_equal [[m, :a], [m, :b]], queue.to_a - end - - # - # unshift test - # - - def test_unshift - assert_equal [], queue.to_a - - queue.unshift(m, :a) - assert_equal [[m, :a]], queue.to_a - - queue.unshift(m, :b) - assert_equal [[m, :b], [m, :a]], queue.to_a - end - - # - # deq test - # - - def test_deq - queue.enq(m, :a) - queue.enq(m, :b) - - assert_equal [m, :a], queue.deq - assert_equal [m, :b], queue.deq - end - - # - # size tests - # - - def test_size_return_number_of_tasks - assert_equal 0, queue.size - queue.enq m, [] - assert_equal 1, queue.size - end - - # - # clear tests - # - - def test_clear_resets_tasks_and_task_inputs - assert_equal([], queue.to_a) - - queue.enq m, [] - queue.clear - - assert_equal([], queue.to_a) - end - - def test_clear_returns_existing_queue - assert_equal([], queue.to_a) - - queue.enq m, :a - queue.enq m, :b - assert_equal [[m, :a], [m, :b]], queue.clear - end - - # - # to_a test - # - - def test_to_a_returns_an_array_of_enqued_methods_and_entries - queue.enq m, :a - queue.enq m, :b - - assert_equal [ - [m, :a], - [m, :b] - ], queue.to_a - end -end \ No newline at end of file diff --git a/tap/test/tap/app_signals_test.rb b/tap/test/tap/app_signals_test.rb index 3c7f86bf..ac19c3b9 100644 --- a/tap/test/tap/app_signals_test.rb +++ b/tap/test/tap/app_signals_test.rb @@ -17,7 +17,7 @@ def test_exe_executes_obj_with_inputs signal :exe, [0, 1,2,3] signal :exe, [0, 4,5,6] - assert_equal [], app.queue.to_a + assert_equal 0, app.queue.size assert_equal [[1,2,3], [4,5,6]], runlist end @@ -35,7 +35,12 @@ def test_enq_enques_obj_with_inputs app.set(0, n) signal :enq, [0, 1,2,3] signal :enq, [0, 4,5,6] - assert_equal [[n, [1,2,3]], [n, [4,5,6]]], app.queue.to_a + + queue = [] + while app.queue.size > 0 + queue << app.queue.deq + end + assert_equal [[n, [1,2,3]], [n, [4,5,6]]], queue end def test_enq_raises_error_for_unknown_obj diff --git a/tap/test/tap/app_test.rb b/tap/test/tap/app_test.rb index 77e3eedc..81c77ba7 100644 --- a/tap/test/tap/app_test.rb +++ b/tap/test/tap/app_test.rb @@ -192,7 +192,9 @@ def test_enq_pushes_node_onto_queue assert_equal 0, app.queue.size app.enq(n, :a) app.enq(n, :b) - assert_equal [[n, :a], [n, :b]], app.queue.to_a + + assert_equal [n, :a], app.queue.deq + assert_equal [n, :b], app.queue.deq end def test_enq_returns_enqued_node @@ -380,7 +382,7 @@ def test_middleware_returns_an_empty_array_if_no_middleware_is_in_use def test_reset_clears_objects_queue_and_middleware app.objects['key'] = Object.new - app.queue.enq(:node, :input) + app.queue.enq [:node, :input] app.use MiddlewareClass assert_equal 1, app.objects.size @@ -495,9 +497,9 @@ def test_run_returns_immediately_when_already_running n0 = lambda do |input| end n1 = lambda do |input| - assert_equal [[n0, []]], app.queue.to_a + assert_equal 1, app.queue.size app.run - assert_equal [[n0, []]], app.queue.to_a + assert_equal 1, app.queue.size was_in_block = true end @@ -833,27 +835,4 @@ def test_terminate_errors_are_handled app.run assert was_in_block end - - def test_terminate_errors_reque_the_latest_node - was_in_block = false - terminate = true - n0 = lambda do |input| - was_in_block = true - raise Tap::App::TerminateError if terminate - end - n1 = lambda do |input| end - - app.enq n0, [1,2,3] - app.enq n1 - - assert_equal [[n0, [1,2,3]], [n1, []]], app.queue.to_a - - app.run - assert was_in_block - assert_equal [[n0, [1,2,3]], [n1, []]], app.queue.to_a - - terminate = false - app.run - assert_equal [], app.queue.to_a - end end diff --git a/tap/test/tap/joins/gate_test.rb b/tap/test/tap/joins/gate_test.rb index c8bede22..0a132e81 100644 --- a/tap/test/tap/joins/gate_test.rb +++ b/tap/test/tap/joins/gate_test.rb @@ -24,7 +24,7 @@ def setup # def test_gate_join_enques_self_after_call_when_results_are_nil - assert_equal [], app.queue.to_a + assert_equal 0, app.queue.size join = Gate.new({}, app) join.join([], []) @@ -32,27 +32,17 @@ def test_gate_join_enques_self_after_call_when_results_are_nil assert_equal nil, join.results join.call('a') - assert_equal [ - [join, ['a']] - ], app.queue.to_a - assert join.results != nil join.call('b') - assert_equal [ - [join, ['a', 'b']] - ], app.queue.to_a - # resets join results join.call(join.results) assert_equal nil, join.results join.call('c') - assert_equal [ - [join, ['a', 'b']], - [join, ['c']] - ], app.queue.to_a + assert_equal [join, ['a', 'b']], app.queue.deq + assert_equal [join, ['c']], app.queue.deq end def test_gate_join_collects_results_on_each_call diff --git a/tap/test/tap/joins/switch_test.rb b/tap/test/tap/joins/switch_test.rb index a99ea652..999d9063 100644 --- a/tap/test/tap/joins/switch_test.rb +++ b/tap/test/tap/joins/switch_test.rb @@ -194,8 +194,6 @@ def test_switch_raises_error_for_out_of_bounds_index a, ], runlist - assert_equal [ - [e, []] - ], app.queue.to_a + assert_equal [e, []], app.queue.deq end end diff --git a/tap/test/tap/joins/sync_test.rb b/tap/test/tap/joins/sync_test.rb index 01d2bfde..3f498486 100644 --- a/tap/test/tap/joins/sync_test.rb +++ b/tap/test/tap/joins/sync_test.rb @@ -130,9 +130,7 @@ def test_sync_merge_raises_error_if_target_cannot_be_enqued_before_a_source_exec a, ], runlist - assert_equal [ - [e, []] - ], app.queue.to_a + assert_equal [e, []], app.queue.deq end def test_sync_removes_callbacks_from_existing_inputs_on_join