module Test65

Build the list of test and library files to be processed.

Process the command line arguments for the test65 program.

Process the test files.

Process the path to the test files.

Constants

DESCRIPTION
VERSION

Public Class Methods

build_file_list() click to toggle source

Find the files to be tested.

# File lib/test65/build_file_list.rb, line 5
def self.build_file_list
  if @arg_files.empty?
    scan_files
  else
    check_files
  end

  puts "Processing #{@test_files.length} test file(s)" if @options[:verbose]
end
check_files() click to toggle source

Check the list of files to be processed.

# File lib/test65/build_file_list.rb, line 26
def self.check_files
  @test_files = @arg_files.map do |file|
    std_file = file.standardize_path

    if !(found = Dir.glob(std_file)).empty?
      found.map {|subfile| File.absolute_path(file) }
    elsif !(found = Dir.glob(@options[:path] + "/" + std_file)).empty?
      found
    else
      fail "Cannot locate the file #{file}"
    end
  end.flatten
end
get_default_path() click to toggle source

Get the default test file path if one was not supplied.

# File lib/test65/process_path.rb, line 18
def self.get_default_path
  search, parent = Pathname.new(Dir.pwd), nil

  while true
    test = search.to_s + "/t65"

    if File.exists?(test)
      return test if File.directory?(test)
      fail "The file #{local_path(test)} is not a folder."
    end

    search, parent = search.parent, search

    fail "Default path not found." if search == parent
  end

end
process() click to toggle source

The code entry point. Run some 65c02 tests. Returns

0 for success
Other for failure
# File lib/test65.rb, line 34
def self.process
  process_args
  process_path
  build_file_list
  process_file_list

rescue => err
  puts "Error: #{err.to_s}"
  puts err.backtrace if @options[:debug]
  exit(1)

ensure
  # Always remove this file if it exists.
  File.delete("_kwhyit") if File.exists?("_kwhyit")
end
process_args() click to toggle source

Process the command line arguments.

# File lib/test65/process_args.rb, line 5
def self.process_args
  @options = {}

  opts = GetoptLong.new(
    ["--debug",      "-d",       GetoptLong::NO_ARGUMENT],
    ["--help",       "-h", "-?", GetoptLong::NO_ARGUMENT],
    ["--list",       "-l",       GetoptLong::NO_ARGUMENT],
    ["--map",        "-m",       GetoptLong::NO_ARGUMENT],
    ["--keep",       "-k",       GetoptLong::NO_ARGUMENT],
    ["--path",       "-p",       GetoptLong::REQUIRED_ARGUMENT],
    ["--quiet",      "-q",       GetoptLong::NO_ARGUMENT],
    ["--verbose",    "-v",       GetoptLong::NO_ARGUMENT],
    ["--version",                GetoptLong::NO_ARGUMENT])

  opts.each do |opt, arg|
    case opt
    when "--debug"
      @options[:debug] = true
    when "--help"
      puts IO.read(@gem_root + "/help.txt")
      exit
    when "--keep"
      @options[:keep] = true
    when "--list"
      @options[:list] = true
    when "--map"
      @options[:map] = true
    when "--path"
      unless @options[:path]
        @options[:path] = File.absolute_path(arg.standardize_path)
      else
        fail "Multiple path options are not allowed."
      end
    when "--quiet"
      @options[:quiet] = "2> _kwhyit"
    when "--verbose"
      @options[:verbose] = true
    when "--version"
      puts "test65 Version #{VERSION}"
      exit
    else
      fail "Invalid option: #{opt}"
    end
  end

  # A list of files to test may follow the options.
  @arg_files = ARGV

  # Setup some default paths
  @options[:gem_root]   = @gem_root
  @options[:ca65_paths] = @gem_root + "/asminc"
  @options[:cc65_home]  = @cc65_home

rescue => err
  puts "Error: #{err.to_s}"
  puts err.backtrace if @options[:debug]
  puts
  puts IO.read(@gem_root + "/help.txt")
  exit
end
process_file(file) click to toggle source

Process a file.

# File lib/test65/process_files.rb, line 21
def self.process_file(file)
  puts file.localize_path if @options[:verbose]

  case File.extname(file).downcase
  when ".c65", ".c"
    script { cc65(File.basename(file)); ld65; sim65 }

  when ".a65", ".asm"
    script { ca65(File.basename(file)); ld65; sim65 }

  when ".rb"
    load file

  else
    fail "Don't know how to process #{file}"
  end
end
process_file_list() click to toggle source

Process the list of files

# File lib/test65/process_files.rb, line 6
def self.process_file_list
  @error_count = 0

  @test_files.each do |file|
    process_file(file)
  end

  if @error_count > 0
    fail "#{@error_count} tests failed."
  else
    puts "OK: All tests passed."
  end
end
process_path() click to toggle source

Determine the path to test files.

# File lib/test65/process_path.rb, line 6
def self.process_path
  path = @options[:path] || get_default_path

  localized_path = path.localize_path
  fail "Path #{localized_path} does not exist."  unless File.exists?(path)
  fail "Path #{localized_path} is not a folder." unless File.directory?(path)
  puts "Using path: #{localized_path}" if @options[:verbose]

  @options[:path] = path
end
scan_files() click to toggle source

Scan the path for files to be processed.

# File lib/test65/build_file_list.rb, line 16
def self.scan_files
  @test_files = Dir.glob(@options[:path] + "/t65*.a65") +
                Dir.glob(@options[:path] + "/t65*.asm") +
                Dir.glob(@options[:path] + "/t65*.c65") +
                Dir.glob(@options[:path] + "/t65*.c") +
                Dir.glob(@options[:path] + "/t65*.rb")
  fail "Cannot locate any test files" if @test_files.empty?
end
script(&block) click to toggle source

Process a test script.

# File lib/test65/process_files.rb, line 40
def self.script(&block)
  test_script = TestScript.new(@options)
  test_script.instance_exec(&block)
rescue => err
  puts err
  puts err.backtrace if @options[:debug]
  @error_count += 1
ensure
  test_script.clean_up
end