Sha256: ea8e3fbcf1181ab0f6bbe27254dba743e540943d647102a9cf6bfa4528d2dd72

Contents?: true

Size: 1.5 KB

Versions: 4

Compression:

Stored size: 1.5 KB

Contents

#!/usr/bin/env ruby
require 'test/unit'
require 'stringio'
require 'tempfile'
require_relative '../../app/options'

# To have something to work with.
load 'tmpdir.rb'

class TestAppStringIO < Test::Unit::TestCase
  include Trepanning

  def setup
    @options = DEFAULT_CMDLINE_SETTINGS.clone
    @stderr  = StringIO.new
    @stdout  = StringIO.new
    @options = copy_default_options
    @opts = setup_options(@options, @stdout, @stderr)
  end

  def test_cd
    rest = @opts.parse(['--cd', Dir.tmpdir])
    assert_equal(Dir.tmpdir, @options[:chdir])
    assert_equal('', @stderr.string)
    assert_equal('', @stdout.string)

    setup
    tf    = Tempfile.new("delete-me")
    orig_cd = @options[:chdir]
    rest = @opts.parse(['--cd', tf.path])
    assert_equal(orig_cd, @options[:chdir])
    assert_not_equal('', @stderr.string)
    assert_equal('', @stdout.string)
    # FIXME: add test where directory isn't executable.
  end

  def test_binary_opts
    %w(nx).each do |name|
      setup
      o    = ["--#{name}"]
      rest = @opts.parse o
      assert_equal('', @stderr.string)
      assert_equal(true, @options[name.to_sym])
    end
  end

  def test_help_and_version_opts
    %w(help version).each do |name|
      setup
      o    = ["--#{name}"]
      rest = @opts.parse o
      assert_not_equal('', @stdout.string)
      assert_equal('', @stderr.string)
      assert_equal(true, @options[name.to_sym])
      other_sym = 'help' == name ? :version : :help
      assert_equal(false, @options.member?(other_sym))
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
trepanning-0.0.9 test/unit/test-app-options.rb
trepanning-0.0.8 test/unit/test-app-options.rb
trepanning-0.0.6 test/unit/test-app-options.rb
trepanning-0.0.4 test/unit/test-app-options.rb