diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-02-01 05:03:34 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-02-01 05:03:34 +0000 |
commit | 38362016f97c891f4b5b0d1fb38f8491c8eeac05 (patch) | |
tree | 9d7bfd518b96a735b06f46714c7d766f4fe934d7 | |
parent | fd2982fdd6268dd5d0a517fc57e03f5f3e2b389b (diff) | |
download | puppet-38362016f97c891f4b5b0d1fb38f8491c8eeac05.tar.gz puppet-38362016f97c891f4b5b0d1fb38f8491c8eeac05.tar.xz puppet-38362016f97c891f4b5b0d1fb38f8491c8eeac05.zip |
Trying to get the functionality I had in previous tests. Mostly I want
to be able to load many files but run just a couple of methods, which
test/unit supports via -n, selectively enabling -d. I now can do this
with the Rakefile, using 'TESTOPTS="-n <method> -d" rake <blah>,
although I find that a bit kludgy (certainly more so than
'rake -n <blah> -d <blah>').
However, I also want to be able to automatically determine which test
suites conflict (meaning something in one suite causes a failure in
another), which too-often happens. So, I'm going to mess around some
with 'test' until I get that, and then see if I can move that
functionality to the rakefile.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2146 980ebf18-57e1-0310-9a29-db15c13687c0
-rwxr-xr-x | test/lib/puppettest.rb | 56 | ||||
-rw-r--r-- | test/lib/rake/puppet_test_loader.rb | 7 | ||||
-rwxr-xr-x | test/test | 54 |
3 files changed, 116 insertions, 1 deletions
diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index 4bf3bc54c..bc6643840 100755 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -12,6 +12,60 @@ if ARGV.include?("-d") end module PuppetTest + # Munge cli arguments, so we can enable debugging if we want + # and so we can run just specific methods. + def self.munge_argv + require 'getoptlong' + + def resolve(dir, method) + end + + def ruby_files(dir) + files = [] + # First collect the entire file list. + find(dir) { |f| files << f if f =~ /\.rb$/ } + files + end + + #[ "--size", "-s", GetoptLong::REQUIRED_ARGUMENT ], + result = GetoptLong.new( + [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], + [ "--resolve", "-r", GetoptLong::REQUIRED_ARGUMENT ], + [ "-n", GetoptLong::REQUIRED_ARGUMENT ], + [ "--help", "-h", GetoptLong::NO_ARGUMENT ] + ) + + usage = "USAGE: %s [--help] <testsuite> <testsuite> .." % $0 + + opts = [] + + dir = method = nil + result.each { |opt,arg| + case opt + when "--resolve" + dir, method = arg.split(",") + when "--debug" + $puppet_debug = true + Puppet::Log.level = :debug + Puppet::Log.newdestination(:console) + when "--help" + puts usage + exit + else + opts << opt << arg + end + } + suites = nil + + args = ARGV.dup + + # Reset the options, so the test suite can deal with them (this is + # what makes things like '-n' work). + opts.each { |o| ARGV << o } + + return args + end + # Find the root of the Puppet tree; this is not the test directory, but # the parent of that dir. def basedir(*list) @@ -109,7 +163,7 @@ module PuppetTest # If we're running under rake, then disable debugging and such. #if rake? or ! Puppet[:debug] - if rake? + if rake? or ! defined?($puppet_debug) Puppet::Log.close Puppet::Log.newdestination tempfile() Puppet[:httplog] = tempfile() diff --git a/test/lib/rake/puppet_test_loader.rb b/test/lib/rake/puppet_test_loader.rb index cd91623b8..2bc03aa07 100644 --- a/test/lib/rake/puppet_test_loader.rb +++ b/test/lib/rake/puppet_test_loader.rb @@ -1,5 +1,12 @@ require 'test/unit/autorunner' +require 'getoptlong' + +result = GetoptLong.new( + [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], + [ "-n", GetoptLong::REQUIRED_ARGUMENT ], + [ "--help", "-h", GetoptLong::NO_ARGUMENT ] +) ARGV.each { |f| require f unless f =~ /^-/ } diff --git a/test/test b/test/test new file mode 100755 index 000000000..9fb856273 --- /dev/null +++ b/test/test @@ -0,0 +1,54 @@ +#!/usr/bin/env ruby + +#------------------------------------------------------------ +# Run any or all test suites. This script is different from +# the Rakefile because it allows one to run one or more individual test methods +# easily. + +require 'find' +include Find + +basedir = File.dirname(__FILE__) +$:.unshift(File.join(basedir, "lib")) + +require 'puppettest' + +def resolve(dir, method) +end + +def ruby_files(dir) + files = [] + # First collect the entire file list. + find(dir) { |f| files << f if f =~ /\.rb$/ } + files +end +suites = nil + +args = PuppetTest.munge_argv + +unless args.length != 0 + Dir.glob("*").find_all { |d| FileTest.directory?(d) }.reject { |d| + d == "lib" + }.each do |d| + args << d + end +end + +files = [] + +args.each do |test| + if FileTest.directory?(test) + files += ruby_files(test) + end +end + +# Now load all of our files. +files.each do |file| + load file unless file =~ /^-/ +end + +runner = Test::Unit::AutoRunner.new(false) +runner.process_args +runner.run + +# $Id$ |