Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add tests for script invocation #1337

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import subprocess, os, tempfile

test_deps = [
'pytest>=3.6',
'pytest>=3.9',
'pytest-console-scripts==0.1.9',
'pytest-cov==2.4.0',
'coveralls[yaml]==1.6.0',
'pytest-xdist==1.18.1',
Expand Down
61 changes: 61 additions & 0 deletions tests/bin/test_vyper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import itertools

import pytest

from vyper import (
__version__,
)


@pytest.fixture
def make_tmp_vy_file(tmp_path):
name_count = itertools.count()

def _make(src):
name = f'tmp{next(name_count)}.vy'

src_path = tmp_path / name
src_path.write_text(src)

return src_path

return _make


@pytest.fixture
def tmp_vy_file_1(make_tmp_vy_file):
return make_tmp_vy_file("""
@public
def a() -> bool:
return True
""")


@pytest.fixture
def tmp_vy_file_2(make_tmp_vy_file):
return make_tmp_vy_file("""
@public
def meaning_of_life() -> uint256:
return 42
""")


@pytest.mark.script_launch_mode('subprocess')
def test_version(script_runner):
ret = script_runner.run('vyper', '--version')

assert ret.stdout == __version__ + '\n'


@pytest.mark.script_launch_mode('subprocess')
def test_compile_one_file(script_runner, tmp_vy_file_1):
ret = script_runner.run('vyper', '-f', 'bytecode', tmp_vy_file_1)

assert ret.stdout == '0x6100c256600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052630dbe671f60005114156100b85734156100ac57600080fd5b600160005260206000f3005b60006000fd5b6100046100c2036100046000396100046100c2036000f3\n' # noqa: E501
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacqueswww how fragile would it be to test against raw bytecode for these simple programs? It shouldn't have to be updated too often due to language semantics changes, right?



@pytest.mark.script_launch_mode('subprocess')
def test_compile_two_files(script_runner, tmp_vy_file_1, tmp_vy_file_2):
ret = script_runner.run('vyper', '-f', 'bytecode', tmp_vy_file_1, tmp_vy_file_2)

assert ret.stdout == '0x6100c256600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052630dbe671f60005114156100b85734156100ac57600080fd5b600160005260206000f3005b60006000fd5b6100046100c2036100046000396100046100c2036000f3\n0x6100c256600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052634f452d6060005114156100b85734156100ac57600080fd5b602a60005260206000f3005b60006000fd5b6100046100c2036100046000396100046100c2036000f3\n' # noqa: E501