-
Notifications
You must be signed in to change notification settings - Fork 29
/
test_cli.rb
85 lines (70 loc) · 1.95 KB
/
test_cli.rb
1
2
3
4
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
#
# @file
# @brief
# @author ongaeshi
# @date 2011/12/03
require 'milkode/cli.rb'
require 'test_helper'
require 'milkode_test_work'
class TestCLI < Test::Unit::TestCase
def setup
$stdout = StringIO.new
@first_default_dir = Dbdir.default_dir
@work = MilkodeTestWork.new({:default_db => true})
@work.add_package "db1", @work.expand_path("../data/a_project")
@orig_stdout = $stdout
end
def teardown
$stdout = @orig_stdout
@work.teardown
end
def test_grep
command("grep")
command("grep not_found")
command("grep require -a")
end
def test_mcd
assert_match /mcd/, command("mcd")
end
def test_info
# assert_match /.*packages.*records/, command("info")
assert_match /Not registered/, command("info")
end
def test_setdb_no_arg_disp
assert_equal @work.expand_path("db1") + "\n", command("setdb")
end
def test_setdb_milkode_db_dir_rewrite
open(@work.path(".milkode_db_dir"), "w") {|f| f.print "/a/custom/db" }
assert_equal "/a/custom/db\n", command("setdb")
end
def test_setdb_error_not_database_dir
assert_match(/fatal:/, command("setdb /a/write/test"))
end
def test_setdb_change
@work.init_db("db2")
assert_match "Set default db", command("setdb #{@work.path "db2"}")
end
def test_setdb_reset
assert_not_equal @first_default_dir, Dbdir.default_dir
command("setdb --reset")
assert_equal @first_default_dir, Dbdir.default_dir
end
def test_fav
command("fav")
command("fav a_not_found_package_xxxxxxx")
# command("fav package")
# command("fav -d package")
end
def test_help_with_h_option
commands = ["init", "add", "update", "remove", "list", "pwd", "cleanup", "rebuild", "dump", "dir", "setdb", "mcd", "info", "ignore", "web", "fav"]
commands.each do |cmd|
assert_match "Usage:", command("#{ cmd } -h")
end
end
private
def command(arg)
CLI.start(arg.split)
$stdout.string
end
end