This repository has been archived by the owner on Jun 4, 2024. It is now read-only.
forked from mono/monodevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mono#816 from my-personal-forks/new-tests
Sublime Text: Add tests
- Loading branch information
Showing
13 changed files
with
294 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (c) 2014, Guillermo López-Anglada. Please see the AUTHORS file for details. | ||
# All rights reserved. Use of this source code is governed by a BSD-style | ||
# license that can be found in the LICENSE file.) | ||
'''Provides classes that make it easier to test several aspects of a package. | ||
''' | ||
|
||
import unittest | ||
|
||
import sublime | ||
|
||
|
||
class ViewTest(unittest.TestCase): | ||
def setUp(self): | ||
self.view = sublime.active_window().new_file() | ||
|
||
def append(self, text): | ||
self.view.run_command('append', {'characters': text}) | ||
|
||
def tearDown(self): | ||
self.view.set_scratch(True) | ||
self.view.close() | ||
|
||
|
||
class SyntaxTest(ViewTest): | ||
def _setSyntax(self, rel_path): | ||
self.view.set_syntax_file(rel_path) | ||
|
||
def getScopeNameAt(self, pt): | ||
return self.view.scope_name(pt) | ||
|
||
def getFinestScopeNameAt(self, pt): | ||
return self.getScopeNameAt(pt).split()[-1] | ||
|
||
def getScopeNameAtRowCol(self, row, col): | ||
text_pt = self.view.text_point(row, col) | ||
return self.getScopeNameAt(text_pt) | ||
|
||
def getFinestScopeNameAtRowCol(self, row, col): | ||
return self.getScopeNameAtRowCol(row, col).split()[-1] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright (c) 2014, Guillermo López-Anglada. Please see the AUTHORS file for details. | ||
# All rights reserved. Use of this source code is governed by a BSD-style | ||
# license that can be found in the LICENSE file.) | ||
|
||
import sublime | ||
import sublime_plugin | ||
|
||
import os | ||
import unittest | ||
import contextlib | ||
import threading | ||
|
||
|
||
from FSharp.sublime_plugin_lib.panels import OutputPanel | ||
|
||
|
||
class RunFsharpTests(sublime_plugin.WindowCommand): | ||
'''Runs tests and displays the result. | ||
- Do not use ST while tests are running. | ||
@working_dir | ||
Required. Should be the parent of the top-level directory for `tests`. | ||
@loader_pattern | ||
Optional. Only run tests matching this glob. | ||
@active_file_only | ||
Optional. Only run tests in the active file in ST. Shadows | ||
@loader_pattern. | ||
To use this runner conveniently, open the command palette and select one | ||
of the `Build: Dart - Test *` commands. | ||
''' | ||
@contextlib.contextmanager | ||
def chdir(self, path=None): | ||
old_path = os.getcwd() | ||
if path is not None: | ||
assert os.path.exists(path), "'path' is invalid {}".format(path) | ||
os.chdir(path) | ||
yield | ||
if path is not None: | ||
os.chdir(old_path) | ||
|
||
def run(self, **kwargs): | ||
with self.chdir(kwargs.get('working_dir')): | ||
p = os.path.join(os.getcwd(), 'tests') | ||
patt = kwargs.get('loader_pattern', 'test*.py',) | ||
# TODO(guillermooo): I can't get $file to expand in the build | ||
# system. It should be possible to make the following code simpler | ||
# with it. | ||
if kwargs.get('active_file_only') is True: | ||
patt = os.path.basename(self.window.active_view().file_name()) | ||
suite = unittest.TestLoader().discover(p, pattern=patt) | ||
|
||
file_regex = r'^\s*File\s*"([^.].*?)",\s*line\s*(\d+),.*$' | ||
display = OutputPanel('fs.tests', file_regex=file_regex) | ||
display.show() | ||
runner = unittest.TextTestRunner(stream=display, verbosity=1) | ||
|
||
def run_and_display(): | ||
runner.run(suite) | ||
|
||
threading.Thread(target=run_and_display).start() |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import contextlib | ||
import glob | ||
import os | ||
import tempfile | ||
import time | ||
import unittest | ||
|
||
import sublime | ||
|
||
from FSharp.lib.project import find_fsproject | ||
from FSharp.lib.project import FSharpFile | ||
from FSharp.lib.project import FSharpProjectFile | ||
from FSharp.sublime_plugin_lib.io import touch | ||
|
||
|
||
@contextlib.contextmanager | ||
def make_directories(dirs): | ||
tmp_dir = tempfile.TemporaryDirectory() | ||
current = tmp_dir.name | ||
for dd in dirs: | ||
for d in dd: | ||
current = os.path.join(current, d) | ||
os.mkdir(current) | ||
current = tmp_dir.name | ||
yield tmp_dir.name | ||
tmp_dir.cleanup() | ||
|
||
|
||
class Test_find_fsproject(unittest.TestCase): | ||
def testCanFind(self): | ||
with make_directories([["foo", "bar", "baz"]]) as tmp_root: | ||
fs_proj_file = os.path.join(tmp_root, 'hey.fsproj') | ||
touch(fs_proj_file) | ||
found = find_fsproject (os.path.join (tmp_root, 'foo/bar/baz')) | ||
self.assertEquals(found, fs_proj_file) | ||
|
||
|
||
class Test_FSharpProjectFile (unittest.TestCase): | ||
def testCanCreateFromPath(self): | ||
with tempfile.TemporaryDirectory () as tmp: | ||
f = os.path.join (tmp, 'foo.fsproj') | ||
touch (f) | ||
fs_project = FSharpProjectFile.from_path(f) | ||
self.assertEquals(fs_project.path, f) | ||
|
||
def testCanReturnParent(self): | ||
with tempfile.TemporaryDirectory () as tmp: | ||
f = os.path.join (tmp, 'foo.fsproj') | ||
touch (f) | ||
fs_project = FSharpProjectFile.from_path(f) | ||
self.assertEquals(fs_project.parent, tmp) | ||
|
||
def testCanBeCompared(self): | ||
with tempfile.TemporaryDirectory () as tmp: | ||
f = os.path.join (tmp, 'foo.fsproj') | ||
touch (f) | ||
fs_project_1 = FSharpProjectFile.from_path(f) | ||
fs_project_2 = FSharpProjectFile.from_path(f) | ||
self.assertEquals(fs_project_1, fs_project_2) | ||
|
||
def test_governs_SameLevel(self): | ||
with tempfile.TemporaryDirectory () as tmp: | ||
f = os.path.join (tmp, 'foo.fsproj') | ||
f2 = os.path.join (tmp, 'foo.fs') | ||
touch (f) | ||
touch (f2) | ||
fs_proj = FSharpProjectFile.from_path(f) | ||
self.assertTrue(fs_proj.governs (f2)) | ||
|
||
|
||
class Test_FSharpFile (unittest.TestCase): | ||
def setUp(self): | ||
self.win = sublime.active_window() | ||
|
||
def tearDown(self): | ||
self.win.run_command ('close') | ||
|
||
def testCanDetectCodeFile(self): | ||
with tempfile.TemporaryDirectory () as tmp: | ||
f = os.path.join (tmp, 'foo.fs') | ||
touch (f) | ||
v = self.win.open_file(f) | ||
time.sleep(0.01) | ||
fs_file = FSharpFile (v) | ||
self.assertTrue (fs_file.is_code_file) | ||
|
||
def testCanDetectScriptFile(self): | ||
with tempfile.TemporaryDirectory () as tmp: | ||
f = os.path.join (tmp, 'foo.fsx') | ||
touch (f) | ||
v = self.win.open_file(f) | ||
time.sleep(0.01) | ||
fs_file = FSharpFile (v) | ||
self.assertTrue (fs_file.is_script_file) | ||
|
||
def testCanDetectCodeForCodeFile(self): | ||
with tempfile.TemporaryDirectory () as tmp: | ||
f = os.path.join (tmp, 'foo.fs') | ||
touch (f) | ||
v = self.win.open_file(f) | ||
time.sleep(0.01) | ||
fs_file = FSharpFile (v) | ||
self.assertTrue (fs_file.is_code) | ||
|
||
def testCanDetectCodeForScriptFile(self): | ||
with tempfile.TemporaryDirectory () as tmp: | ||
f = os.path.join (tmp, 'foo.fsx') | ||
touch (f) | ||
v = self.win.open_file(f) | ||
time.sleep(0.01) | ||
fs_file = FSharpFile (v) | ||
self.assertTrue (fs_file.is_code) | ||
|
||
def testCanDetectProjectFile(self): | ||
with tempfile.TemporaryDirectory () as tmp: | ||
f = os.path.join (tmp, 'foo.fsproj') | ||
touch (f) | ||
v = self.win.open_file(f) | ||
time.sleep(0.01) | ||
fs_file = FSharpFile (v) | ||
self.assertTrue (fs_file.is_project_file) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from FSharp.tests.tools import FSharpSyntaxTest | ||
|
||
|
||
class Test_DoubledQuotedStrings(FSharpSyntaxTest): | ||
def testCanDetectDoubleQuotedStrings(self): | ||
self.append(''' | ||
let foo = "some string here" | ||
0123456789 | ||
0123456789 | ||
0123456 | ||
''') | ||
actual = self.getFinestScopeNameAtRowCol(1, 11) | ||
self.assertEqual(actual, 'string.quoted.double.fsharp') | ||
|
||
|
||
class Test_TripleQuotedStrings(FSharpSyntaxTest): | ||
def testCanDetectTripleQuotedStrings(self): | ||
self.append(''' | ||
let foo = """some string here""" | ||
0123456789 | ||
0123456789 | ||
0123456 | ||
''') | ||
actual = self.getFinestScopeNameAtRowCol(1, 13) | ||
self.assertEqual(actual, 'string.quoted.triple.fsharp') | ||
|
||
|
||
class Test_VerbatimStrings(FSharpSyntaxTest): | ||
def testCanDetectVerbatimStrings(self): | ||
self.append(''' | ||
let foo = @"some string here" | ||
0123456789 | ||
0123456789 | ||
0123456 | ||
''') | ||
actual = self.getFinestScopeNameAtRowCol(1, 12) | ||
self.assertEqual(actual, 'string.quoted.double.verbatim.fsharp') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import unittest | ||
|
||
import sublime | ||
|
||
from FSharp.sublime_plugin_lib.testing import SyntaxTest | ||
|
||
|
||
class FSharpSyntaxTest(SyntaxTest): | ||
def setUp(self): | ||
super().setUp() | ||
self._setSyntax('Packages/FSharp/FSharp.tmLanguage') |