diff options
Diffstat (limited to 'spec/test_spec.lua')
| -rw-r--r-- | spec/test_spec.lua | 173 |
1 files changed, 0 insertions, 173 deletions
diff --git a/spec/test_spec.lua b/spec/test_spec.lua index 4be0567f..194dcfd1 100644 --- a/spec/test_spec.lua +++ b/spec/test_spec.lua | |||
| @@ -1,12 +1,9 @@ | |||
| 1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
| 2 | local lfs = require("lfs") | 2 | local lfs = require("lfs") |
| 3 | local get_tmp_path = test_env.get_tmp_path | ||
| 4 | local run = test_env.run | 3 | local run = test_env.run |
| 5 | local testing_paths = test_env.testing_paths | 4 | local testing_paths = test_env.testing_paths |
| 6 | local write_file = test_env.write_file | 5 | local write_file = test_env.write_file |
| 7 | 6 | ||
| 8 | test_env.unload_luarocks() | ||
| 9 | |||
| 10 | local extra_rocks = { | 7 | local extra_rocks = { |
| 11 | "/busted-2.0.0-1.rockspec", | 8 | "/busted-2.0.0-1.rockspec", |
| 12 | "/lua_cliargs-3.0-1.src.rock", | 9 | "/lua_cliargs-3.0-1.src.rock", |
| @@ -109,173 +106,3 @@ describe("luarocks test #integration", function() | |||
| 109 | end) | 106 | end) |
| 110 | end) | 107 | end) |
| 111 | 108 | ||
| 112 | test_env.unload_luarocks() | ||
| 113 | |||
| 114 | local fs = require("luarocks.fs") | ||
| 115 | local cfg = require("luarocks.core.cfg") | ||
| 116 | local path = require("luarocks.path") | ||
| 117 | local test = require("luarocks.test") | ||
| 118 | local test_busted = require("luarocks.test.busted") | ||
| 119 | local test_command = require("luarocks.test.command") | ||
| 120 | |||
| 121 | describe("LuaRocks test #unit", function() | ||
| 122 | local runner | ||
| 123 | |||
| 124 | lazy_setup(function() | ||
| 125 | cfg.init() | ||
| 126 | fs.init() | ||
| 127 | runner = require("luacov.runner") | ||
| 128 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | ||
| 129 | runner.tick = true | ||
| 130 | end) | ||
| 131 | |||
| 132 | lazy_teardown(function() | ||
| 133 | runner.shutdown() | ||
| 134 | end) | ||
| 135 | |||
| 136 | local tmpdir | ||
| 137 | local olddir | ||
| 138 | |||
| 139 | local create_tmp_dir = function() | ||
| 140 | tmpdir = get_tmp_path() | ||
| 141 | olddir = lfs.currentdir() | ||
| 142 | lfs.mkdir(tmpdir) | ||
| 143 | lfs.chdir(tmpdir) | ||
| 144 | fs.change_dir(tmpdir) | ||
| 145 | end | ||
| 146 | |||
| 147 | local destroy_tmp_dir = function() | ||
| 148 | if olddir then | ||
| 149 | lfs.chdir(olddir) | ||
| 150 | if tmpdir then | ||
| 151 | lfs.rmdir(tmpdir) | ||
| 152 | end | ||
| 153 | end | ||
| 154 | end | ||
| 155 | |||
| 156 | describe("test.command", function() | ||
| 157 | describe("command.detect_type", function() | ||
| 158 | before_each(function() | ||
| 159 | create_tmp_dir() | ||
| 160 | end) | ||
| 161 | |||
| 162 | after_each(function() | ||
| 163 | destroy_tmp_dir() | ||
| 164 | end) | ||
| 165 | |||
| 166 | it("returns true if test.lua exists", function() | ||
| 167 | write_file("test.lua", "", finally) | ||
| 168 | assert.truthy(test_command.detect_type()) | ||
| 169 | end) | ||
| 170 | |||
| 171 | it("returns false if test.lua doesn't exist", function() | ||
| 172 | assert.falsy(test_command.detect_type()) | ||
| 173 | end) | ||
| 174 | end) | ||
| 175 | |||
| 176 | describe("command.run_tests", function() | ||
| 177 | before_each(function() | ||
| 178 | create_tmp_dir() | ||
| 179 | end) | ||
| 180 | |||
| 181 | after_each(function() | ||
| 182 | destroy_tmp_dir() | ||
| 183 | end) | ||
| 184 | |||
| 185 | it("returns the result of the executed tests", function() | ||
| 186 | write_file("test.lua", "assert(1==1)", finally) | ||
| 187 | assert.truthy(test_command.run_tests(nil, {})) | ||
| 188 | |||
| 189 | write_file("test.lua", "assert(1==2)", finally) | ||
| 190 | assert.falsy(test_command.run_tests(nil, {})) | ||
| 191 | end) | ||
| 192 | |||
| 193 | it("returns the result of the executed tests with custom arguments and test command", function() | ||
| 194 | write_file("test.lua", "assert(1==1)", finally) | ||
| 195 | |||
| 196 | local test = { | ||
| 197 | script = "test.lua", | ||
| 198 | flags = { | ||
| 199 | arg1 = "1", | ||
| 200 | arg2 = "2" | ||
| 201 | }, | ||
| 202 | command = fs.Q(testing_paths.lua) | ||
| 203 | } | ||
| 204 | assert.truthy(test_command.run_tests(test, {})) | ||
| 205 | end) | ||
| 206 | |||
| 207 | it("returns false and does nothing if the test script doesn't exist", function() | ||
| 208 | assert.falsy(test_command.run_tests(nil, {})) | ||
| 209 | end) | ||
| 210 | end) | ||
| 211 | end) | ||
| 212 | |||
| 213 | describe("test.busted", function() | ||
| 214 | describe("busted.detect_type", function() | ||
| 215 | before_each(function() | ||
| 216 | create_tmp_dir() | ||
| 217 | end) | ||
| 218 | |||
| 219 | after_each(function() | ||
| 220 | destroy_tmp_dir() | ||
| 221 | end) | ||
| 222 | |||
| 223 | it("returns true if .busted exists", function() | ||
| 224 | write_file(".busted", "", finally) | ||
| 225 | assert.truthy(test_busted.detect_type()) | ||
| 226 | end) | ||
| 227 | |||
| 228 | it("returns false if .busted doesn't exist", function() | ||
| 229 | assert.falsy(test_busted.detect_type()) | ||
| 230 | end) | ||
| 231 | end) | ||
| 232 | |||
| 233 | describe("busted.run_tests", function() | ||
| 234 | before_each(function() | ||
| 235 | path.use_tree(testing_paths.testing_sys_tree) | ||
| 236 | create_tmp_dir() | ||
| 237 | end) | ||
| 238 | |||
| 239 | after_each(function() | ||
| 240 | destroy_tmp_dir() | ||
| 241 | end) | ||
| 242 | |||
| 243 | pending("returns the result of the executed tests", function() | ||
| 244 | -- FIXME: busted issue | ||
| 245 | write_file("test_spec.lua", "assert(1==1)", finally) | ||
| 246 | assert.truthy(test_busted.run_tests(nil, {})) | ||
| 247 | |||
| 248 | write_file("test_spec.lua", "assert(1==2)", finally) | ||
| 249 | assert.falsy(test_busted.run_tests()) | ||
| 250 | end) | ||
| 251 | end) | ||
| 252 | end) | ||
| 253 | |||
| 254 | describe("test", function() | ||
| 255 | describe("test.run_test_suite", function() | ||
| 256 | before_each(function() | ||
| 257 | create_tmp_dir() | ||
| 258 | end) | ||
| 259 | |||
| 260 | after_each(function() | ||
| 261 | destroy_tmp_dir() | ||
| 262 | end) | ||
| 263 | |||
| 264 | it("returns false if the given rockspec cannot be loaded", function() | ||
| 265 | assert.falsy(test.run_test_suite("invalid", nil, {})) | ||
| 266 | end) | ||
| 267 | |||
| 268 | it("returns false if no test type was detected", function() | ||
| 269 | assert.falsy(test.run_test_suite({ package = "test" }, nil, {})) | ||
| 270 | end) | ||
| 271 | |||
| 272 | it("returns the result of executing the tests specified in the given rockspec", function() | ||
| 273 | write_file("test.lua", "assert(1==1)", finally) | ||
| 274 | assert.truthy(test.run_test_suite({ test_dependencies = {} }, nil, {})) | ||
| 275 | |||
| 276 | write_file("test.lua", "assert(1==2)", finally) | ||
| 277 | assert.falsy(test.run_test_suite({ test_dependencies = {} }, nil, {})) | ||
| 278 | end) | ||
| 279 | end) | ||
| 280 | end) | ||
| 281 | end) | ||
