smc-get 0.1.0 → 0.2.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +674 -674
- data/HISTORY.rdoc +31 -0
- data/README.rdoc +163 -148
- data/VERSION.txt +1 -1
- data/bin/smc-checksum +44 -0
- data/bin/smc-get +31 -31
- data/config/smc-get.yml +32 -32
- data/lib/smc_get.rb +23 -21
- data/lib/smc_get/cui.rb +325 -289
- data/lib/smc_get/cui_commands/build.rb +329 -0
- data/lib/smc_get/cui_commands/command.rb +117 -81
- data/lib/smc_get/cui_commands/getinfo.rb +92 -91
- data/lib/smc_get/cui_commands/help.rb +65 -64
- data/lib/smc_get/cui_commands/install.rb +101 -91
- data/lib/smc_get/cui_commands/list.rb +101 -80
- data/lib/smc_get/cui_commands/search.rb +106 -109
- data/lib/smc_get/cui_commands/uninstall.rb +80 -78
- data/lib/smc_get/cui_commands/update.rb +119 -0
- data/lib/smc_get/cui_commands/version.rb +58 -57
- data/lib/smc_get/errors.rb +140 -113
- data/lib/smc_get/gui.rb +20 -19
- data/lib/smc_get/local_repository.rb +277 -0
- data/lib/smc_get/package.rb +260 -279
- data/lib/smc_get/package_archive.rb +80 -0
- data/lib/smc_get/package_specification.rb +253 -0
- data/lib/smc_get/remote_repository.rb +272 -0
- data/lib/smc_get/repository.rb +10 -0
- data/lib/smc_get/smc_get.rb +117 -139
- data/smcpak.rdoc +332 -0
- data/test/test_smc-get-cui.rb +123 -121
- data/test/test_smc-get-lib.rb +172 -170
- metadata +71 -36
data/test/test_smc-get-cui.rb
CHANGED
@@ -1,121 +1,123 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#Encoding: UTF-8
|
3
|
-
################################################################################
|
4
|
-
# This file is part of smc-get.
|
5
|
-
# Copyright (C) 2010-2011 Entertaining Software, Inc.
|
6
|
-
# Copyright (C) 2011 Marvin Gülker
|
7
|
-
#
|
8
|
-
# This program is free software: you can redistribute it and/or modify
|
9
|
-
# it under the terms of the GNU General Public License as published by
|
10
|
-
# the Free Software Foundation, either version 3 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# This program is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
-
################################################################################
|
21
|
-
|
22
|
-
require "fileutils"
|
23
|
-
require "test/unit"
|
24
|
-
|
25
|
-
if RUBY_VERSION =~ /^1.9/
|
26
|
-
require_relative "../lib/smc_get/smc_get"
|
27
|
-
else #For 1.8 fans
|
28
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "..", "smc_get")
|
29
|
-
end
|
30
|
-
|
31
|
-
class SmcGetCUITest < Test::Unit::TestCase
|
32
|
-
#Directory from which packages are downloaded for the test.
|
33
|
-
TEST_REPO = "https://github.com/Luiji/Secret-Maryo-Chronicles-Contributed-Levels/raw/master/"
|
34
|
-
#Directory where we will download everything into. It's "testdir" right in this directory.
|
35
|
-
TEST_DIR = File.join(File.expand_path(File.dirname(__FILE__)), "testdir")
|
36
|
-
TEST_PACKAGES_DIR = File.join(TEST_DIR, "packages")
|
37
|
-
TEST_PACKAGES_MUSIC_DIR = File.join(TEST_PACKAGES_DIR, "contrib-music")
|
38
|
-
TEST_PACKAGES_GRAPHICS_DIR = File.join(TEST_PACKAGES_DIR, "contrib-graphics")
|
39
|
-
TEST_PACKAGES_LEVELS_DIR = File.join(TEST_PACKAGES_DIR, "levels")
|
40
|
-
#Test configuration file's location. Inside the test dir, so we're able to
|
41
|
-
#delete it together with everything else.
|
42
|
-
TEST_CONFIG_FILE = File.join(TEST_DIR, "testconf.yml")
|
43
|
-
|
44
|
-
#The configuration file we use for this tests.
|
45
|
-
TEST_CONFIG =<<CONFIG
|
46
|
-
---
|
47
|
-
data_directory: #{TEST_DIR}
|
48
|
-
repo_url: "https://github.com/Luiji/Secret-Maryo-Chronicles-Contributed-Levels/raw/master/"
|
49
|
-
CONFIG
|
50
|
-
|
51
|
-
#List of pacakges to install and inspect wheather they
|
52
|
-
#are correctly installed or not.
|
53
|
-
TEST_PACKAGES = %w[icy-mountain christmas-2010]
|
54
|
-
#To test wheather smc-get does know what to do in case of non-existing packages.
|
55
|
-
TEST_INVALID_PACKAGES = %w[sdhrfg jhjjjj]
|
56
|
-
|
57
|
-
TEST_SEARCH_TERMS = ["icy", "chr.stmas"]
|
58
|
-
TEST_SEARCH_TERMS_NOT_FOUND = ["dfgd", "^icy$"]
|
59
|
-
|
60
|
-
#The command to run smc-get
|
61
|
-
SMC_GET = File.join(File.expand_path(File.dirname(__FILE__)), "..", "bin", "smc-get")
|
62
|
-
|
63
|
-
#Test initialization. Write the config file and ensure the directory we
|
64
|
-
#want to download into is available. Run before EACH test.
|
65
|
-
def setup
|
66
|
-
FileUtils.mkdir_p(TEST_DIR)
|
67
|
-
File.open(TEST_CONFIG_FILE, "w"){|f| f.write(TEST_CONFIG)}
|
68
|
-
end
|
69
|
-
|
70
|
-
#Cleanup afterwards. Delete our testing directory. Run after EACH test.
|
71
|
-
def teardown
|
72
|
-
FileUtils.rm_rf(TEST_DIR)
|
73
|
-
end
|
74
|
-
|
75
|
-
#Executes <tt>smc-get str</tt> and returns true on success, false
|
76
|
-
#otherwise. Ensures the test configuration file is loaded.
|
77
|
-
def smc_get(str)
|
78
|
-
system("#{SMC_GET} -c #{TEST_CONFIG_FILE} #{str}")
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_install
|
82
|
-
TEST_PACKAGES.each do |pkg|
|
83
|
-
smc_get "install #{pkg}"
|
84
|
-
assert(File.file?(File.join(TEST_PACKAGES_DIR, "#{pkg}.yml")), "Package file not found: #{pkg}.yml.")
|
85
|
-
end
|
86
|
-
TEST_INVALID_PACKAGES.each do |pkg|
|
87
|
-
assert(!smc_get("install #{pkg}"), "Command completed on invalid packages without error.")
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_uninstall
|
92
|
-
TEST_PACKAGES.each do |pkg|
|
93
|
-
assert(!smc_get("uninstall #{pkg}"), "Uninstalled a noninstalled package successfully.")
|
94
|
-
smc_get "install #{pkg}"
|
95
|
-
smc_get "uninstall #{pkg}"
|
96
|
-
assert(!File.exists?(File.join(TEST_PACKAGES_DIR, "#{pkg}.yml")), "Found after uninstalling: #{pkg}.yml")
|
97
|
-
end
|
98
|
-
TEST_INVALID_PACKAGES.each do |pkg|
|
99
|
-
assert(!smc_get("uninstall #{pkg}"), "Uninstalled an invalid package successfully.")
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_getinfo
|
104
|
-
TEST_PACKAGES.each do |pkg|
|
105
|
-
assert(smc_get("getinfo #{pkg}"), "Couldn't retrieve info for #{pkg}.")
|
106
|
-
end
|
107
|
-
TEST_INVALID_PACKAGES.each do |pkg|
|
108
|
-
assert(!smc_get("getinfo #{pkg}"), "Retrieved info for broken package sucessfully.")
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_search
|
113
|
-
TEST_SEARCH_TERMS.each do |query|
|
114
|
-
assert(smc_get("search #{query}"), "Did not find packages it ought to find.")
|
115
|
-
end
|
116
|
-
TEST_SEARCH_TERMS_NOT_FOUND.each do |query|
|
117
|
-
assert(!smc_get("search #{query}"), "Did find packages for invalid query.")
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#Encoding: UTF-8
|
3
|
+
################################################################################
|
4
|
+
# This file is part of smc-get.
|
5
|
+
# Copyright (C) 2010-2011 Entertaining Software, Inc.
|
6
|
+
# Copyright (C) 2011 Marvin Gülker
|
7
|
+
#
|
8
|
+
# This program is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
################################################################################
|
21
|
+
|
22
|
+
require "fileutils"
|
23
|
+
require "test/unit"
|
24
|
+
|
25
|
+
if RUBY_VERSION =~ /^1.9/
|
26
|
+
require_relative "../lib/smc_get/smc_get"
|
27
|
+
else #For 1.8 fans
|
28
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "..", "smc_get")
|
29
|
+
end
|
30
|
+
|
31
|
+
class SmcGetCUITest < Test::Unit::TestCase
|
32
|
+
#Directory from which packages are downloaded for the test.
|
33
|
+
TEST_REPO = "https://github.com/Luiji/Secret-Maryo-Chronicles-Contributed-Levels/raw/master/"
|
34
|
+
#Directory where we will download everything into. It's "testdir" right in this directory.
|
35
|
+
TEST_DIR = File.join(File.expand_path(File.dirname(__FILE__)), "testdir")
|
36
|
+
TEST_PACKAGES_DIR = File.join(TEST_DIR, "packages")
|
37
|
+
TEST_PACKAGES_MUSIC_DIR = File.join(TEST_PACKAGES_DIR, "contrib-music")
|
38
|
+
TEST_PACKAGES_GRAPHICS_DIR = File.join(TEST_PACKAGES_DIR, "contrib-graphics")
|
39
|
+
TEST_PACKAGES_LEVELS_DIR = File.join(TEST_PACKAGES_DIR, "levels")
|
40
|
+
#Test configuration file's location. Inside the test dir, so we're able to
|
41
|
+
#delete it together with everything else.
|
42
|
+
TEST_CONFIG_FILE = File.join(TEST_DIR, "testconf.yml")
|
43
|
+
|
44
|
+
#The configuration file we use for this tests.
|
45
|
+
TEST_CONFIG =<<CONFIG
|
46
|
+
---
|
47
|
+
data_directory: #{TEST_DIR}
|
48
|
+
repo_url: "https://github.com/Luiji/Secret-Maryo-Chronicles-Contributed-Levels/raw/master/"
|
49
|
+
CONFIG
|
50
|
+
|
51
|
+
#List of pacakges to install and inspect wheather they
|
52
|
+
#are correctly installed or not.
|
53
|
+
TEST_PACKAGES = %w[icy-mountain christmas-2010]
|
54
|
+
#To test wheather smc-get does know what to do in case of non-existing packages.
|
55
|
+
TEST_INVALID_PACKAGES = %w[sdhrfg jhjjjj]
|
56
|
+
|
57
|
+
TEST_SEARCH_TERMS = ["icy", "chr.stmas"]
|
58
|
+
TEST_SEARCH_TERMS_NOT_FOUND = ["dfgd", "^icy$"]
|
59
|
+
|
60
|
+
#The command to run smc-get
|
61
|
+
SMC_GET = File.join(File.expand_path(File.dirname(__FILE__)), "..", "bin", "smc-get")
|
62
|
+
|
63
|
+
#Test initialization. Write the config file and ensure the directory we
|
64
|
+
#want to download into is available. Run before EACH test.
|
65
|
+
def setup
|
66
|
+
FileUtils.mkdir_p(TEST_DIR)
|
67
|
+
File.open(TEST_CONFIG_FILE, "w"){|f| f.write(TEST_CONFIG)}
|
68
|
+
end
|
69
|
+
|
70
|
+
#Cleanup afterwards. Delete our testing directory. Run after EACH test.
|
71
|
+
def teardown
|
72
|
+
FileUtils.rm_rf(TEST_DIR)
|
73
|
+
end
|
74
|
+
|
75
|
+
#Executes <tt>smc-get str</tt> and returns true on success, false
|
76
|
+
#otherwise. Ensures the test configuration file is loaded.
|
77
|
+
def smc_get(str)
|
78
|
+
system("#{SMC_GET} -c #{TEST_CONFIG_FILE} #{str}")
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_install
|
82
|
+
TEST_PACKAGES.each do |pkg|
|
83
|
+
smc_get "install #{pkg}"
|
84
|
+
assert(File.file?(File.join(TEST_PACKAGES_DIR, "#{pkg}.yml")), "Package file not found: #{pkg}.yml.")
|
85
|
+
end
|
86
|
+
TEST_INVALID_PACKAGES.each do |pkg|
|
87
|
+
assert(!smc_get("install #{pkg}"), "Command completed on invalid packages without error.")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_uninstall
|
92
|
+
TEST_PACKAGES.each do |pkg|
|
93
|
+
assert(!smc_get("uninstall #{pkg}"), "Uninstalled a noninstalled package successfully.")
|
94
|
+
smc_get "install #{pkg}"
|
95
|
+
smc_get "uninstall #{pkg}"
|
96
|
+
assert(!File.exists?(File.join(TEST_PACKAGES_DIR, "#{pkg}.yml")), "Found after uninstalling: #{pkg}.yml")
|
97
|
+
end
|
98
|
+
TEST_INVALID_PACKAGES.each do |pkg|
|
99
|
+
assert(!smc_get("uninstall #{pkg}"), "Uninstalled an invalid package successfully.")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_getinfo
|
104
|
+
TEST_PACKAGES.each do |pkg|
|
105
|
+
assert(smc_get("getinfo #{pkg}"), "Couldn't retrieve info for #{pkg}.")
|
106
|
+
end
|
107
|
+
TEST_INVALID_PACKAGES.each do |pkg|
|
108
|
+
assert(!smc_get("getinfo #{pkg}"), "Retrieved info for broken package sucessfully.")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_search
|
113
|
+
TEST_SEARCH_TERMS.each do |query|
|
114
|
+
assert(smc_get("search #{query}"), "Did not find packages it ought to find.")
|
115
|
+
end
|
116
|
+
TEST_SEARCH_TERMS_NOT_FOUND.each do |query|
|
117
|
+
assert(!smc_get("search #{query}"), "Did find packages for invalid query.")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
# vim:set ts=8 sts=2 sw=2 et: #
|
data/test/test_smc-get-lib.rb
CHANGED
@@ -1,170 +1,172 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#Encoding: UTF-8
|
3
|
-
################################################################################
|
4
|
-
# This file is part of smc-get.
|
5
|
-
# Copyright (C) 2010-2011 Entertaining Software, Inc.
|
6
|
-
# Copyright (C) 2011 Marvin Gülker
|
7
|
-
#
|
8
|
-
# This program is free software: you can redistribute it and/or modify
|
9
|
-
# it under the terms of the GNU General Public License as published by
|
10
|
-
# the Free Software Foundation, either version 3 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# This program is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
-
################################################################################
|
21
|
-
|
22
|
-
require "fileutils"
|
23
|
-
require "test/unit"
|
24
|
-
|
25
|
-
if RUBY_VERSION =~ /^1.9/
|
26
|
-
require_relative "../lib/smc_get/smc_get"
|
27
|
-
else #For 1.8 fans
|
28
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "..", "smc_get")
|
29
|
-
end
|
30
|
-
|
31
|
-
#Test case for SmcGet. If the tests defined here don't fail, everything
|
32
|
-
#works well.
|
33
|
-
class SmcGetLibraryTest < Test::Unit::TestCase
|
34
|
-
|
35
|
-
#Directory from which packages are downloaded for the test.
|
36
|
-
TEST_REPO = "https://github.com/Luiji/Secret-Maryo-Chronicles-Contributed-Levels/raw/master/"
|
37
|
-
#Directory where we will download everything into. It's "testdir" right in this directory.
|
38
|
-
TEST_DIR = File.join(File.expand_path(File.dirname(__FILE__)), "testdir")
|
39
|
-
TEST_PACKAGES_DIR = File.join(TEST_DIR, "packages")
|
40
|
-
TEST_PACKAGES_MUSIC_DIR = File.join(TEST_PACKAGES_DIR, "contrib-music")
|
41
|
-
TEST_PACKAGES_GRAPHICS_DIR = File.join(TEST_PACKAGES_DIR, "contrib-graphics")
|
42
|
-
TEST_PACKAGES_LEVELS_DIR = File.join(TEST_PACKAGES_DIR, "levels")
|
43
|
-
#Test configuration file's location. Inside the test dir, so we're able to
|
44
|
-
#delete it together with everything else.
|
45
|
-
TEST_CONFIG_FILE = File.join(TEST_DIR, "testconf.yml")
|
46
|
-
|
47
|
-
#The configuration file we use for this tests.
|
48
|
-
TEST_CONFIG =<<CONFIG
|
49
|
-
---
|
50
|
-
data-directory: #{TEST_DIR}
|
51
|
-
CONFIG
|
52
|
-
|
53
|
-
#List of pacakges to install and inspect wheather they
|
54
|
-
#are correctly installed or not.
|
55
|
-
TEST_PACKAGES = %w[icy-mountain christmas-2010]
|
56
|
-
#To test wheather smc-get does know what to do in case of non-existing packages.
|
57
|
-
TEST_INVALID_PACKAGES = %w[sdhrfg jhjjjj]
|
58
|
-
|
59
|
-
TEST_SEARCH_TERMS = ["icy", /icy/]
|
60
|
-
TEST_SEARCH_TERMS_NOT_FOUND = ["dfgd", /^nonexistant$/]
|
61
|
-
|
62
|
-
#Test initialization. Write the config file and ensure the directory we
|
63
|
-
#want to download into is available. Run before EACH test.
|
64
|
-
def setup
|
65
|
-
FileUtils.mkdir_p(TEST_DIR)
|
66
|
-
File.open(TEST_CONFIG_FILE, "w"){|f| f.write(TEST_CONFIG)}
|
67
|
-
SmcGet.setup(TEST_REPO, TEST_DIR)
|
68
|
-
end
|
69
|
-
|
70
|
-
#Cleanup afterwards. Delete our testing directory. Run after EACH test.
|
71
|
-
def teardown
|
72
|
-
FileUtils.rm_rf(TEST_DIR)
|
73
|
-
end
|
74
|
-
|
75
|
-
#Tests the library's install routine.
|
76
|
-
def test_install
|
77
|
-
TEST_PACKAGES.each do |pkg|
|
78
|
-
puts "Test installing #{pkg}"
|
79
|
-
package = SmcGet::Package.new(pkg)
|
80
|
-
package.install
|
81
|
-
|
82
|
-
assert(package.spec_file.file?, "Package config file for #{pkg} not found.")
|
83
|
-
|
84
|
-
pkg_config = YAML.load_file(package.spec_file.to_s)
|
85
|
-
|
86
|
-
Dir.chdir(TEST_DIR) do
|
87
|
-
[%w[levels levels], %w[music music/contrib-music], %w[graphics pixmaps/contrib-graphics]].each do |part, dir|
|
88
|
-
next unless pkg_config.has_key?(part)
|
89
|
-
pkg_config[part].each do |file|
|
90
|
-
assert(File.file?(File.join(dir, file)), "File not found after installing: #{file}.")
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
TEST_INVALID_PACKAGES.each do |pkg|
|
97
|
-
assert_raises(SmcGet::Errors::NoSuchPackageError){SmcGet::Package.new(pkg).install}
|
98
|
-
end
|
99
|
-
assert_equal(TEST_PACKAGES.count, SmcGet::Package.installed_packages.count)
|
100
|
-
end
|
101
|
-
|
102
|
-
#def test_incorrect_install
|
103
|
-
# #Maybe installed twice?
|
104
|
-
#end
|
105
|
-
|
106
|
-
def test_uninstall
|
107
|
-
TEST_PACKAGES.each do |pkg|
|
108
|
-
puts "Test uninstalling #{pkg}"
|
109
|
-
package = SmcGet::Package.new(pkg)
|
110
|
-
package.install #We can't uninstall a package that is not installed
|
111
|
-
|
112
|
-
pkg_config = YAML.load_file(package.spec_file)
|
113
|
-
|
114
|
-
package.uninstall
|
115
|
-
assert(!package.spec_file.exist?, "File found after uninstalling: #{package.spec_file}.")
|
116
|
-
|
117
|
-
Dir.chdir(TEST_DIR) do
|
118
|
-
[%w[levels levels], %w[music music/contrib-music], %w[graphics pixmaps/contrib-graphics]].each do |part, dir|
|
119
|
-
next unless pkg_config.has_key?(part)
|
120
|
-
pkg_config[part].each do |file|
|
121
|
-
assert(!File.exists?(File.join(dir, file)), "File found after uninstalling: #{file}.")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
TEST_INVALID_PACKAGES.each do |pkg|
|
128
|
-
assert_raises(SmcGet::Errors::NoSuchPackageError){SmcGet::Package.new(pkg).uninstall}
|
129
|
-
end
|
130
|
-
assert_equal(0, SmcGet::Package.installed_packages.count)
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_getinfo
|
134
|
-
TEST_PACKAGES.each do |pkg|
|
135
|
-
puts "Test getting info about #{pkg}"
|
136
|
-
package = SmcGet::Package.new(pkg)
|
137
|
-
package.install #We can't check specs from packages not installed
|
138
|
-
|
139
|
-
pkg_config = YAML.load_file(package.spec_file)
|
140
|
-
|
141
|
-
assert_equal(pkg_config, package.getinfo)
|
142
|
-
end
|
143
|
-
|
144
|
-
TEST_INVALID_PACKAGES.each do |pkg|
|
145
|
-
assert_raises(SmcGet::Errors::NoSuchPackageError){SmcGet::Package.new(pkg).getinfo}
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_search
|
150
|
-
TEST_SEARCH_TERMS.each do |query|
|
151
|
-
ary = SmcGet::Package.search(query)
|
152
|
-
pkg = ary[0]
|
153
|
-
assert_not_equal(0, ary.size)
|
154
|
-
|
155
|
-
pkg.install
|
156
|
-
|
157
|
-
ary = SmcGet::Package.search(query, [:pkgname], true)
|
158
|
-
assert_not_equal(0, ary.size)
|
159
|
-
|
160
|
-
pkg.uninstall
|
161
|
-
|
162
|
-
ary = SmcGet::Package.search(query, [:pkgname], true)
|
163
|
-
assert_equal(0, ary.size)
|
164
|
-
end
|
165
|
-
TEST_SEARCH_TERMS_NOT_FOUND.each do |query|
|
166
|
-
assert_equal(0, SmcGet::Package.search(query).size)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#Encoding: UTF-8
|
3
|
+
################################################################################
|
4
|
+
# This file is part of smc-get.
|
5
|
+
# Copyright (C) 2010-2011 Entertaining Software, Inc.
|
6
|
+
# Copyright (C) 2011 Marvin Gülker
|
7
|
+
#
|
8
|
+
# This program is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
################################################################################
|
21
|
+
|
22
|
+
require "fileutils"
|
23
|
+
require "test/unit"
|
24
|
+
|
25
|
+
if RUBY_VERSION =~ /^1.9/
|
26
|
+
require_relative "../lib/smc_get/smc_get"
|
27
|
+
else #For 1.8 fans
|
28
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "..", "smc_get")
|
29
|
+
end
|
30
|
+
|
31
|
+
#Test case for SmcGet. If the tests defined here don't fail, everything
|
32
|
+
#works well.
|
33
|
+
class SmcGetLibraryTest < Test::Unit::TestCase
|
34
|
+
|
35
|
+
#Directory from which packages are downloaded for the test.
|
36
|
+
TEST_REPO = "https://github.com/Luiji/Secret-Maryo-Chronicles-Contributed-Levels/raw/master/"
|
37
|
+
#Directory where we will download everything into. It's "testdir" right in this directory.
|
38
|
+
TEST_DIR = File.join(File.expand_path(File.dirname(__FILE__)), "testdir")
|
39
|
+
TEST_PACKAGES_DIR = File.join(TEST_DIR, "packages")
|
40
|
+
TEST_PACKAGES_MUSIC_DIR = File.join(TEST_PACKAGES_DIR, "contrib-music")
|
41
|
+
TEST_PACKAGES_GRAPHICS_DIR = File.join(TEST_PACKAGES_DIR, "contrib-graphics")
|
42
|
+
TEST_PACKAGES_LEVELS_DIR = File.join(TEST_PACKAGES_DIR, "levels")
|
43
|
+
#Test configuration file's location. Inside the test dir, so we're able to
|
44
|
+
#delete it together with everything else.
|
45
|
+
TEST_CONFIG_FILE = File.join(TEST_DIR, "testconf.yml")
|
46
|
+
|
47
|
+
#The configuration file we use for this tests.
|
48
|
+
TEST_CONFIG =<<CONFIG
|
49
|
+
---
|
50
|
+
data-directory: #{TEST_DIR}
|
51
|
+
CONFIG
|
52
|
+
|
53
|
+
#List of pacakges to install and inspect wheather they
|
54
|
+
#are correctly installed or not.
|
55
|
+
TEST_PACKAGES = %w[icy-mountain christmas-2010]
|
56
|
+
#To test wheather smc-get does know what to do in case of non-existing packages.
|
57
|
+
TEST_INVALID_PACKAGES = %w[sdhrfg jhjjjj]
|
58
|
+
|
59
|
+
TEST_SEARCH_TERMS = ["icy", /icy/]
|
60
|
+
TEST_SEARCH_TERMS_NOT_FOUND = ["dfgd", /^nonexistant$/]
|
61
|
+
|
62
|
+
#Test initialization. Write the config file and ensure the directory we
|
63
|
+
#want to download into is available. Run before EACH test.
|
64
|
+
def setup
|
65
|
+
FileUtils.mkdir_p(TEST_DIR)
|
66
|
+
File.open(TEST_CONFIG_FILE, "w"){|f| f.write(TEST_CONFIG)}
|
67
|
+
SmcGet.setup(TEST_REPO, TEST_DIR)
|
68
|
+
end
|
69
|
+
|
70
|
+
#Cleanup afterwards. Delete our testing directory. Run after EACH test.
|
71
|
+
def teardown
|
72
|
+
FileUtils.rm_rf(TEST_DIR)
|
73
|
+
end
|
74
|
+
|
75
|
+
#Tests the library's install routine.
|
76
|
+
def test_install
|
77
|
+
TEST_PACKAGES.each do |pkg|
|
78
|
+
puts "Test installing #{pkg}"
|
79
|
+
package = SmcGet::Package.new(pkg)
|
80
|
+
package.install
|
81
|
+
|
82
|
+
assert(package.spec_file.file?, "Package config file for #{pkg} not found.")
|
83
|
+
|
84
|
+
pkg_config = YAML.load_file(package.spec_file.to_s)
|
85
|
+
|
86
|
+
Dir.chdir(TEST_DIR) do
|
87
|
+
[%w[levels levels], %w[music music/contrib-music], %w[graphics pixmaps/contrib-graphics]].each do |part, dir|
|
88
|
+
next unless pkg_config.has_key?(part)
|
89
|
+
pkg_config[part].each do |file|
|
90
|
+
assert(File.file?(File.join(dir, file)), "File not found after installing: #{file}.")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
TEST_INVALID_PACKAGES.each do |pkg|
|
97
|
+
assert_raises(SmcGet::Errors::NoSuchPackageError){SmcGet::Package.new(pkg).install}
|
98
|
+
end
|
99
|
+
assert_equal(TEST_PACKAGES.count, SmcGet::Package.installed_packages.count)
|
100
|
+
end
|
101
|
+
|
102
|
+
#def test_incorrect_install
|
103
|
+
# #Maybe installed twice?
|
104
|
+
#end
|
105
|
+
|
106
|
+
def test_uninstall
|
107
|
+
TEST_PACKAGES.each do |pkg|
|
108
|
+
puts "Test uninstalling #{pkg}"
|
109
|
+
package = SmcGet::Package.new(pkg)
|
110
|
+
package.install #We can't uninstall a package that is not installed
|
111
|
+
|
112
|
+
pkg_config = YAML.load_file(package.spec_file)
|
113
|
+
|
114
|
+
package.uninstall
|
115
|
+
assert(!package.spec_file.exist?, "File found after uninstalling: #{package.spec_file}.")
|
116
|
+
|
117
|
+
Dir.chdir(TEST_DIR) do
|
118
|
+
[%w[levels levels], %w[music music/contrib-music], %w[graphics pixmaps/contrib-graphics]].each do |part, dir|
|
119
|
+
next unless pkg_config.has_key?(part)
|
120
|
+
pkg_config[part].each do |file|
|
121
|
+
assert(!File.exists?(File.join(dir, file)), "File found after uninstalling: #{file}.")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
TEST_INVALID_PACKAGES.each do |pkg|
|
128
|
+
assert_raises(SmcGet::Errors::NoSuchPackageError){SmcGet::Package.new(pkg).uninstall}
|
129
|
+
end
|
130
|
+
assert_equal(0, SmcGet::Package.installed_packages.count)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_getinfo
|
134
|
+
TEST_PACKAGES.each do |pkg|
|
135
|
+
puts "Test getting info about #{pkg}"
|
136
|
+
package = SmcGet::Package.new(pkg)
|
137
|
+
package.install #We can't check specs from packages not installed
|
138
|
+
|
139
|
+
pkg_config = YAML.load_file(package.spec_file)
|
140
|
+
|
141
|
+
assert_equal(pkg_config, package.getinfo)
|
142
|
+
end
|
143
|
+
|
144
|
+
TEST_INVALID_PACKAGES.each do |pkg|
|
145
|
+
assert_raises(SmcGet::Errors::NoSuchPackageError){SmcGet::Package.new(pkg).getinfo}
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_search
|
150
|
+
TEST_SEARCH_TERMS.each do |query|
|
151
|
+
ary = SmcGet::Package.search(query)
|
152
|
+
pkg = ary[0]
|
153
|
+
assert_not_equal(0, ary.size)
|
154
|
+
|
155
|
+
pkg.install
|
156
|
+
|
157
|
+
ary = SmcGet::Package.search(query, [:pkgname], true)
|
158
|
+
assert_not_equal(0, ary.size)
|
159
|
+
|
160
|
+
pkg.uninstall
|
161
|
+
|
162
|
+
ary = SmcGet::Package.search(query, [:pkgname], true)
|
163
|
+
assert_equal(0, ary.size)
|
164
|
+
end
|
165
|
+
TEST_SEARCH_TERMS_NOT_FOUND.each do |query|
|
166
|
+
assert_equal(0, SmcGet::Package.search(query).size)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
# vim:set ts=8 sts=2 sw=2 et: #
|