1
0
Fork 0
mirror of synced 2024-11-18 06:55:33 -05:00
ultimate-vim/sources_non_forked/rust.vim/test/run-tests

106 lines
2.7 KiB
Text
Raw Normal View History

#!/usr/bin/env python
import os
import sys
REPO = "alonid/vim-testbed"
TAG = "10-rust.vim"
IMAGE = "%s:%s" % (REPO, TAG)
class Error(Exception):
pass
def system(cmd, capture=False, ok_fail=False):
if capture:
f = os.popen(cmd)
d = f.read()
return d
res = os.system(cmd)
if res != 0:
if ok_fail:
return res
raise Error("Error executing: %s" % (cmd, ))
return 0
def root():
return os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
def prep():
d = os.path.join(root(), "test")
for i in [".cargo", ".rustup", ".multirust"]:
l = os.path.join(d, i)
if not os.path.lexists(l):
os.symlink("/rust/" + i, l)
l = os.path.join(root(), "test/.vimrc")
if not os.path.lexists(l):
os.symlink("vimrc", l)
if not os.path.exists(os.path.join(d, ".profile")):
f = open(os.path.join(d, ".profile"), "w")
f.write('export PATH="$HOME/.cargo/bin:$PATH"\n')
f.close()
def docker_run(cmd, interactive=False, ok_fail=False):
prep()
d = root()
params = "-v %s:/testplugin -v %s/test:/home/vimtest" % (d, d)
params += " -e HOME=/home/vimtest"
if not interactive:
params += " -a stderr"
params += " -e VADER_OUTPUT_FILE=/dev/stderr"
params += " -u %s" % (os.getuid(), )
params += " -w /testplugin"
if interactive:
interactive_str = "-it"
else:
interactive_str = ""
return system("docker run %s --rm %s %s %s" % (interactive_str, params, IMAGE, cmd),
ok_fail=ok_fail)
def image_exists():
r = system("docker images -q %s" % (IMAGE, ), capture=True)
return len(r.strip().splitlines()) >= 1
def tests_on_docker():
res = docker_run("bash -lc 'python /home/vimtest/run-tests inside-docker'", ok_fail=True)
if res == 0:
2021-10-11 05:30:43 -04:00
print("Tests OK")
else:
2021-10-11 05:30:43 -04:00
print("Tests Failed")
sys.exit(1)
def inside_docker():
res = system("/vim-build/bin/vim80 --not-a-term '+Vader! test/*.vader'", ok_fail=True)
if res != 0:
sys.exit(1)
def run_with_vimrc(vimrc):
res = system("vim -u %s --not-a-term '+Vader! test/*.vader'" % (vimrc, ), ok_fail=True)
if res != 0:
sys.exit(1)
def main():
if sys.argv[1:] == ["inside-docker"]:
inside_docker()
return
if sys.argv[1:2] == ["run-with-vimrc"]:
run_with_vimrc(sys.argv[2])
return
if not image_exists():
2021-10-11 05:30:43 -04:00
print("Need to take image from remote")
system("docker pull %s" % (IMAGE, ))
if "-i" in sys.argv[1:]:
docker_run("bash -l", interactive=True)
return
tests_on_docker()
if __name__ == "__main__":
main()