Skip to content

Add Travis and AppVeyor. #246

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

Merged
merged 1 commit into from
Feb 10, 2018
Merged
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
54 changes: 54 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
env:
global:
- PACKAGE="Rust Enhanced"
- SUBLIME_TEXT_VERSION="3"

language: rust

matrix:
include:
- os: linux
rust: stable

- os: osx
rust: stable

- os: linux
rust: beta

- os: osx
rust: beta

- os: linux
rust: nightly

- os: osx
rust: nightly


before_install:
- curl -OL https://github.com/raw/SublimeText/UnitTesting/master/sbin/travis.sh

# enable gui, see https://docs.travis-ci.com/user/gui-and-headless-browsers
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then
export DISPLAY=:99.0;
sh -e /etc/init.d/xvfb start;
fi


install:
# Install Sublime and Sublime Unittesting.
- sh travis.sh bootstrap
# Install Package Control, needed for dependencies.
- sh travis.sh install_package_control

# Ensure nightly is installed to run no-trans, benchmarks, and Clippy.
- rustup install nightly
# Install Rust packages needed by integration tests.
- cargo +nightly install clippy || export RE_SKIP_CLIPPY=1
- cargo install cargo-script


script:
- sh travis.sh run_syntax_tests
- sh travis.sh run_tests
32 changes: 32 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
environment:
global:
PACKAGE: "Rust Enhanced"
SUBLIME_TEXT_VERSION : "3"

matrix:
- RUST_VERSION: stable
- RUST_VERSION: beta
- RUST_VERSION: nightly


install:
- ps: appveyor DownloadFile "https://github.com/raw/SublimeText/UnitTesting/master/sbin/appveyor.ps1"
# Install Sublime and Sublime Unittesting.
- ps: .\appveyor.ps1 "bootstrap" -verbose
- ps: .\appveyor.ps1 "install_package_control" -verbose
# Install rust.
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
- rustup-init.exe -y --default-toolchain %RUST_VERSION%
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
# Ensure nightly is installed to run no-trans, benchmarks, and Clippy.
- rustup install nightly
# Install Rust packages needed by integration tests.
- cargo +nightly install clippy || set RE_SKIP_CLIPPY=1
- cargo install cargo-script
- rustc -Vv

build: off

test_script:
- ps: .\appveyor.ps1 "run_syntax_tests" -verbose
- ps: .\appveyor.ps1 "run_tests" -verbose
2 changes: 0 additions & 2 deletions cargo_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,7 @@ class CargoCurrentFile(sublime_plugin.WindowCommand):
what = None

def run(self):
print('current file')
def _test_file(target):
print('target is %r' % target)
self.window.run_command('cargo_exec', args={
'command': self.what,
'settings': {
Expand Down
18 changes: 16 additions & 2 deletions rust/cargo_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@
}


CARGO_BUILD_DEFAULTS = {
'variants': {
'clippy': {
'toolchain': 'nightly',
}
}
}


class CargoSettings(object):

"""Interface to Cargo project settings stored in `sublime-project`
Expand All @@ -146,9 +155,11 @@ def load(self):
self.re_settings = sublime.load_settings('RustEnhanced.sublime-settings')

def get_global_default(self, key, default=None):
internal_default = CARGO_BUILD_DEFAULTS.get('defaults', {})\
.get(key, default)
return self.re_settings.get('cargo_build', {})\
.get('defaults', {})\
.get(key, default)
.get(key, internal_default)

def set_global_default(self, key, value):
cb = self.re_settings.get('cargo_build', {})
Expand All @@ -169,10 +180,13 @@ def set_project_default(self, key, value):
self._set_project_data()

def get_global_variant(self, variant, key, default=None):
internal_default = CARGO_BUILD_DEFAULTS.get('variants', {})\
.get(variant, {})\
.get(key, default)
return self.re_settings.get('cargo_build', {})\
.get('variants', {})\
.get(variant, {})\
.get(key, default)
.get(key, internal_default)

def set_global_variant(self, variant, key, value):
cb = self.re_settings.get('cargo_build', {})
Expand Down
2 changes: 1 addition & 1 deletion rust/rust_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def _cleanup(self):
self.proc.stdout.close()
rc = self.proc.wait()
with PROCS_LOCK:
p = PROCS[self.window.id()]
p = PROCS.get(self.window.id())
if p is self:
del PROCS[self.window.id()]
return rc
51 changes: 43 additions & 8 deletions tests/rust_test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import os
import unittest
import subprocess
import threading
import time
# Used for debugging.
Expand Down Expand Up @@ -45,9 +46,25 @@ def setUp(self):
window = sublime.active_window()
# Clear any rust project settings.
data = window.project_data()
if not data:
data = {}
# Ensure any user settings don't interfere with the test.
if 'cargo_build' in data.get('settings', {}):
del data['settings']['cargo_build']
window.set_project_data(data)
# When the tests run automatically, they are not part of a sublime
# project. However, various tests depend on checking relative paths,
# so ensure that `folders` is set.
#
# Set `folder_exclude_patterns` to prevent the Rust build directory
# from being recognized by Sublime. I have a suspicion this causes
# spurious errors on Windows because Sublime may be indexing the
# files, preventing `cargo clean` from being able to remove them.
if 'folders' not in data:
data['folders'] = [{
'path': plugin_path,
'folder_exclude_patterns': ['target'],
}]
window.set_project_data(data)
plugin.cargo_build.ON_LOAD_MESSAGES_ENABLED = False

# Override settings.
Expand Down Expand Up @@ -75,12 +92,18 @@ def tearDown(self):
self._restore_settings()
plugin.cargo_build.ON_LOAD_MESSAGES_ENABLED = True

def _get_rust_thread(self):
"""Waits for a rust thread to get started and returns it."""
for n in range(500):
def _get_rust_thread(self, previous_thread=None):
"""Waits for a rust thread to get started and returns it.

:param previous_thread: If set, it will avoid returning this thread.
Use this when there is a thread currently running, and you want to
make sure you get the next thread that starts.
"""
for n in range(1000):
t = rust_thread.THREADS.get(sublime.active_window().id())
if t:
return t
if previous_thread is None or previous_thread != t:
return t
time.sleep(0.01)
raise AssertionError('Rust thread never started.')

Expand Down Expand Up @@ -151,11 +174,23 @@ def _cargo_clean(self, view_or_path):
else:
path = view_or_path
window = sublime.active_window()
rust_proc.check_output(window,
'cargo clean'.split(),
path)
try:
rust_proc.check_output(window,
'cargo clean'.split(),
path)
except subprocess.CalledProcessError as e:
print('Cargo clean failure')
print(e.output)
raise
messages.clear_messages(window)

def _skip_clippy(self):
if 'RE_SKIP_CLIPPY' in os.environ:
print('Skipping Clippy test.')
return True
else:
return False


class AlteredSetting(object):

Expand Down
16 changes: 14 additions & 2 deletions tests/test_cargo_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ def _test_document(self, view):

def test_clippy(self):
"""Test "Clippy" variant."""
if self._skip_clippy():
return
self._with_open_file('tests/error-tests/examples/clippy_ex.rs',
self._test_clippy)

Expand Down Expand Up @@ -412,8 +414,6 @@ def _test_build_env(self, view):
def test_auto_build(self):
"""Test "auto" build."""
tests = [
# This should probably automatically use nightly?
('benches/bench1.rs', r'may not be used on the (stable|beta) release channel'),
('examples/ex1.rs', r'(?m)^ex1$'),
('src/bin/bin1.rs', r'(?m)^bin1$'),
('src/altmain.rs', r'(?m)^altmain$'),
Expand All @@ -422,6 +422,18 @@ def test_auto_build(self):
('src/main.rs', r'(?m)^Hello$'),
('tests/test1.rs', r'(?m)^test sample_test1 \.\.\. ok$'),
]
rustc_version = util.get_rustc_version(sublime.active_window(),
plugin_path)
if 'nightly' in rustc_version:
# Benches are allowed to run on nightly.
tests.append(
('benches/bench1.rs',
r'\[Running: cargo bench --bench bench1'))
else:
tests.append(
('benches/bench1.rs',
r'may not be used on the (stable|beta) release channel'))

for path, pattern in tests:
self._with_open_file('tests/multi-targets/' + path,
self._test_auto_build, pattern=pattern)
Expand Down
10 changes: 8 additions & 2 deletions tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,14 @@ def _test_rust_list_messages2(self, view):
]
self.quick_panel_index = 2
window.run_command('rust_list_messages')
new_view = window.active_view()
expected_path = os.path.normpath(
os.path.join(plugin_path, 'tests/message-order/examples/warning2.rs'))
self.assertEqual(new_view.file_name(), expected_path)
# Give Sublime some time to switch views.
for n in range(5):
new_view = window.active_view()
if new_view.file_name() == expected_path:
break
time.sleep(0.5)
else:
self.assertEqual(new_view.file_name(), expected_path)
new_view.run_command('close_file')
26 changes: 19 additions & 7 deletions tests/test_interrupt.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def _test_slow_check(self, view):

def test_build_cancel(self):
"""Test manually canceling a build."""
# So it doesn't hide the UnitTest output panel.
self._with_open_file('tests/slow-build/src/lib.rs',
self._test_build_cancel)

Expand All @@ -101,6 +100,7 @@ def _test_build_cancel(self, view):
window.run_command('rust_cancel')
# Sleep long enough to make sure the build didn't continue running.
time.sleep(4)
t.join()
self.assertEqual(self.terminated, [t])
# Start, but no end.
self.assertEqual(self._files(), [pattern + '-start-1'])
Expand All @@ -119,6 +119,7 @@ def _test_syntax_check_cancel(self, view):
view.window().run_command('rust_cancel')
# Sleep long enough to make sure the build didn't continue running.
time.sleep(4)
t.join()
self.assertEqual(self.terminated, [t])
# Start, but no end.
self.assertEqual(self._files(), [pattern + '-start-1'])
Expand All @@ -140,6 +141,8 @@ def _test_syntax_check_while_build(self, view):
# This thread will silently exit without running.
check_t.start()
time.sleep(4)
check_t.join()
build_t.join()
self.assertEqual(self.terminated, [])
self.assertEqual(self._files(),
[pattern + '-start-1',
Expand All @@ -158,9 +161,11 @@ def _test_build_while_syntax_check(self, view):
self._wait_for_start()
# Should silently kill the syntax check thread.
self._run_build()
build_t = self._get_rust_thread()
build_t = self._get_rust_thread(previous_thread=check_t)
self._wrap_terminate(build_t)
time.sleep(4)
build_t.join()
check_t.join()
self.assertEqual(self.terminated, [check_t])
self.assertEqual(self._files(),
[pattern + '-start-1',
Expand All @@ -176,12 +181,17 @@ def _test_build_with_save(self, view):
self._cargo_clean(view)
# Trigger on_save for syntax checking.
view.run_command('save')
on_save_thread = self._get_rust_thread()
self._wrap_terminate(on_save_thread)
# Doing this immediately afterwards should cancel the syntax check
# before it gets a chance to do much.
self._run_build()
build_t = self._get_rust_thread()
build_t = self._get_rust_thread(previous_thread=on_save_thread)
self._wrap_terminate(build_t)
time.sleep(5)
# Wait for threads to finish.
on_save_thread.join()
build_t.join()
self.assertEqual(self.terminated, [on_save_thread])
self.assertEqual(self._files(),
[pattern + '-start-1',
pattern + '-end-1'])
Expand Down Expand Up @@ -210,13 +220,15 @@ def ok_cancel_dialog(msg, ok_title=None):
self._wrap_terminate(build_t)
# Start a second build.
self._run_build()
time.sleep(1)
next_build_t = self._get_rust_thread(previous_thread=build_t)
build_t.join()
self.assertEqual(self.terminated, [build_t])
# Start again, but hit cancel.
ok_value = False
self._run_build()
time.sleep(4)
# Should not have interrupted.
next_build_t.join()
# Should not have interrupted next_build_t.
self.assertEqual(self.terminated, [build_t])
self.assertEqual(self._files(),
[pattern + '-start-1',
Expand All @@ -226,7 +238,7 @@ def ok_cancel_dialog(msg, ok_title=None):
sublime.ok_cancel_dialog = orig_ok_cancel_dialog

def _wait_for_start(self):
for _ in range(50):
for _ in range(100):
time.sleep(0.1)
if self._files() == [pattern + '-start-1']:
break
Expand Down
2 changes: 2 additions & 0 deletions tests/test_syntax_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def test_messages(self):

def test_clippy_messages(self):
"""Test clippy messages."""
if self._skip_clippy():
return
to_test = [
'tests/error-tests/examples/clippy_ex.rs',
]
Expand Down
3 changes: 2 additions & 1 deletion unittesting.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"async": true
"async": true,
"capture_console": true
}