Permalink
Browse files

Adding tests for the DSL configurator.

  • Loading branch information...
1 parent 000c1bf commit 6c66ea5d3c77a9a88cfdfc9e179bcd2b41087866 @TwP committed Jul 17, 2008
View
@@ -0,0 +1,13 @@
+
+Logging.configure {
+
+ logger(:root) {
+ level :info
+ appenders 'bad'
+ }
+
+ appender('bad') {
+ type 'FooBar'
+ }
+
+} # logging configuration
View
@@ -0,0 +1,21 @@
+
+Logging.configure {
+
+ logger(:root) {
+ level :info
+ appenders 'logfile'
+ }
+
+ appender('logfile') {
+ type 'File'
+ level 'DEB'
+ filename 'tmp/temp.log'
+ truncate true
+ layout {
+ type 'BadLayout'
+ date_method 'to_s'
+ pattern '[%d] %l %c : %m\n'
+ }
+ }
+
+} # logging configuration
View
@@ -0,0 +1,13 @@
+
+Logging.configure {
+
+ logger(:root) {
+ level :info
+ appenders 'stdout'
+ }
+
+ appender('stdout') {
+ type 'Stdout'
+ }
+
+} # logging configuration
View
@@ -234,15 +234,15 @@ def version
# <tt>File.join</tt>.
#
def libpath( *args )
- args.empty? ? LIBPATH : ::File.join(LIBPATH, *args)
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
end
# Returns the lpath for the module. If any arguments are given,
# they will be joined to the end of the path using
# <tt>File.join</tt>.
#
def path( *args )
- args.empty? ? PATH : ::File.join(PATH, *args)
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
end
# Utility method used to rquire all files ending in .rb that lie in the
View
@@ -1,4 +1,3 @@
-# $Id$
require 'thread'
@@ -1,4 +1,3 @@
-# $Id$
require Logging.libpath(*%w[logging appenders io])
@@ -1,4 +1,3 @@
-# $Id$
require 'net/smtp'
require 'time' # get rfc822 time format
@@ -1,4 +1,3 @@
-# $Id$
module Logging::Appenders
@@ -1,4 +1,3 @@
-# $Id$
module Logging::Appenders
@@ -1,4 +1,3 @@
-# $Id$
module Logging::Appenders
@@ -1,4 +1,3 @@
-# $Id$
require 'lockfile'
@@ -1,4 +1,3 @@
-# $Id$
begin
require 'syslog'
@@ -94,7 +94,7 @@ def load( &block )
#
def pre_config( config )
if config.nil?
- ::Logging.init unless defined?(::Logging::MAX_LEVEL_LENGTH)
+ ::Logging.init unless ::Logging.const_defined? 'MAX_LEVEL_LENGTH'
return
end
@@ -149,7 +149,7 @@ def appender( name, config )
type = config.delete(:type)
raise Error, "appender type not given for #{name.inspect}" if type.nil?
- config[:layout] = layout(config.delete(:layout))
+ config[:layout] = layout(config[:layout]) if config.has_key? :layout
clazz = ::Logging::Appenders.const_get type
clazz.new(name, config)
@@ -166,7 +166,7 @@ def appender( name, config )
# initializer.
#
def layout( config )
- return if config.nil?
+ return ::Logging::Layouts::Basic.new if config.nil?
type = config.delete(:type)
raise Error, 'layout type not given' if type.nil?
View
@@ -1,4 +1,3 @@
-# $Id$
require 'yaml'
@@ -1,4 +1,3 @@
-# $Id$
module Logging
module Layouts
@@ -1,4 +1,3 @@
-# $Id$
module Logging
module Layouts
View
@@ -1,4 +1,3 @@
-# $Id$
module Logging
@@ -1,4 +1,3 @@
-# $Id$
module Logging
View
@@ -1,4 +1,3 @@
-# $Id$
class Hash
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[.. setup])
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[.. setup])
require 'flexmock'
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[.. setup])
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[.. setup])
require 'flexmock'
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[.. setup])
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[.. setup])
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[.. setup])
View
@@ -1,4 +1,3 @@
-# $Id$
begin
require 'logging'
@@ -0,0 +1,70 @@
+
+require File.join(File.dirname(__FILE__), %w[.. setup])
+
+module TestLogging
+module TestConfig
+
+ class TestConfigurator < Test::Unit::TestCase
+ include LoggingTestCase
+
+ def test_configuration
+ begin
+ load Logging.path(%w[data logging.rb])
+ rescue Exception => err
+ flunk err.inspect
+ end
+
+ levels = {
+ 'deb' => 0,
+ 'inf' => 1,
+ 'prt' => 2,
+ 'wrn' => 3,
+ 'err' => 4,
+ 'fat' => 5
+ }
+ assert_equal levels, Logging::LEVELS
+ assert_equal :inspect, Logging::OBJ_FORMAT
+
+ hash = Logging::Repository.instance.instance_variable_get(:@h)
+ assert hash.has_key?('A::B::C')
+ assert hash.has_key?('yourlogger')
+ end
+
+ def test_simple_configuration
+ begin
+ load Logging.path(%w[data simple_logging.rb])
+ rescue Exception => err
+ flunk err.inspect
+ end
+
+ levels = {
+ 'debug' => 0,
+ 'info' => 1,
+ 'warn' => 2,
+ 'error' => 3,
+ 'fatal' => 4
+ }
+ assert_equal levels, Logging::LEVELS
+ assert_equal false, Logging.const_defined?('OBJ_FORMAT')
+
+ root = Logging::Logger.root
+ assert_equal 1, root.level
+ end
+
+ def test_bad_appender_configuration
+ assert_raise(Logging::Config::Configurator::Error) {
+ load Logging.path(%w[data bad_logging_1.rb])
+ }
+ end
+
+ def test_bad_layout_configuration
+ assert_raise(Logging::Config::Configurator::Error) {
+ load Logging.path(%w[data bad_logging_2.rb])
+ }
+ end
+ end
+
+end # module TestConfig
+end # module TestLogging
+
+# EOF
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[.. setup])
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[.. setup])
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[.. setup])
View
@@ -1,4 +1,3 @@
-# $Id$
# Equivalent to a header guard in C/C++
# Used to prevent the class/module from being loaded more than once
View
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[setup])
View
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[setup])
View
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[setup])
View
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[setup])
View
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[setup])
View
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[setup])
View
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[setup])
View
@@ -1,4 +1,3 @@
-# $Id$
require File.join(File.dirname(__FILE__), %w[setup])

0 comments on commit 6c66ea5

Please sign in to comment.