Sublime Forum

Plugin automated testing

#1

Is there a way to automatically test sublimetext plugins?

I’m aware we can run a command using the command line:

subl --command <command_name> --background <file_path>

but I can’t see how to verify the output of the command from a bash script (it is only available from sublimetext GUI)

The only workaround I’ve found until now is to copy/paste into the console something like this:

window.open_file("<file_path>"); window.run_command("<command_name>")

that will prompt me if there is an error. But that can be difficult to read/maintain if I have 10 or more tests and I cannot not use it in a CI tool like travis.ci, codeship or circle.ci.

Is there any recommendation on that?

0 Likes

#2

There is a package for this, I think called unit testing. (I’m on mobile)

0 Likes

#3

Thanks a lot FichteFoll.

I had a look at it (https://github.com/randy3k/UnitTesting) and it does exactly what I’m looking for: automation and Travis integration.

However I can’t see how I can assert that the output of my exec command is correct. What I would like to do is:

def test_sample
        self.window.run_command("exec",{'shell': True, 'cmd': 'echo "Hello World!"'})
        command_output = <a way to get the command output>
        self.assertEqual(command_output, 'Hello World!"')

I’ve tried to play with create_output_panel but I could not retrieve the ouptut of the command. In the unoficial documentation I’ve also seen result_file_regex and other view settings but it’s not clear to me how/if I could use it to programatically retrieve the command output.

0 Likes