test/bin/runtests in ruby-jss-2.0.0a11 vs test/bin/runtests in ruby-jss-2.0.0b1
- old
+ new
@@ -27,10 +27,44 @@
require 'pathname'
require 'getoptlong'
require 'ruby-jss'
+# Debug Trace support, Ideas from
+# https://gist.github.com/bendilley/1453a555e981ed533f68
+# and the other gist and stack overflow mentioned there.
+####################################
+
+# Enable tracing to help debug stack level too deep errors
+$do_tracing = false
+
+# set this to true to save the call traces to a file
+$save_trace = false
+
+# the file to hold the traces
+$trace_out = open('/tmp/ruby-jss-tests-trace.txt', 'w')
+
+# the max call-stack depth - adjust this to help catch and
+# debug SystemStackError exceptions
+$trace_max_call_stack_depth = 1000
+
+# the tracing proc
+set_trace_func proc { |event, file, line, id, _binding, classname|
+ if $do_tracing
+ begin
+ if event == 'call'
+ $trace_out.puts "#{file}:#{line} #{classname}##{id}" if $save_trace
+ raise 'MaxCallStackReached' if caller_locations.length > $trace_max_call_stack_depth
+ end
+ rescue => e
+ warn "ERROR: #{e.class}: #{e}"
+ e.backtrace.each { |l| warn "..#{l}" }
+ exit 1
+ end
+ end # if
+}
+
# app
class App
TEST_MODULE_FILE_SUFFIX = '.rb'
@@ -60,12 +94,12 @@
@appdir = @bindir.parent
@libdir = @appdir + 'lib'
@testsdir = @appdir + 'tests'
@tests_to_run = ARGV.dup
- @tests_to_run = @testsdir.children.map { |c| c.basename.to_s }.sort if @tests_to_run .empty?
- @tests_to_run.delete_if { |t| t.start_with? '.'}
+ @tests_to_run = @testsdir.children.map { |c| c.basename.to_s }.sort if @tests_to_run.empty?
+ @tests_to_run.delete_if { |t| t.start_with? '.' }
@minitest_opts = ['--verbose']
helper_module = @libdir + 'jamf_test.rb'
load helper_module.to_s
@@ -124,10 +158,11 @@
JamfTest::Auth.connect_to_api host: @api_server, port: @api_port
end
###################################
def run_tests
+ puts
JamfTest.say "Starting tests of ruby-jss v#{Jamf::VERSION}, using ruby version #{RUBY_VERSION}"
JamfTest.say "API Connection: #{Jamf.cnx}; Server running Jamf Pro #{Jamf.cnx.jamf_version}"
@tests_to_run.each do |t|
t = t.chomp TEST_MODULE_FILE_SUFFIX
@@ -156,10 +191,11 @@
# display help if asked
###################################
def show_help
return false unless @show_help
+
puts <<-USAGEBLURB
Usage: #{File.basename __FILE__} [options] [spec [spec ...]]
Runs one or more specification tests of ruby-jss.
@@ -207,9 +243,13 @@
if $PROGRAM_NAME == __FILE__
begin
app = App.new
app.run
exit 0
+ rescue SystemStackError
+ puts $!
+ puts caller[0..100]
+ exit 1
rescue => e
puts "ERROR #{e.class}: #{e}"
puts e.backtrace
exit 1
end # begin