From b107d622445ab26f0e1cc5a2d05ac5056cac89ee Mon Sep 17 00:00:00 2001 From: Andreas Karlsson Date: Wed, 14 Jan 2026 23:58:49 +0100 Subject: [PATCH 1/5] Remove extra empty lines from test helpers These extra empty lines are pretty arbitrarily inserted and makes the readability worse so be consistent about the code style. --- spec/helpers.rb | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/spec/helpers.rb b/spec/helpers.rb index b279e0346..f8c8702e9 100644 --- a/spec/helpers.rb +++ b/spec/helpers.rb @@ -93,7 +93,6 @@ def self::included( mod ) end - # # Examples # @@ -121,7 +120,6 @@ def self::included( mod ) 'white' => 37, 'on_white' => 47 } - ############### module_function ############### @@ -143,7 +141,6 @@ def ansi_code( *attributes ) end end - ### Colorize the given +string+ with the specified +attributes+ and return it, handling ### line-endings, color reset, etc. def colorize( *args ) @@ -161,13 +158,11 @@ def colorize( *args ) return ansi_code( args.flatten ) + string + ansi_code( 'reset' ) + ending end - ### Output a message with highlighting. def message( *msg ) $stderr.puts( colorize(:bold) { msg.flatten.join(' ') } ) end - ### Output a logging message if $VERBOSE is true def trace( *msg ) return unless $VERBOSE @@ -175,13 +170,11 @@ def trace( *msg ) $stderr.puts( output ) end - ### Return the specified args as a string, quoting any that have a space. def quotelist( *args ) return args.flatten.collect {|part| part.to_s =~ /\s/ ? part.to_s.inspect : part.to_s } end - ### Run the specified command +cmd+ with system(), failing if the execution ### fails. def run( *cmd ) @@ -197,7 +190,6 @@ def run( *cmd ) raise "Command failed: [%s]" % [cmd.join(' ')] unless $?.success? end - ### Run the specified command +cmd+ after redirecting stdout and stderr to the specified ### +logpath+, failing if the execution fails. def log_and_run( logpath, *cmd ) @@ -504,7 +496,6 @@ def check_for_lingering_connections( conn ) end end - # Retrieve the names of the column types of a given result set. def result_typenames(res) @conn.exec_params( "SELECT " + res.nfields.times.map{|i| "format_type($#{i*2+1},$#{i*2+2})"}.join(","), @@ -512,7 +503,6 @@ def result_typenames(res) values[0] end - # A matcher for checking the status of a PG::Connection to ensure it's still # usable. class ConnStillUsableMatcher @@ -549,10 +539,8 @@ def failure_message def failure_message_when_negated "expected %p not to be usable, but it still is" % [ @conn ] end - end - ### Return a ConnStillUsableMatcher to be used like: ### ### expect( pg_conn ).to still_be_usable @@ -700,7 +688,6 @@ def set_etc_hosts(hostaddr, hostname) end end - RSpec.configure do |config| config.include( PG::TestingHelpers ) @@ -746,7 +733,6 @@ def set_etc_hosts(hostaddr, hostname) end end - # Do not wait for threads doing blocking calls at the process shutdown. # Instead exit immediately after printing the rspec report, if we know there are pending IO calls, which do not react on ruby interrupts. END{ From 4a79a342f54e3824638c9ed8f540b41f7fa139e7 Mon Sep 17 00:00:00 2001 From: Andreas Karlsson Date: Wed, 14 Jan 2026 23:30:31 +0100 Subject: [PATCH 2/5] Remove commented out code from test helpers This commented out code seems like it was left here by accident and that it does not provide any value for future readers. --- spec/helpers.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/spec/helpers.rb b/spec/helpers.rb index f8c8702e9..a547c22db 100644 --- a/spec/helpers.rb +++ b/spec/helpers.rb @@ -133,7 +133,6 @@ def ansi_code( *attributes ) return '' unless /(?:vt10[03]|xterm(?:-color)?|linux|screen)/i =~ ENV['TERM'] attributes = ANSI_ATTRIBUTES.values_at( *attributes ).compact.join(';') - # $stderr.puts " attr is: %p" % [attributes] if attributes.empty? return '' else @@ -411,11 +410,9 @@ def create_ca_cert(name, ca_key, x509_name, valid_years: 10) def create_key(name, rsa_size: 2048) ca_key = OpenSSL::PKey::RSA.new rsa_size - #cipher = OpenSSL::Cipher.new 'AES-128-CBC' - File.open "#{output_dir}/#{name}", 'w', 0600 do |io| io.puts ca_key.to_text - io.write ca_key.export # (cipher) + io.write ca_key.export end ca_key end From 609b80854f6f8294065c910c5ddc2f1aa14ec7ea Mon Sep 17 00:00:00 2001 From: Andreas Karlsson Date: Wed, 14 Jan 2026 23:50:07 +0100 Subject: [PATCH 3/5] Simplify log colorization test helpers The code for colorizing text was unnecessarily complex for the few callers it had. It can be simplified even further, e.g. by dropping support for having multiple attributes, but that is left for fututre cleanups. --- spec/helpers.rb | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/spec/helpers.rb b/spec/helpers.rb index a547c22db..7fdcdd4bb 100644 --- a/spec/helpers.rb +++ b/spec/helpers.rb @@ -127,46 +127,34 @@ def self::included( mod ) module Loggable ### Create a string that contains the ANSI codes specified and return it def ansi_code( *attributes ) - attributes.flatten! - attributes.collect! {|at| at.to_s } - return '' unless /(?:vt10[03]|xterm(?:-color)?|linux|screen)/i =~ ENV['TERM'] - attributes = ANSI_ATTRIBUTES.values_at( *attributes ).compact.join(';') + attrs = ANSI_ATTRIBUTES.values_at(*attributes).compact.join(';') - if attributes.empty? - return '' + if attrs.empty? + '' else - return "\e[%sm" % attributes + "\e[%sm" % attrs end end ### Colorize the given +string+ with the specified +attributes+ and return it, handling ### line-endings, color reset, etc. - def colorize( *args ) - string = '' - - if block_given? - string = yield - else - string = args.shift - end - + def colorize(attribute, string) ending = string[/(\s)$/] || '' string = string.rstrip - return ansi_code( args.flatten ) + string + ansi_code( 'reset' ) + ending + return ansi_code(attribute) + string + ansi_code('reset') + ending end ### Output a message with highlighting. def message( *msg ) - $stderr.puts( colorize(:bold) { msg.flatten.join(' ') } ) + $stderr.puts(colorize('bold', msg.flatten.join(' '))) end ### Output a logging message if $VERBOSE is true def trace( *msg ) return unless $VERBOSE - output = colorize( msg.flatten.join(' '), 'yellow' ) - $stderr.puts( output ) + $stderr.puts(colorize('yellow', msg.flatten.join(' '))) end ### Return the specified args as a string, quoting any that have a space. From e31a1dc166fb78c083e4bc7c552137f15d95a16b Mon Sep 17 00:00:00 2001 From: Andreas Karlsson Date: Wed, 14 Jan 2026 23:57:14 +0100 Subject: [PATCH 4/5] Simplify logging test helpers By making sure we always call the logging test helpers with a single string we can simplify the code for them. The only callers with a list were Loggable#run and Loggable#log_and_run. --- spec/helpers.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/helpers.rb b/spec/helpers.rb index 7fdcdd4bb..2524c4fcf 100644 --- a/spec/helpers.rb +++ b/spec/helpers.rb @@ -147,19 +147,19 @@ def colorize(attribute, string) end ### Output a message with highlighting. - def message( *msg ) - $stderr.puts(colorize('bold', msg.flatten.join(' '))) + def message(msg) + $stderr.puts(colorize('bold', msg)) end ### Output a logging message if $VERBOSE is true - def trace( *msg ) + def trace(msg) return unless $VERBOSE - $stderr.puts(colorize('yellow', msg.flatten.join(' '))) + $stderr.puts(colorize('yellow', msg)) end ### Return the specified args as a string, quoting any that have a space. def quotelist( *args ) - return args.flatten.collect {|part| part.to_s =~ /\s/ ? part.to_s.inspect : part.to_s } + args.collect {|part| part.to_s =~ /\s/ ? part.to_s.inspect : part.to_s }.join(' ') end ### Run the specified command +cmd+ with system(), failing if the execution From 4ff35188bd2698723efb70e62a8456baef83fe73 Mon Sep 17 00:00:00 2001 From: Andreas Karlsson Date: Wed, 14 Jan 2026 23:56:42 +0100 Subject: [PATCH 5/5] Simplify test helpers for running shell commands Flattening the input is not necessarily since no caller calls us with anything which needs to be flattened. --- spec/helpers.rb | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/spec/helpers.rb b/spec/helpers.rb index 2524c4fcf..65f70086e 100644 --- a/spec/helpers.rb +++ b/spec/helpers.rb @@ -165,13 +165,7 @@ def quotelist( *args ) ### Run the specified command +cmd+ with system(), failing if the execution ### fails. def run( *cmd ) - cmd.flatten! - - if cmd.length > 1 - trace( quotelist(*cmd) ) - else - trace( cmd ) - end + trace(cmd.length == 1 ? cmd.first : quotelist(*cmd)) system( *cmd ) raise "Command failed: [%s]" % [cmd.join(' ')] unless $?.success? @@ -180,13 +174,7 @@ def run( *cmd ) ### Run the specified command +cmd+ after redirecting stdout and stderr to the specified ### +logpath+, failing if the execution fails. def log_and_run( logpath, *cmd ) - cmd.flatten! - - if cmd.length > 1 - trace( quotelist(*cmd) ) - else - trace( cmd ) - end + trace(cmd.length == 1 ? cmd.first : quotelist(*cmd)) # Eliminate the noise of creating/tearing down the database by # redirecting STDERR/STDOUT to a logfile