From c02b5989301312dfee02c195497e119bd0c73b85 Mon Sep 17 00:00:00 2001 From: George Roman Date: Fri, 27 Jul 2018 22:29:11 +0300 Subject: Tests: refactor and add fixtures for the doc tests --- spec/doc_spec.lua | 158 ++++++++++++++++++++++------- spec/fixtures/a_repo/a_rock-1.0-1.rockspec | 1 + 2 files changed, 122 insertions(+), 37 deletions(-) diff --git a/spec/doc_spec.lua b/spec/doc_spec.lua index c7cacc94..bf5214d4 100644 --- a/spec/doc_spec.lua +++ b/spec/doc_spec.lua @@ -4,13 +4,7 @@ local testing_paths = test_env.testing_paths test_env.unload_luarocks() -local extra_rocks = { - "/luarepl-0.4-1.src.rock", - "/c3-1.0-1.src.rock" -} - describe("LuaRocks doc tests #integration", function() - before_each(function() test_env.setup_specs(extra_rocks) end) @@ -19,23 +13,57 @@ describe("LuaRocks doc tests #integration", function() it("LuaRocks doc with no flags/arguments", function() assert.is_false(run.luarocks_bool("doc")) end) + it("LuaRocks doc with invalid argument", function() assert.is_false(run.luarocks_bool("doc invalid")) end) - it("LuaRocks doc with no homepage", function() - assert.is_true(run.luarocks_bool("install c3")) - assert.is_false(run.luarocks_bool("doc c3 --home")) - end) - it("LuaRocks doc with no home page and no doc folder", function() - assert.is_true(run.luarocks_bool("install c3")) - test_env.remove_dir(testing_paths.testing_sys_rocks .. "/c3/1.0-1/doc") - assert.is_false(run.luarocks_bool("doc c3")) + + it("LuaRocks doc with no homepage and no doc folder", function() + test_env.run_in_tmp(function(tmpdir) + test_env.write_file("test-1.0-1.rockspec", [[ + package = "test" + version = "1.0-1" + source = { + url = "file://test.lua" + } + build = { + type = "builtin", + modules = { + test = "test.lua" + } + } + ]], finally) + test_env.write_file("test.lua", "return {}", finally) + + assert.is_true(run.luarocks_bool("install test-1.0-1.rockspec")) + assert.is_false(run.luarocks_bool("doc test --home")) + end, finally) end) - it("LuaRocks doc with no doc folder opening descript.homepage", function() - assert.is_true(run.luarocks_bool("install luarepl")) - test_env.remove_dir(testing_paths.testing_sys_rocks .. "/luarepl/0.4-1/doc") - local output = run.luarocks("doc luarepl") - assert.is.truthy(output:find("Local documentation directory not found")) + + it("LuaRocks doc with no doc folder but with homepage", function() + test_env.run_in_tmp(function(tmpdir) + test_env.write_file("test-1.0-1.rockspec", [[ + package = "test" + version = "1.0-1" + source = { + url = "file://test.lua" + } + description = { + homepage = "http://www.example.com" + } + build = { + type = "builtin", + modules = { + test = "test.lua" + } + } + ]], finally) + test_env.write_file("test.lua", "return {}", finally) + + assert.is_true(run.luarocks_bool("install test-1.0-1.rockspec")) + local output = assert.is.truthy(run.luarocks("doc test")) + assert.is.truthy(output:find("documentation directory not found")) + end, finally) end) end) @@ -48,30 +76,86 @@ describe("LuaRocks doc tests #integration", function() end) describe("LuaRocks doc tests with flags", function() - it("LuaRocks doc of installed luarepl", function() - assert.is_true(run.luarocks_bool("install luarepl")) - assert.is_true(run.luarocks_bool("doc luarepl")) - end) + it("LuaRocks doc of installed package", function() + test_env.run_in_tmp(function(tmpdir) + test_env.write_file("test-1.0-1.rockspec", [[ + package = "test" + version = "1.0-1" + source = { + url = "file://test.lua" + } + build = { + type = "builtin", + modules = { + test = "test.lua" + } + } + ]], finally) + test_env.write_file("test.lua", "return {}", finally) - it("LuaRocks doc of luacov and access its home page", function() - assert.is_true(run.luarocks_bool("install luacov")) - assert.is_true(run.luarocks_bool("doc luacov --home")) + assert.is_true(run.luarocks_bool("install test-1.0-1.rockspec")) + lfs.mkdir(testing_paths.testing_sys_rocks .. "/test/1.0-1/doc") + test_env.write_file(testing_paths.testing_sys_rocks .. "/test/1.0-1/doc/doc.md", "", finally) + test_env.write_file(testing_paths.testing_sys_rocks .. "/test/1.0-1/doc/readme.md", "", finally) + assert.is_true(run.luarocks_bool("doc test")) + end, finally) end) - - it("LuaRocks doc of luacov and list doc folder", function() - assert.is_true(run.luarocks_bool("install luacov")) - local output = assert.is.truthy(run.luarocks("doc luacov --list")) - assert.is.truthy(output:find("/lib/luarocks/rocks%-.*/luacov/0.11.0%-1/doc/", 1)) + + it("LuaRocks doc with --list", function() + test_env.run_in_tmp(function(tmpdir) + test_env.write_file("test-1.0-1.rockspec", [[ + package = "test" + version = "1.0-1" + source = { + url = "file://test.lua" + } + build = { + type = "builtin", + modules = { + test = "test.lua" + } + } + ]], finally) + test_env.write_file("test.lua", "return {}", finally) + + assert.is_true(run.luarocks_bool("install test-1.0-1.rockspec")) + lfs.mkdir(testing_paths.testing_sys_rocks .. "/test/1.0-1/doc") + test_env.write_file(testing_paths.testing_sys_rocks .. "/test/1.0-1/doc/doc1.md", "", finally) + test_env.write_file(testing_paths.testing_sys_rocks .. "/test/1.0-1/doc/doc2.md", "", finally) + local output = assert.is.truthy(run.luarocks("doc test --list")) + assert.is.truthy(output:find("doc1%.md")) + assert.is.truthy(output:find("doc2%.md")) + end, finally) end) - it("LuaRocks doc of luacov local", function() - assert.is_true(run.luarocks_bool("install luacov")) - assert.is_true(run.luarocks_bool("doc luacov --local")) + it("LuaRocks doc with --local", function() + assert.is_true(run.luarocks_bool("install --server=" .. testing_paths.fixtures_dir .. "/a_repo a_rock")) + assert.is_true(run.luarocks_bool("doc --server=" .. testing_paths.fixtures_dir .. "/a_repo a_rock --local")) end) - it("LuaRocks doc of luacov porcelain", function() - assert.is_true(run.luarocks_bool("install luacov")) - assert.is_true(run.luarocks_bool("doc luacov --porcelain")) + it("LuaRocks doc with --porcelain", function() + test_env.run_in_tmp(function(tmpdir) + test_env.write_file("test-1.0-1.rockspec", [[ + package = "test" + version = "1.0-1" + source = { + url = "file://test.lua" + } + build = { + type = "builtin", + modules = { + test = "test.lua" + } + } + ]], finally) + test_env.write_file("test.lua", "return {}", finally) + + assert.is_true(run.luarocks_bool("install test-1.0-1.rockspec")) + lfs.mkdir(testing_paths.testing_sys_rocks .. "/test/1.0-1/doc") + test_env.write_file(testing_paths.testing_sys_rocks .. "/test/1.0-1/doc/doc1.md", "", finally) + test_env.write_file(testing_paths.testing_sys_rocks .. "/test/1.0-1/doc/doc2.md", "", finally) + assert.is_true(run.luarocks_bool("doc test --porcelain")) + end, finally) end) end) end) diff --git a/spec/fixtures/a_repo/a_rock-1.0-1.rockspec b/spec/fixtures/a_repo/a_rock-1.0-1.rockspec index 9f15e87a..69d78209 100644 --- a/spec/fixtures/a_repo/a_rock-1.0-1.rockspec +++ b/spec/fixtures/a_repo/a_rock-1.0-1.rockspec @@ -5,6 +5,7 @@ source = { } description = { summary = "An example rockspec", + homepage = "http://www.example.com" } dependencies = { "lua >= 5.1" -- cgit v1.2.3-55-g6feb