Port tests to nosetests

This commit is contained in:
Peter Melnichenko 2016-04-27 22:58:15 +03:00
parent de368c98d8
commit 0086cd3457
7 changed files with 95 additions and 45 deletions

4
.gitignore vendored
View File

@ -1,4 +1,6 @@
*.pyc *.pyc
*.egg-info *.egg-info
dist dist
test .coverage
test/here
test/builds

View File

@ -22,10 +22,10 @@ matrix:
install: install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install python; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install python; fi
- pip install pyflakes - pip install pyflakes pep8 coverage coveralls nose
- pip install pep8
script: script:
- pyflakes . - pyflakes .
- pep8 . - pep8 .
- ./test.sh - nosetests
- coveralls

39
test.sh
View File

@ -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

87
test/cli_test.py Normal file
View File

@ -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)"])

View File

@ -15,11 +15,11 @@ dependencies = {
build = { build = {
type = "builtin", type = "builtin",
modules = { modules = {
["hererocks.test"] = "test.lua" ["hererocks.test"] = "test/test.lua"
}, },
install = { install = {
bin = { bin = {
["hererocks-test"] = "hererocks-test.lua" ["hererocks-test"] = "test/hererocks-test.lua"
} }
}, },
copy_directories = {} copy_directories = {}