#!/usr/bin/ruby
#
# NAME
#   symbiosis-test - Test systems' functionality running under Symbiosis
#
# SYNOPSIS
#   symbiosis-test [ --help ] [ --manual ] [ --verbose ] [directory]
#
# OPTIONS
#  --help        Show a brief help message.
#
#  --manual       Show the full manual.
#
#  --verbose      Show debugging information.
#
# USAGE
# 
# This program runs all the tests in a given directory, defaulting to
# /etc/symbiosis/test.d.
#
# AUTHOR
#
#  Patrick J. Cherry <patrick@bytemark.co.uk>
#


#
#  Run all tests.
#


require 'getoptlong'

help = manual = false

opts = GetoptLong.new(
         [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
         [ '--manual', '-m', GetoptLong::NO_ARGUMENT ],
         [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ]
       )

opts.each do |opt, arg|
  case opt
  when '--help'
    help = true
  when '--manual'
    manual = true
  when '--verbose'
    $VERBOSE = true
  end
end

#
# Output help as required.
#
if help or manual
  require 'symbiosis/utils'
  Symbiosis::Utils.show_help(__FILE__) if help
  Symbiosis::Utils.show_manual(__FILE__) if manual
  exit 0
end

#
# This require is here to allow manpage generation without it.
#
require 'test/unit'
require 'fileutils'

if ARGV.empty?
  dir = '/etc/symbiosis/test.d'
else
  dir = File.expand_path(ARGV.shift)
end

FileUtils.chdir(dir)

#
# Add the test directory to the load path
#
$LOAD_PATH << dir

Dir.glob(File.join(dir,"t*.rb")).each do |test|
  require test
end

