test/tc_easylog.rb in eymiha_util-1.0.1 vs test/tc_easylog.rb in eymiha_util-1.0.2
- old
+ new
@@ -17,39 +17,239 @@
log_debug "logging"
assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* DEBUG logging \(TC_log\)/ =~
log.string)
end
+ def test_level_debug
+ log = StringIO.new
+ start_logging log
+ log_level_fatal
+ log_debug "logging"
+ assert("" == log.string)
+ log_level_error
+ log_debug "logging"
+ assert("" == log.string)
+ log_level_warn
+ log_debug "logging"
+ assert("" == log.string)
+ log_level_info
+ log_debug "logging"
+ assert("" == log.string)
+ log_level_debug
+ log_debug "logging"
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* DEBUG logging \(TC_log\)/ =~
+ log.string)
+ end
+
+ def test_level_debug?
+ start_logging StringIO.new
+ log_level_debug
+ assert(log_fatal? == true)
+ assert(log_error? == true)
+ assert(log_warn? == true)
+ assert(log_info? == true)
+ assert(log_debug? == true)
+ end
+
def test_info
log = StringIO.new
start_logging log
log_info "logging"
assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* INFO logging \(TC_log\)/ =~
log.string)
end
+ def test_level_info
+ log = StringIO.new
+ start_logging log
+ log_level_fatal
+ log_info "logging"
+ assert("" == log.string)
+ log_level_error
+ log_info "logging"
+ assert("" == log.string)
+ log_level_warn
+ log_info "logging"
+ assert("" == log.string)
+ log_level_info
+ log_info "logging"
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* INFO logging \(TC_log\)/ =~
+ log.string)
+ debug_log = StringIO.new
+ start_logging debug_log
+ log_level_debug
+ log_info "logging"
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* INFO logging \(TC_log\)/ =~
+ debug_log.string)
+ end
+
+ def test_level_info?
+ start_logging StringIO.new
+ log_level_info
+ assert(log_fatal? == true)
+ assert(log_error? == true)
+ assert(log_warn? == true)
+ assert(log_info? == true)
+ assert(log_debug? == false)
+ end
+
def test_warn
log = StringIO.new
start_logging log
log_warn "logging"
assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* WARN logging \(TC_log\)/ =~
log.string)
end
+ def test_level_warn
+ log = StringIO.new
+ start_logging log
+ log_level_fatal
+ log_warn "logging"
+ assert("" == log.string)
+ log_level_error
+ log_warn "logging"
+ assert("" == log.string)
+ log_level_warn
+ log_warn "logging"
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* WARN logging \(TC_log\)/ =~
+ log.string)
+ info_log = StringIO.new
+ start_logging info_log
+ log_level_info
+ log_warn "logging"
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* WARN logging \(TC_log\)/ =~
+ info_log.string)
+ debug_log = StringIO.new
+ start_logging debug_log
+ log_level_debug
+ log_warn "logging"
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* WARN logging \(TC_log\)/ =~
+ debug_log.string)
+ end
+
+ def test_level_warn?
+ start_logging StringIO.new
+ log_level_warn
+ assert(log_fatal? == true)
+ assert(log_error? == true)
+ assert(log_warn? == true)
+ assert(log_info? == false)
+ assert(log_debug? == false)
+ end
+
def test_error
log = StringIO.new
start_logging log
log_error "logging"
assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* ERROR logging \(TC_log\)/ =~
log.string)
end
+ def test_level_error
+ log = StringIO.new
+ start_logging log
+ log_level_fatal
+ log_error "logging"
+ assert("" == log.string)
+ log_level_error
+ log_error "logging"
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* ERROR logging \(TC_log\)/ =~
+ log.string)
+ warn_log = StringIO.new
+ start_logging warn_log
+ log_level_warn
+ log_error "logging"
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* ERROR logging \(TC_log\)/ =~
+ warn_log.string)
+ info_log = StringIO.new
+ start_logging info_log
+ log_level_info
+ log_error "logging"
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* ERROR logging \(TC_log\)/ =~
+ info_log.string)
+ debug_log = StringIO.new
+ start_logging debug_log
+ log_level_debug
+ log_error "logging"
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* ERROR logging \(TC_log\)/ =~
+ debug_log.string)
+ end
+
+ def test_level_error?
+ start_logging StringIO.new
+ log_level_error
+ assert(log_fatal? == true)
+ assert(log_error? == true)
+ assert(log_warn? == false)
+ assert(log_info? == false)
+ assert(log_debug? == false)
+ end
+
def test_fatal
log = StringIO.new
start_logging log
log_fatal "logging"
assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* FATAL logging \(TC_log\)/ =~
log.string)
+ end
+
+ def test_level_fatal
+ log = StringIO.new
+ start_logging log
+ log_level_fatal
+ log_fatal "logging"
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* FATAL logging \(TC_log\)/ =~
+ log.string)
+ error_log = StringIO.new
+ start_logging error_log
+ log_level_error
+ log_fatal "logging"
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* FATAL logging \(TC_log\)/ =~
+ error_log.string)
+ warn_log = StringIO.new
+ start_logging warn_log
+ log_level_warn
+ log_fatal "logging"
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* FATAL logging \(TC_log\)/ =~
+ warn_log.string)
+ info_log = StringIO.new
+ start_logging info_log
+ log_level_info
+ log_fatal "logging"
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* FATAL logging \(TC_log\)/ =~
+ info_log.string)
+ debug_log = StringIO.new
+ start_logging debug_log
+ log_level_debug
+ log_fatal "logging"
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* FATAL logging \(TC_log\)/ =~
+ debug_log.string)
+ end
+
+ def test_level_fatal?
+ start_logging StringIO.new
+ log_level_fatal
+ assert(log_fatal? == true)
+ assert(log_error? == false)
+ assert(log_warn? == false)
+ assert(log_info? == false)
+ assert(log_debug? == false)
+ end
+
+ def test_empty_message
+ log = StringIO.new
+ start_logging log
+ log_info
+ assert("" == log.string.chomp)
+ end
+
+ def test_nearly_empty_message
+ log = StringIO.new
+ start_logging log
+ log_info(" ")
+ assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* INFO / =~
+ log.string.chomp)
end
def test_easylogger_instance
log1 = StringIO.new
logger1 = EasyLogger.new(log1)