diff options
| author | Deepak Singh Rathore <dsrdeepak8@gmail.com> | 2021-06-23 01:56:56 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-22 17:26:56 -0300 |
| commit | a9ea4395bca05516e8297588ec943c648f726345 (patch) | |
| tree | 2c3106d2841e72acf999a324d84f34ee5f37bb39 | |
| parent | 7e6bfb6d8c1d45d62ceb4bbe8e89a184d4c96ffb (diff) | |
| download | luarocks-a9ea4395bca05516e8297588ec943c648f726345.tar.gz luarocks-a9ea4395bca05516e8297588ec943c648f726345.tar.bz2 luarocks-a9ea4395bca05516e8297588ec943c648f726345.zip | |
luarocks test: add --prepare flag (#1314)
* Added prepare flag in test command
* Added test for prepare flag in spec/test_spec.lua
Fixes #1303
| -rw-r--r-- | spec/test_spec.lua | 26 | ||||
| -rw-r--r-- | src/luarocks/cmd/test.lua | 9 | ||||
| -rw-r--r-- | 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() | |||
| 70 | -- Assert that busted ran, whether successfully or not | 70 | -- Assert that busted ran, whether successfully or not |
| 71 | assert.match("%d+ success.* / %d+ failure.* / %d+ error.* / %d+ pending", output) | 71 | assert.match("%d+ success.* / %d+ failure.* / %d+ error.* / %d+ pending", output) |
| 72 | end) | 72 | end) |
| 73 | |||
| 74 | it("prepare", function() | ||
| 75 | finally(function() | ||
| 76 | -- delete downloaded and unpacked files | ||
| 77 | lfs.chdir(testing_paths.testrun_dir) | ||
| 78 | test_env.remove_dir("busted_project-0.1-1") | ||
| 79 | os.remove("busted_project-0.1-1.src.rock") | ||
| 80 | end) | ||
| 81 | |||
| 82 | -- make luassert | ||
| 83 | assert.is_true(run.luarocks_bool("download --server="..testing_paths.fixtures_repo_dir.." busted_project 0.1-1")) | ||
| 84 | assert.is_true(run.luarocks_bool("unpack busted_project-0.1-1.src.rock")) | ||
| 85 | lfs.chdir("busted_project-0.1-1/busted_project") | ||
| 86 | assert.is_true(run.luarocks_bool("make")) | ||
| 87 | |||
| 88 | run.luarocks_bool("remove busted") | ||
| 89 | local prepareOutput = run.luarocks_bool("test --prepare") | ||
| 90 | assert.is_true(run.luarocks_bool("show busted")) | ||
| 91 | |||
| 92 | -- Assert that "test --prepare" run successfully | ||
| 93 | assert.is_true(prepareOutput) | ||
| 94 | |||
| 95 | local output = run.luarocks("test") | ||
| 96 | assert.not_match(tostring(prepareOutput), output) | ||
| 97 | |||
| 98 | end) | ||
| 73 | end) | 99 | end) |
| 74 | end) | 100 | end) |
| 75 | 101 | ||
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.]], | |||
| 23 | :args("?") | 23 | :args("?") |
| 24 | cmd:argument("args", "Test suite arguments.") | 24 | cmd:argument("args", "Test suite arguments.") |
| 25 | :args("*") | 25 | :args("*") |
| 26 | 26 | cmd:flag("--prepare", "Only install dependencies needed for testing only, but do not run the test") | |
| 27 | |||
| 27 | cmd:option("--test-type", "Specify the test suite type manually if it was ".. | 28 | cmd:option("--test-type", "Specify the test suite type manually if it was ".. |
| 28 | "not specified in the rockspec and it could not be auto-detected.") | 29 | "not specified in the rockspec and it could not be auto-detected.") |
| 29 | :argname("<type>") | 30 | :argname("<type>") |
| @@ -31,7 +32,7 @@ end | |||
| 31 | 32 | ||
| 32 | function cmd_test.command(args) | 33 | function cmd_test.command(args) |
| 33 | if args.rockspec and args.rockspec:match("rockspec$") then | 34 | if args.rockspec and args.rockspec:match("rockspec$") then |
| 34 | return test.run_test_suite(args.rockspec, args.test_type, args.args) | 35 | return test.run_test_suite(args.rockspec, args.test_type, args.args, args.prepare) |
| 35 | end | 36 | end |
| 36 | 37 | ||
| 37 | table.insert(args.args, 1, args.rockspec) | 38 | table.insert(args.args, 1, args.rockspec) |
| @@ -40,8 +41,8 @@ function cmd_test.command(args) | |||
| 40 | if not rockspec then | 41 | if not rockspec then |
| 41 | return nil, err | 42 | return nil, err |
| 42 | end | 43 | end |
| 43 | 44 | ||
| 44 | return test.run_test_suite(rockspec, args.test_type, args.args) | 45 | return test.run_test_suite(rockspec, args.test_type, args.args, args.prepare) |
| 45 | end | 46 | end |
| 46 | 47 | ||
| 47 | return cmd_test | 48 | 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) | |||
| 33 | end | 33 | end |
| 34 | 34 | ||
| 35 | -- Run test suite as configured in rockspec in the current directory. | 35 | -- Run test suite as configured in rockspec in the current directory. |
| 36 | function test.run_test_suite(rockspec_arg, test_type, args) | 36 | function test.run_test_suite(rockspec_arg, test_type, args, prepare) |
| 37 | local rockspec | 37 | local rockspec |
| 38 | if type(rockspec_arg) == "string" then | 38 | if type(rockspec_arg) == "string" then |
| 39 | local err, errcode | 39 | local err, errcode |
| @@ -68,7 +68,11 @@ function test.run_test_suite(rockspec_arg, test_type, args) | |||
| 68 | return nil, "failed loading test execution module " .. mod_name | 68 | return nil, "failed loading test execution module " .. mod_name |
| 69 | end | 69 | end |
| 70 | 70 | ||
| 71 | return test_mod.run_tests(rockspec.test, args) | 71 | if prepare then |
| 72 | return test_mod.run_tests(rockspec_arg, {"--version"}) | ||
| 73 | else | ||
| 74 | return test_mod.run_tests(rockspec.test, args) | ||
| 75 | end | ||
| 72 | end | 76 | end |
| 73 | 77 | ||
| 74 | return test | 78 | return test |
