summaryrefslogtreecommitdiffstats
path: root/test/util/classgen.rb
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
commit3180b9d9b2c844dade1d361326600f7001ec66dd (patch)
tree98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /test/util/classgen.rb
parent543225970225de5697734bfaf0a6eee996802c04 (diff)
downloadpuppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
Diffstat (limited to 'test/util/classgen.rb')
-rwxr-xr-xtest/util/classgen.rb340
1 files changed, 170 insertions, 170 deletions
diff --git a/test/util/classgen.rb b/test/util/classgen.rb
index 83b64813c..5560764d5 100755
--- a/test/util/classgen.rb
+++ b/test/util/classgen.rb
@@ -6,236 +6,236 @@ require 'puppet'
require 'puppettest'
class TestPuppetUtilClassGen < Test::Unit::TestCase
- include PuppetTest
+ include PuppetTest
- class FakeBase
- class << self
- attr_accessor :name
- end
+ class FakeBase
+ class << self
+ attr_accessor :name
end
+ end
- class GenTest
- class << self
- include Puppet::Util::ClassGen
- end
+ class GenTest
+ class << self
+ include Puppet::Util::ClassGen
end
+ end
- def testclasses(name)
- sub = Class.new(GenTest) do @name = "base#{name.to_s}" end
- self.class.const_set("Base#{name.to_s}", sub)
+ def testclasses(name)
+ sub = Class.new(GenTest) do @name = "base#{name.to_s}" end
+ self.class.const_set("Base#{name.to_s}", sub)
- klass = Class.new(FakeBase) do @name = "gen#{name.to_s}"end
+ klass = Class.new(FakeBase) do @name = "gen#{name.to_s}"end
- return sub, klass
- end
+ return sub, klass
+ end
- def test_handleclassconst
- sub, klass = testclasses("const")
- const = nil
- assert_nothing_raised do
- const = sub.send(:handleclassconst, klass, klass.name, {})
- end
+ def test_handleclassconst
+ sub, klass = testclasses("const")
+ const = nil
+ assert_nothing_raised do
+ const = sub.send(:handleclassconst, klass, klass.name, {})
+ end
- # make sure the constant is set
- assert(defined?(Baseconst::Genconst), "const was not defined")
- assert_equal(Baseconst::Genconst.object_id, klass.object_id)
+ # make sure the constant is set
+ assert(defined?(Baseconst::Genconst), "const was not defined")
+ assert_equal(Baseconst::Genconst.object_id, klass.object_id)
- # Now make sure don't replace by default
- newklass = Class.new(FakeBase) do @name = klass.name end
- assert_raise(Puppet::ConstantAlreadyDefined) do
- const = sub.send(:handleclassconst, newklass, klass.name, {})
- end
- assert_equal(Baseconst::Genconst.object_id, klass.object_id)
+ # Now make sure don't replace by default
+ newklass = Class.new(FakeBase) do @name = klass.name end
+ assert_raise(Puppet::ConstantAlreadyDefined) do
+ const = sub.send(:handleclassconst, newklass, klass.name, {})
+ end
+ assert_equal(Baseconst::Genconst.object_id, klass.object_id)
- # Now make sure we can replace it
- assert_nothing_raised do
- const = sub.send(:handleclassconst, newklass, klass.name, :overwrite => true)
- end
- assert_equal(Baseconst::Genconst.object_id, newklass.object_id)
+ # Now make sure we can replace it
+ assert_nothing_raised do
+ const = sub.send(:handleclassconst, newklass, klass.name, :overwrite => true)
+ end
+ assert_equal(Baseconst::Genconst.object_id, newklass.object_id)
- # Now make sure we can choose our own constant
- assert_nothing_raised do
+ # Now make sure we can choose our own constant
+ assert_nothing_raised do
- const = sub.send(
- :handleclassconst, newklass, klass.name,
+ const = sub.send(
+ :handleclassconst, newklass, klass.name,
- :constant => "Fooness")
- end
- assert(defined?(Baseconst::Fooness), "Specified constant was not defined")
+ :constant => "Fooness")
+ end
+ assert(defined?(Baseconst::Fooness), "Specified constant was not defined")
- # And make sure prefixes work
- assert_nothing_raised do
+ # And make sure prefixes work
+ assert_nothing_raised do
- const = sub.send(
- :handleclassconst, newklass, klass.name,
+ const = sub.send(
+ :handleclassconst, newklass, klass.name,
- :prefix => "Test")
- end
- assert(defined?(Baseconst::TestGenconst), "prefix was not used")
+ :prefix => "Test")
end
+ assert(defined?(Baseconst::TestGenconst), "prefix was not used")
+ end
- def test_initclass_preinit
- sub, klass = testclasses("preinit")
+ def test_initclass_preinit
+ sub, klass = testclasses("preinit")
- class << klass
- attr_accessor :set
- def preinit
- @set = true
- end
- end
+ class << klass
+ attr_accessor :set
+ def preinit
+ @set = true
+ end
+ end
- assert(!klass.set, "Class was already initialized")
+ assert(!klass.set, "Class was already initialized")
- assert_nothing_raised do sub.send(:initclass, klass, {}) end
+ assert_nothing_raised do sub.send(:initclass, klass, {}) end
- assert(klass.set, "Class was not initialized")
- end
+ assert(klass.set, "Class was not initialized")
+ end
- def test_initclass_initvars
- sub, klass = testclasses("initvars")
+ def test_initclass_initvars
+ sub, klass = testclasses("initvars")
- class << klass
- attr_accessor :set
- def initvars
- @set = true
- end
- end
+ class << klass
+ attr_accessor :set
+ def initvars
+ @set = true
+ end
+ end
- assert(!klass.set, "Class was already initialized")
+ assert(!klass.set, "Class was already initialized")
- assert_nothing_raised do sub.send(:initclass, klass, {}) end
+ assert_nothing_raised do sub.send(:initclass, klass, {}) end
- assert(klass.set, "Class was not initialized")
- end
+ assert(klass.set, "Class was not initialized")
+ end
- def test_initclass_attributes
- sub, klass = testclasses("attributes")
+ def test_initclass_attributes
+ sub, klass = testclasses("attributes")
- class << klass
- attr_accessor :one, :two, :three
- end
+ class << klass
+ attr_accessor :one, :two, :three
+ end
- assert(!klass.one, "'one' was already set")
+ assert(!klass.one, "'one' was already set")
- assert_nothing_raised do sub.send(
- :initclass, klass,
+ assert_nothing_raised do sub.send(
+ :initclass, klass,
- :attributes => {:one => :a, :two => :b}) end
+ :attributes => {:one => :a, :two => :b}) end
- assert_equal(:a, klass.one, "Class was initialized incorrectly")
- assert_equal(:b, klass.two, "Class was initialized incorrectly")
- assert_nil(klass.three, "Class was initialized incorrectly")
- end
+ assert_equal(:a, klass.one, "Class was initialized incorrectly")
+ assert_equal(:b, klass.two, "Class was initialized incorrectly")
+ assert_nil(klass.three, "Class was initialized incorrectly")
+ end
- def test_initclass_include_and_extend
- sub, klass = testclasses("include_and_extend")
+ def test_initclass_include_and_extend
+ sub, klass = testclasses("include_and_extend")
- incl = Module.new do
- attr_accessor :included
- end
- self.class.const_set("Incl", incl)
+ incl = Module.new do
+ attr_accessor :included
+ end
+ self.class.const_set("Incl", incl)
- ext = Module.new do
- attr_accessor :extended
- end
- self.class.const_set("Ext", ext)
+ ext = Module.new do
+ attr_accessor :extended
+ end
+ self.class.const_set("Ext", ext)
- assert(! klass.respond_to?(:extended), "Class already responds to extended")
- assert(! klass.new.respond_to?(:included), "Class already responds to included")
+ assert(! klass.respond_to?(:extended), "Class already responds to extended")
+ assert(! klass.new.respond_to?(:included), "Class already responds to included")
- assert_nothing_raised do sub.send(
- :initclass, klass,
+ assert_nothing_raised do sub.send(
+ :initclass, klass,
- :include => incl, :extend => ext)
- end
-
- assert(klass.respond_to?(:extended), "Class did not get extended")
- assert(klass.new.respond_to?(:included), "Class did not include")
+ :include => incl, :extend => ext)
end
- def test_genclass
- hash = {}
- array = []
+ assert(klass.respond_to?(:extended), "Class did not get extended")
+ assert(klass.new.respond_to?(:included), "Class did not include")
+ end
- name = "yayness"
- klass = nil
- assert_nothing_raised {
- klass = GenTest.genclass(name, :array => array, :hash => hash, :parent => FakeBase) do
- class << self
- attr_accessor :name
- end
- end
- }
+ def test_genclass
+ hash = {}
+ array = []
- assert(klass.respond_to?(:name=), "Class did not execute block")
+ name = "yayness"
+ klass = nil
+ assert_nothing_raised {
+ klass = GenTest.genclass(name, :array => array, :hash => hash, :parent => FakeBase) do
+ class << self
+ attr_accessor :name
+ end
+ end
+ }
+
+ assert(klass.respond_to?(:name=), "Class did not execute block")
- assert(
- hash.include?(klass.name),
+ assert(
+ hash.include?(klass.name),
- "Class did not get added to hash")
+ "Class did not get added to hash")
- assert(
- array.include?(klass),
+ assert(
+ array.include?(klass),
- "Class did not get added to array")
- assert_equal(klass.superclass, FakeBase, "Parent class was wrong")
+ "Class did not get added to array")
+ assert_equal(klass.superclass, FakeBase, "Parent class was wrong")
+ end
+
+ # Make sure we call a preinithook, if there is one.
+ def test_inithooks
+ newclass = Class.new(FakeBase) do
+ class << self
+ attr_accessor :preinited, :postinited
+ end
+ def self.preinit
+ self.preinited = true
+ end
+ def self.postinit
+ self.postinited = true
+ end
end
- # Make sure we call a preinithook, if there is one.
- def test_inithooks
- newclass = Class.new(FakeBase) do
- class << self
- attr_accessor :preinited, :postinited
- end
- def self.preinit
- self.preinited = true
- end
- def self.postinit
- self.postinited = true
- end
- end
+ klass = nil
+ assert_nothing_raised {
+ klass = GenTest.genclass(:funtest, :parent => newclass)
+ }
- klass = nil
- assert_nothing_raised {
- klass = GenTest.genclass(:funtest, :parent => newclass)
- }
-
- assert(klass.preinited, "prehook did not get called")
- assert(klass.postinited, "posthook did not get called")
- end
+ assert(klass.preinited, "prehook did not get called")
+ assert(klass.postinited, "posthook did not get called")
+ end
- def test_modulegen
- hash = {}
- array = []
+ def test_modulegen
+ hash = {}
+ array = []
- name = "modness"
- mod = nil
- assert_nothing_raised {
- mod = GenTest.genmodule(name, :array => array, :hash => hash) do
- class << self
- attr_accessor :yaytest
- end
+ name = "modness"
+ mod = nil
+ assert_nothing_raised {
+ mod = GenTest.genmodule(name, :array => array, :hash => hash) do
+ class << self
+ attr_accessor :yaytest
+ end
- @yaytest = true
- end
- }
+ @yaytest = true
+ end
+ }
- assert(mod.respond_to?(:yaytest), "Class did not execute block")
+ assert(mod.respond_to?(:yaytest), "Class did not execute block")
- assert_instance_of(Module, mod)
- assert(hash.include?(mod.name), "Class did not get added to hash")
- assert(array.include?(mod), "Class did not get added to array")
- end
+ assert_instance_of(Module, mod)
+ assert(hash.include?(mod.name), "Class did not get added to hash")
+ assert(array.include?(mod), "Class did not get added to array")
+ end
- def test_genconst_string
- const = nil
- assert_nothing_raised do
- const = GenTest.send(:genconst_string, :testing, :prefix => "Yayness")
- end
- assert_equal("YaynessTesting", const)
+ def test_genconst_string
+ const = nil
+ assert_nothing_raised do
+ const = GenTest.send(:genconst_string, :testing, :prefix => "Yayness")
end
+ assert_equal("YaynessTesting", const)
+ end
end