Module: Test65

Defined in:
lib/test65/process_args.rb,
lib/test65.rb,
lib/test65/version.rb,
lib/test65/process_path.rb,
lib/test65/process_files.rb,
lib/test65/build_file_list.rb

Overview

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

Constant Summary collapse

VERSION =
"0.6.0".freeze
DESCRIPTION =
"test65: A testing framework for ca65.".freeze

Class Method Summary collapse

Class Method Details

.build_file_listObject

Find the files to be tested.



5
6
7
8
9
10
11
12
13
# 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_filesObject

Check the list of files to be processed.



26
27
28
29
30
31
32
33
34
35
36
37
38
# 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_pathObject

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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

.processObject

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

0 for success
Other for failure


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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_argsObject

Process the command line arguments.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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) ⇒ Object

Process a file.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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_listObject

Process the list of files



6
7
8
9
10
11
12
13
14
15
16
17
18
# 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_pathObject

Determine the path to test files.



6
7
8
9
10
11
12
13
14
15
# 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_filesObject

Scan the path for files to be processed.



16
17
18
19
20
21
22
23
# 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) ⇒ Object

Process a test script.



40
41
42
43
44
45
46
47
48
49
# 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