test/test_cli.rb in tracksperanto-2.5.0 vs test/test_cli.rb in tracksperanto-2.6.0

- old
+ new

@@ -1,7 +1,8 @@ require File.expand_path(File.dirname(__FILE__)) + '/helper' require "set" +require "cli_test" class CliTest < Test::Unit::TestCase TEMP_DIR = File.expand_path(File.dirname(__FILE__) + "/tmp") BIN_P = File.expand_path(File.dirname(__FILE__) + "/../bin/tracksperanto") @@ -14,36 +15,22 @@ FileUtils.rm_rf(TEMP_DIR) end # Run the tracksperanto binary with passed options, and return [exit_code, stdout_content, stderr_content] def cli(commandline_arguments) - old_stdout, old_stderr, old_argv = $stdout, $stderr, ARGV.dup - os, es = StringIO.new, StringIO.new - begin - $stdout, $stderr, verbosity = os, es, $VERBOSE - ARGV.replace(commandline_arguments.split) - $VERBOSE = false - load(BIN_P) - return [0, os.string, es.string] - rescue SystemExit => boom # The binary uses exit(), we use that to preserve the output code - return [boom.status, os.string, es.string] - ensure - $VERBOSE = verbosity - ARGV.replace(old_argv) - $stdout, $stderr = old_stdout, old_stderr - end + CLITest.new(BIN_P).run(commandline_arguments) end def test_cli_with_no_args_produces_usage status, o, e = cli('') - assert_equal -1, status + assert_equal 1, status assert_match /Also use the --help option/, e end def test_cli_with_nonexisting_file status, o, e = cli(TEMP_DIR + "/nonexisting.file") - assert_equal -1, status + assert_equal 1, status assert_equal "Input file #{TEMP_DIR + "/nonexisting.file"} does not exist\n", e end def test_basic_cli status, o, e = cli(TEMP_DIR + "/flm.stabilizer") @@ -70,9 +57,16 @@ p = Tracksperanto::Import::FlameStabilizer.new(:io => File.open(TEMP_DIR + "/flm_flame.stabilizer")) items = p.to_a assert_equal 1204, p.width, "The width of the converted setup should be that" assert_equal 340, p.height, "The height of the converted setup should be that" + end + + def test_cli_trim + FileUtils.cp(File.dirname(__FILE__) + "/import/samples/flame_stabilizer/fromCombustion_fromMidClip_wSnap.stabilizer", TEMP_DIR + "/flm.stabilizer") + results = cli("--slip -8000 --trim --only flamestabilizer #{TEMP_DIR}/flm.stabilizer") + assert_not_equal 0, results[0] # status + assert_match /There were no trackers exported /, results[-1] # STDERR end # We use this instead of assert_equals for arrays since different filesystems # return files in different order def assert_same_set(expected_enum, enum, message = "Should be the same set") \ No newline at end of file