Skip to content

Commit

Permalink
Add tests to existing package (#36044)
Browse files Browse the repository at this point in the history
Adds a couple of melange tests to existing ruby packages.

Signed-off-by: Mark McCormick <[email protected]>
  • Loading branch information
mamccorm authored Dec 8, 2024
1 parent c4b1f61 commit 59c696e
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 0 deletions.
86 changes: 86 additions & 0 deletions ruby3.2-logger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,94 @@ vars:
gem: logger

test:
environment:
contents:
packages:
- ruby-${{vars.rubyMM}}
pipeline:
- runs: ruby -e "require 'logger'"
- name: Test basic logging functionality
runs: |
ruby <<-EOF
require 'logger'
require 'stringio'
# Use StringIO to capture log output
log_output = StringIO.new
logger = Logger.new(log_output)
# Test different log levels
logger.level = Logger::INFO
logger.info('Info message')
logger.error('Error message')
logger.debug('Debug message') # Shouldn't appear due to log level
log_content = log_output.string
# Verify log level filtering works
raise 'Info message not found' unless log_content.include?('Info message')
raise 'Error message not found' unless log_content.include?('Error message')
raise 'Debug message should not appear' if log_content.include?('Debug message')
# Test log formatting
raise 'Log entry missing severity' unless log_content.include?('INFO') && log_content.include?('ERROR')
raise 'Log entries should be on separate lines' unless log_content.split("\n").length >= 2
puts "Logger functionality tests passed!"
EOF
- name: Test advanced logger features
runs: |
ruby <<-EOF
require 'logger'
require 'stringio'
require 'time'
# Test custom formatter
log_output = StringIO.new
logger = Logger.new(log_output)
logger.formatter = proc do |severity, datetime, progname, msg|
"#{severity}|#{msg}\n"
end
logger.info('Custom format test')
raise 'Custom formatter failed' unless log_output.string.include?('INFO|Custom format test')
# Test progname
logger.progname = 'TestApp'
log_output.truncate(0)
log_output.rewind
logger.formatter = Logger::Formatter.new
logger.info('Program name test')
raise 'Progname not included' unless log_output.string.include?('TestApp')
# Test datetime format
logger.datetime_format = '%Y-%m-%d'
log_output.truncate(0)
log_output.rewind
logger.info('Date format test')
today = Time.now.strftime('%Y-%m-%d')
raise 'Custom datetime format failed' unless log_output.string.include?(today)
# Test log levels conversion
logger.level = :info
raise 'Symbol log level failed' unless logger.level == Logger::INFO
logger.level = 'WARN'
raise 'String log level failed' unless logger.level == Logger::WARN
# Test adding custom levels (supported in newer versions)
begin
Logger.define_singleton_method(:success) { 25 }
Logger.define_method(:success) { |progname, &block| add(Logger.success, nil, progname, &block) }
logger.success('Custom level test')
rescue => e
# Skip if custom levels not supported in this version
end
puts "Advanced logger features tests passed!"
EOF
update:
enabled: true
Expand Down
86 changes: 86 additions & 0 deletions ruby3.3-logger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,94 @@ vars:
gem: logger

test:
environment:
contents:
packages:
- ruby-${{vars.rubyMM}}
pipeline:
- runs: ruby -e "require 'logger'"
- name: Test basic logging functionality
runs: |
ruby <<-EOF
require 'logger'
require 'stringio'
# Use StringIO to capture log output
log_output = StringIO.new
logger = Logger.new(log_output)
# Test different log levels
logger.level = Logger::INFO
logger.info('Info message')
logger.error('Error message')
logger.debug('Debug message') # Shouldn't appear due to log level
log_content = log_output.string
# Verify log level filtering works
raise 'Info message not found' unless log_content.include?('Info message')
raise 'Error message not found' unless log_content.include?('Error message')
raise 'Debug message should not appear' if log_content.include?('Debug message')
# Test log formatting
raise 'Log entry missing severity' unless log_content.include?('INFO') && log_content.include?('ERROR')
raise 'Log entries should be on separate lines' unless log_content.split("\n").length >= 2
puts "Logger functionality tests passed!"
EOF
- name: Test advanced logger features
runs: |
ruby <<-EOF
require 'logger'
require 'stringio'
require 'time'
# Test custom formatter
log_output = StringIO.new
logger = Logger.new(log_output)
logger.formatter = proc do |severity, datetime, progname, msg|
"#{severity}|#{msg}\n"
end
logger.info('Custom format test')
raise 'Custom formatter failed' unless log_output.string.include?('INFO|Custom format test')
# Test progname
logger.progname = 'TestApp'
log_output.truncate(0)
log_output.rewind
logger.formatter = Logger::Formatter.new
logger.info('Program name test')
raise 'Progname not included' unless log_output.string.include?('TestApp')
# Test datetime format
logger.datetime_format = '%Y-%m-%d'
log_output.truncate(0)
log_output.rewind
logger.info('Date format test')
today = Time.now.strftime('%Y-%m-%d')
raise 'Custom datetime format failed' unless log_output.string.include?(today)
# Test log levels conversion
logger.level = :info
raise 'Symbol log level failed' unless logger.level == Logger::INFO
logger.level = 'WARN'
raise 'String log level failed' unless logger.level == Logger::WARN
# Test adding custom levels (supported in newer versions)
begin
Logger.define_singleton_method(:success) { 25 }
Logger.define_method(:success) { |progname, &block| add(Logger.success, nil, progname, &block) }
logger.success('Custom level test')
rescue => e
# Skip if custom levels not supported in this version
end
puts "Advanced logger features tests passed!"
EOF
update:
enabled: true
Expand Down

0 comments on commit 59c696e

Please sign in to comment.