From a9ea4395bca05516e8297588ec943c648f726345 Mon Sep 17 00:00:00 2001 From: Deepak Singh Rathore Date: Wed, 23 Jun 2021 01:56:56 +0530 Subject: luarocks test: add --prepare flag (#1314) * Added prepare flag in test command * Added test for prepare flag in spec/test_spec.lua Fixes #1303 --- spec/test_spec.lua | 26 ++++++++++++++++++++++++++ src/luarocks/cmd/test.lua | 9 +++++---- src/luarocks/test.lua | 8 ++++++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/spec/test_spec.lua b/spec/test_spec.lua index 220ae632..943d0e48 100644 --- a/spec/test_spec.lua +++ b/spec/test_spec.lua @@ -70,6 +70,32 @@ describe("luarocks test #integration", function() -- Assert that busted ran, whether successfully or not assert.match("%d+ success.* / %d+ failure.* / %d+ error.* / %d+ pending", output) end) + + it("prepare", function() + finally(function() + -- delete downloaded and unpacked files + lfs.chdir(testing_paths.testrun_dir) + test_env.remove_dir("busted_project-0.1-1") + os.remove("busted_project-0.1-1.src.rock") + end) + + -- make luassert + assert.is_true(run.luarocks_bool("download --server="..testing_paths.fixtures_repo_dir.." busted_project 0.1-1")) + assert.is_true(run.luarocks_bool("unpack busted_project-0.1-1.src.rock")) + lfs.chdir("busted_project-0.1-1/busted_project") + assert.is_true(run.luarocks_bool("make")) + + run.luarocks_bool("remove busted") + local prepareOutput = run.luarocks_bool("test --prepare") + assert.is_true(run.luarocks_bool("show busted")) + + -- Assert that "test --prepare" run successfully + assert.is_true(prepareOutput) + + local output = run.luarocks("test") + assert.not_match(tostring(prepareOutput), output) + + end) end) end) diff --git a/src/luarocks/cmd/test.lua b/src/luarocks/cmd/test.lua index 21838c90..be9a5dfb 100644 --- a/src/luarocks/cmd/test.lua +++ b/src/luarocks/cmd/test.lua @@ -23,7 +23,8 @@ to separate LuaRocks arguments from test suite arguments.]], :args("?") cmd:argument("args", "Test suite arguments.") :args("*") - + cmd:flag("--prepare", "Only install dependencies needed for testing only, but do not run the test") + cmd:option("--test-type", "Specify the test suite type manually if it was ".. "not specified in the rockspec and it could not be auto-detected.") :argname("") @@ -31,7 +32,7 @@ end function cmd_test.command(args) if args.rockspec and args.rockspec:match("rockspec$") then - return test.run_test_suite(args.rockspec, args.test_type, args.args) + return test.run_test_suite(args.rockspec, args.test_type, args.args, args.prepare) end table.insert(args.args, 1, args.rockspec) @@ -40,8 +41,8 @@ function cmd_test.command(args) if not rockspec then return nil, err end - - return test.run_test_suite(rockspec, args.test_type, args.args) + + return test.run_test_suite(rockspec, args.test_type, args.args, args.prepare) end return cmd_test diff --git a/src/luarocks/test.lua b/src/luarocks/test.lua index 15eca234..cf475fd3 100644 --- a/src/luarocks/test.lua +++ b/src/luarocks/test.lua @@ -33,7 +33,7 @@ local function get_test_type(rockspec) end -- Run test suite as configured in rockspec in the current directory. -function test.run_test_suite(rockspec_arg, test_type, args) +function test.run_test_suite(rockspec_arg, test_type, args, prepare) local rockspec if type(rockspec_arg) == "string" then local err, errcode @@ -68,7 +68,11 @@ function test.run_test_suite(rockspec_arg, test_type, args) return nil, "failed loading test execution module " .. mod_name end - return test_mod.run_tests(rockspec.test, args) + if prepare then + return test_mod.run_tests(rockspec_arg, {"--version"}) + else + return test_mod.run_tests(rockspec.test, args) + end end return test -- cgit v1.2.3-55-g6feb