From 0086cd34570e4da94dba177802da628781ff534d Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Wed, 27 Apr 2016 22:58:15 +0300 Subject: [PATCH] Port tests to nosetests --- .gitignore | 4 +- .travis.yml | 6 +- test.sh | 39 --------- test/cli_test.py | 87 +++++++++++++++++++ .../hererocks-test-scm-1.rockspec | 4 +- hererocks-test.lua => test/hererocks-test.lua | 0 test.lua => test/test.lua | 0 7 files changed, 95 insertions(+), 45 deletions(-) delete mode 100755 test.sh create mode 100644 test/cli_test.py rename hererocks-test-scm-1.rockspec => test/hererocks-test-scm-1.rockspec (82%) rename hererocks-test.lua => test/hererocks-test.lua (100%) rename test.lua => test/test.lua (100%) diff --git a/.gitignore b/.gitignore index 5c35ced..3522b8e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ *.pyc *.egg-info dist -test +.coverage +test/here +test/builds diff --git a/.travis.yml b/.travis.yml index 878cb6a..fbc5662 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,10 +22,10 @@ matrix: install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install python; fi - - pip install pyflakes - - pip install pep8 + - pip install pyflakes pep8 coverage coveralls nose script: - pyflakes . - pep8 . - - ./test.sh + - nosetests + - coveralls diff --git a/test.sh b/test.sh deleted file mode 100755 index 93a7f77..0000000 --- a/test.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -set -ev -export PATH="$PWD/test/here/bin:$PATH" -HEREROCKS="python hererocks.py test/here --downloads=test/cache --no-git-cache --verbose" - -rm -rf test/here -$HEREROCKS -l^ -r^ -lua -v -lua -e "assert(bit32)" -lua -e "assert(coroutine.wrap(string.gmatch('x', '.'))() ~= 'x')" - -luarocks --version -luarocks make -hererocks-test | tee test/tmp && grep "5\.3" test/tmp -$HEREROCKS -l^ -r^ | tee test/tmp && grep "already installed" test/tmp - -rm -rf test/here -$HEREROCKS -j @v2.1 -r^ | tee test/tmp && grep "Fetching" test/tmp | grep "cached" -lua -v -lua -e "require 'jit.bcsave'" -luarocks --version -luarocks make -hererocks-test | tee test/tmp && grep "2\.1" test/tmp - -rm -rf test/here -$HEREROCKS -l 5.1 --compat=none --no-readline -lua -e "assert(not pcall(string.gfind, '', '.'))" -lua -e "(function(...) assert(arg == nil) end)()" -lua -e "assert(math.mod == nil)" - -rm -rf test/here -rm -rf test/builds -$HEREROCKS -l 5.3 --compat=none --patch --builds=test/builds -lua -e "assert(not bit32)" -lua -e "assert(coroutine.wrap(string.gmatch('x', '.'))() == 'x')" - -rm -rf test/here -$HEREROCKS -l 5.3 --compat=none --patch --builds=test/builds | tee test/tmp && grep "Building" test/tmp | grep "cached" -$HEREROCKS --show diff --git a/test/cli_test.py b/test/cli_test.py new file mode 100644 index 0000000..90e0212 --- /dev/null +++ b/test/cli_test.py @@ -0,0 +1,87 @@ +import os +import shutil +import subprocess +import unittest + +class TestCLI(unittest.TestCase): + @classmethod + def setUpClass(cls): + subprocess.check_call(["coverage", "erase"]) + + def setUp(self): + for subdir in ["here", "builds"]: + if os.path.exists(os.path.join("test", subdir)): + shutil.rmtree(os.path.join("test", subdir)) + + def assertSuccess(self, args, expected_output_lines=None, from_prefix=True): + if from_prefix: + args[0] = os.path.join("test", "here", "bin", args[0]) + + process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + output = process.communicate()[0].decode("UTF-8") + + if process.returncode != 0: + raise AssertionError("Error running command '{}': code {}, output:\n{}".format( + " ".join(args), process.returncode, output)) + + if expected_output_lines is not None: + actual_output_lines = output.splitlines() + + for expected_output_line in expected_output_lines: + if not any(expected_output_line in actual_output_line for actual_output_line in actual_output_lines): + raise AssertionError("Expected to see '{}' in output of command '{}', got output:\n{}".format( + expected_output_line, " ".join(args), output)) + + def assertHererocksSuccess(self, args, expected_output_lines=None): + self.assertSuccess([ + "coverage", "run", "-a", + "hererocks.py", os.path.join("test", "here")] + args, expected_output_lines, from_prefix=False) + + def test_install_latest_lua_with_latest_luarocks(self): + self.assertHererocksSuccess(["--lua", "latest", "--luarocks", "latest"]) + self.assertHererocksSuccess(["--show"], ["Programs installed in", "Compat: default"]) + self.assertSuccess(["lua", "-v"], ["Lua 5.3.2"]) + self.assertSuccess(["lua", "-e", "assert(bit32)"]) + self.assertSuccess(["lua", "-e", "assert(coroutine.wrap(string.gmatch('x', '.'))() ~= 'x')"]) + + self.assertSuccess(["luarocks", "--version"]) + self.assertSuccess(["luarocks", "make", os.path.join("test", "hererocks-test-scm-1.rockspec")]) + self.assertSuccess(["hererocks-test"], ["Lua 5.3"]) + + self.assertHererocksSuccess(["--lua", "latest", "--luarocks", "latest"], ["already installed"]) + self.assertHererocksSuccess(["--luarocks", "latest", "--ignore-installed"], ["Fetching", "cached"]) + + def test_install_bleeding_edge_luajit_with_latest_luarocks(self): + self.assertHererocksSuccess(["--luajit", "@v2.1", "--luarocks", "latest"]) + self.assertSuccess(["lua", "-v"], ["LuaJIT 2.1.0"]) + self.assertSuccess(["lua", "-e", "require 'jit.bcsave'"]) + + self.assertSuccess(["luarocks", "--version"]) + self.assertSuccess(["luarocks", "make", os.path.join("test", "hererocks-test-scm-1.rockspec")]) + self.assertSuccess(["hererocks-test"], ["LuaJIT 2.1.0"]) + + self.assertHererocksSuccess(["--luajit", "@v2.1", "--luarocks", "latest"], ["already installed"]) + + def test_install_lua_5_1_without_compat_without_readline_with_old_luarocks(self): + self.assertHererocksSuccess(["--lua", "5.1", "--compat", "none", "--no-readline", "--luarocks", "2.0.8"]) + self.assertSuccess(["lua", "-e", "assert(not pcall(string.gfind, '', '.'))"]) + self.assertSuccess(["lua", "-e", "(function(...) assert(arg == nil) end)()"]) + self.assertSuccess(["lua", "-e", "assert(math.mod == nil)"]) + + self.assertSuccess(["luarocks", "--version"]) + self.assertSuccess(["luarocks", "make", os.path.join("test", "hererocks-test-scm-1.rockspec")]) + + def test_install_lua_5_3_with_patches(self): + self.assertHererocksSuccess(["--lua", "5.3", "--patch"]) + self.assertSuccess(["lua", "-e", "assert(coroutine.wrap(string.gmatch('x', '.'))() == 'x')"]) + + def test_cached_lua_5_2_build(self): + self.assertHererocksSuccess( + ["--lua", "5.2", "--builds", os.path.join("test", "builds")], + ["No patches available for Lua 5.2"]) + self.assertHererocksSuccess( + ["--lua", "5.2", "--compat", "none", "--builds", os.path.join("test", "builds")], + ["No patches available for Lua 5.2"]) + self.assertHererocksSuccess( + ["--lua", "5.2", "--ignore-installed", "--compat", "none", "--builds", os.path.join("test", "builds")], + ["Building Lua 5.2.4 (compat: none) (cached)"]) diff --git a/hererocks-test-scm-1.rockspec b/test/hererocks-test-scm-1.rockspec similarity index 82% rename from hererocks-test-scm-1.rockspec rename to test/hererocks-test-scm-1.rockspec index 752db7f..178f3ab 100644 --- a/hererocks-test-scm-1.rockspec +++ b/test/hererocks-test-scm-1.rockspec @@ -15,11 +15,11 @@ dependencies = { build = { type = "builtin", modules = { - ["hererocks.test"] = "test.lua" + ["hererocks.test"] = "test/test.lua" }, install = { bin = { - ["hererocks-test"] = "hererocks-test.lua" + ["hererocks-test"] = "test/hererocks-test.lua" } }, copy_directories = {} diff --git a/hererocks-test.lua b/test/hererocks-test.lua similarity index 100% rename from hererocks-test.lua rename to test/hererocks-test.lua diff --git a/test.lua b/test/test.lua similarity index 100% rename from test.lua rename to test/test.lua