• Stars
    star
    111
  • Rank 314,510 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created over 10 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Testing Sublime Text Packages

UnitTesting

test codecov

This is a unittest framework for Sublime Text. It runs unittest testcases on local machines and via Github Actions. It also supports testing syntax_test files for the new sublime-syntax format and sublime-color-scheme files.

Sublime Text 4

Sublime Text 4 is now supported and testing works for Python 3.8 packages. Though test coverage wouldn't work until Package Control adds support of Python 3.8 package dependencies.

Preparation

  1. Before testing anything, you have to install UnitTesting via Package Control.
  2. Your package!
  3. TestCases should be placed in test*.py under the directory tests (configurable, see below). The testcases are then loaded by TestLoader.discover.

Here are some small examples

Running Tests Locally

UnitTesting can be triggered via the command palette command UnitTesting. Enter the package name in the input panel and hit enter, a console should pop up and the tests should be running. To run only tests in particular files, enter <Package name>:<filename>. <filename> should be a unix shell wildcard to match the file names, <Package name>:test*.py is used in default.

You could run the command UnitTesting: Test Current Package to run the current package. The current package will be first reloaded by UnitTesting and then the tests will be executed.

It is also possible to generate test coverage report via coverage by using the command UnitTesting: Test Current Package with Coverage. The file .coveragerc is used to control the coverage configurations. If it is missing, UnitTesting will ignore the tests directory.

GitHub Actions

Basic: put the following in your workflow.

name: test

on: [push, pull_request]

jobs:
  run-tests:
    strategy:
      fail-fast: false
      matrix:
        st-version: [3, 4]
        os: ["ubuntu-latest", "macOS-latest", "windows-latest"]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - uses: SublimeText/UnitTesting/actions/setup@v1
        with:
          sublime-text-version: ${{ matrix.st-version }}
      - uses: SublimeText/UnitTesting/actions/run-tests@v1
        with:
          coverage: true
      - uses: codecov/codecov-action@v3

Remarks: actions are released in the branch v1. Minor changes will be pushed to the same branch unless there are breaking changes.

Testing syntax_test files

name: test-syntax

on: [push, pull_request]

jobs:
  run-syntax-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: SublimeText/UnitTesting/actions/setup@v1
      - uses: SublimeText/UnitTesting/actions/run-syntax-tests@v1

Check this for an example.

Deferred testing

Tests can be written using the Deferrable testcase, such that you are able to run sublime commands from your test cases and yield control to sublime text runtime and continue the execution later. Would be useful to test asynchronous codes. The idea was inspired by Plugin UnitTest Harness.

DeferrableTestCase is used to write the test cases. They are executed by the DeferringTextTestRunner and the runner expects not only regular test functions, but also generators. If the test function is a generator, it does the following

  • if the yielded object is a callable, the runner will evaluate the callable and check its returned value. If the result is not None, the runner continues the generator, if not, the runner will wait until the condition is met with the default timeout of 4s. The result of the callable can be also retrieved from the yield statement. The yielded object could be also a dictionary of the form {"condition": callable, timeout: timeout} to specify timeout in ms.

  • if the yielded object is an integer, say x, then it will continue the generator after x ms.

  • yield AWAIT_WORKER would yield to a task in the worker thread.

  • otherwise, a single yield would yield to a task in the main thread.

An example would be found in here.

Options

UnitTesting could be configured by providing the following settings in unittesting.json

name description default value
tests_dir the name of the directory containing the tests "tests"
pattern the pattern to discover tests "test*.py"
deferred whether to use deferred test runner true
verbosity verbosity level 2
output name of the test output instead of showing
in the panel
nil
show_reload_progress self explained true
reload_package_on_testing reloading package will increase coverage rate true
start_coverage_after_reload self explained, irrelevent if reload_package_on_testing is false false
coverage_on_worker_thread (experimental) false
generate_html_report generate coverage report for coverage false
capture_console capture stdout and stderr in the test output false
failfast stop early if a test fails false

Others

Add Test Current Package build

It is recommended to add the following in your .sublime-project file so that c+b would invoke the testing action.

"build_systems":
[
  {
    "name": "Test Current Package",
    "target": "unit_testing_current_package",
  }
]

Credits

Thanks guillermooo and philippotto for their early efforts in AppVeyor and Travis CI macOS support (though these services are not supported now).

More Repositories

1

Spacegray

A Hyperminimal UI Theme for Sublime Text
JavaScript
7,188
star
2

LaTeXTools

LaTeX plugin for Sublime Text
Python
2,007
star
3

Origami

Split the window however you like! Create new panes, delete panes, move and clone views from pane to pane.
Python
1,208
star
4

CTags

CTags support for Sublime Text
Python
987
star
5

TrailingSpaces

Highlight trailing spaces and delete them in a flash.
Python
897
star
6

AdvancedNewFile

File creation plugin for Sublime Text
Python
828
star
7

CoffeeScript

Syntax highlighting and checking, commands, shortcuts, snippets, watched compilation and more.
CoffeeScript
439
star
8

PackageDev

Tools to ease the creation of snippets, syntax definitions, etc. for Sublime Text.
Python
436
star
9

VintageEx

An implementation of Vim's command-line mode for Sublime Text 2
Python
381
star
10

PowerShell

Support for the MS PowerShell programming language.
PowerShell
313
star
11

Helium

Let Sublime Text talk with Jupyter.
Python
236
star
12

ColdFusion

ColdFusion Sublime Text Package
Python
197
star
13

VBScript

VBScript package for Sublime Text
Python
185
star
14

WordHighlight

Highlight all copies of the currently selected word.
Python
180
star
15

PhpDoc

PhpDoc support package.
JavaScript
165
star
16

Terraform

Terraform (HCL) configuration file syntax highlighting for Sublime Text
HCL
163
star
17

RSpec

Sublime Text 2 / 3 plugin for RSpec BDD Framework
Python
124
star
18

InsertNums

Sublime Text plugin for inserting sequences. Supporting alphanumerics and hex, with bitwise operations!
Python
123
star
19

IndentGuides

Draw vertical guides to easily visualize indent depth.
Python
106
star
20

Mote

SFTP Remote Editing for Sublime Text 2
Python
105
star
21

Pywin32

Pywin32 support for sublime (win32api etc)
Python
81
star
22

ElasticTabstops

Tab characters automatically adjust to keep adjacent lines aligned.
Python
67
star
23

PhpBeautifier

Pear Php_beautifier plugin for Sublime Text 2
Python
66
star
24

SaneSnippets

Sublime Text snippets optimized for humans, not robots
Python
59
star
25

LegacyColorSchemes

Color schemes that were part of Sublime Text 2 and older builds of Sublime Text 3
52
star
26

sublime_lib

Utility library for frequently used functionality in Sublime Text and convenience functions or classes
Python
52
star
27

Theme-DAneo

A theme for Sublime Text 3.2+ inspired by the popular DA UI
Python
51
star
28

Sass

Sass and SCSS syntax for Sublime Text
SCSS
50
star
29

material-theme

Material Theme, a theme for Sublime Text 3, made by Mattia Astorino
Python
44
star
30

GenerateUUID

Generate UUID for Sublime Text
Python
42
star
31

NSIS

Sublime Text plugin for the Nullsoft Scriptable Install System
Shell
40
star
32

WinMerge

Plugin that enables comparison of the last 2 activated buffers (even in different windows) using WinDiff (Windows only).
Python
37
star
33

InactivePanes

Sublime Text plugin that slightly dims (or grays) inactive panes in your group view
Python
32
star
34

SublimeHg

Use Mercurial from Sublime Text.
Python
30
star
35

QML

QML support for Sublime Text and Sublime Merge
QML
28
star
36

StatusBarFileSize

Show the file size in the Sublime Text status bar
Python
27
star
37

TailwindCSS

Tailswind CSS syntax for Sublime Text
CSS
24
star
38

MouseEventListener

Adds on_pre_click and on_post_click callbacks to Sublime Text's plugin API.
JavaScript
24
star
39

Mojolicious

Mojolicious package for the Perl Web Dev Framework for Sublime Text 2
JavaScript
22
star
40

Modelines

Vim-like modelines for Sublime Text.
Python
21
star
41

NaturalDocs

NaturalDocs package for SublimeText 2
JavaScript
21
star
42

ExtractSublimePackage

Extract .sublime-package files to the Sublime Text Packages folder.
Python
20
star
43

RevertFontSize

Sublime Text plugin to quickly revert to a preferred font size
Python
20
star
44

LegacyTheme

Sublime Text 2's default theme with retina graphics
19
star
45

YamlPipelines

Sublime Syntax Definitions for YAML CI/CD pipelines like GitHub Actions, AzureDevops, Kong API Gateway, Gitlab CICD, Bitbucket, Drone CI etc.
Python
18
star
46

KnowledgeBase

Sublime Text Knowledge Base
Python
18
star
47

ScrollOffset

Python
18
star
48

UberSelection

Commands to extend the functionality of Sublime Text's multiselection.
Python
17
star
49

PythonOpenModule

Open python modules on sys.path and open folders in window
Python
16
star
50

PowershellUtils

Run powershell commands from within Sublime Text.
Python
16
star
51

Rake

Sublime Text 2 plugin for Ruby Rake
Python
15
star
52

JumpTo

Sublime Text plugin to move (multiple) cursors
Python
13
star
53

SwitchWindow

A plugin to quickly switch between Sublime Text windows via Command Palette
Python
12
star
54

ScopeNamingGuidelines

Collection of documents for scope naming guidelines in Sublime Text syntax definitions
12
star
55

AutoSelect

Sticky Selection
Python
12
star
56

SublimeCMD

Simple command processor for Sublime Text.
Python
12
star
57

syntax-test-action

Github Action to run syntax tests
Shell
12
star
58

OpenDefaultApplication

Sublime Text plugin to open files in the system default application
Python
11
star
59

Terminal

Launch terminals from the current file or the root project folder
Python
11
star
60

Sublime-Snipt

Sublime Text 2 plugin that will sync with snipt.net
Python
10
star
61

sublimetext.github.io

GitHub Organization for Open-Source Sublime Text Package Development
9
star
62

AutoProjects

A Sublime Text plugin to open folders as projects
Python
9
star
63

PackageTesting

Minimal testing framework for Sublime Text packages. (beta)
Python
8
star
64

WslBuild

A Sublime Text package to create build systems running in WSL2
Python
7
star
65

Astro

Astro syntax for Sublime Text
Astro
7
star
66

TJ3-syntax-sublimetext2

Taskjuggler 3 syntax and code snippets for Sublime Text 2
7
star
67

Mustache

Mustache syntax and snippets for Sublime Text
Mustache
6
star
68

Less

Less syntax for Sublime Text
Less
6
star
69

LINQPad

Syntax highlighting and build system for LINQPad scripts
5
star
70

AlpineJS

AlpineJS syntax for Sublime Text
PHP
4
star
71

Ceedling

Sublime Text plugin for Ceedling C unit testing framework
Python
4
star
72

Gaelyk

Gaelyk Sublime Text Package
3
star
73

GoToEndOfLineOrScope

Sublime Text plugin to bind a key (for example the end key) to move/extend the cursor/selection(s) to the end of the line, or to before the specified scope (i.e. a comment) at the end of the line
Python
3
star
74

RichTextFormat

Syntax definition for RTF files in Sublime Text 3
2
star
75

wbond-packages

Packages created, and (mostly) managed by Will Bond
1
star
76

OpenFileInCurrentFolder

Allows opening of files in the same folder as the active view
Python
1
star