Sublime is Sublime 7

So as we have come along the path our sublime instance is starting to feel quite a bit more customized than it was before. We can now build, have git/github integration, and of course have awesome command line integration but what about running tests?

We will start with the simplest way of running tests. This may not work for all of your scenarios and does somewhat require you to have thought about things in advance.

If you for instance started off from the beginning with resharper as a test runner you are probably have a test suite that will be difficult to use. Likely it is all in one assembly regardless of whether its a unit test or an integration test. Quite likely the tests have large numbers of dependencies. And to be frank your unit tests probably don’t run properly in linux anyways. Yeah this kind of sucks but can be fixed.

To start with there is no integrated right click->debug test in sublime. I find however that this is not something I missed. Maybe its having worked for a few years building embedded systems where there was no debugger (except dumping as hex pieces of memory).

Let’s talk about the simplest way to run tests from sublime and the general workflow. Normally when working with sublime I have multiple test suites either separated by category or by assembly. I have unit tests which are quick to run and then all other tests. I rarely if ever run the other tests locally. Instead I let a CI server run those. My unit tests should be run in and this would give you a new buffer with the output of your tests running. For a huge portion of code you will be working on this is *good enough*. If you have a 10 second cycle on tests running it is completely reasonable.

There are however some other things you can do if you want to be more fancy. The first is you could assign the running of the script to a key in sublime. This is actually quite easy any command can be assigned to any key by editing your keymap http://sublimetext.info/docs/en/reference/key_bindings.html

Another cool option that is quite easy to enable to get a notification from linux on the status of your build/test run. This can be done trivial using notify-send in your small script above based on return values from processes.

Try:
notify-send ‘Hello world!’ ‘This is an example notification.’ –icon=dialog-information

You can even change the icons to say red/green circles for the notification.

Now if your tests are more than 10 seconds. The first strategy would be to start putting them into categories that make sense to you. This way you can only run tests within a given category. This step alone will normally be good enough to get your test runs back under 10 seconds (I prefer 1-2 seconds). If this is not then perhaps your code base has become too dependent on the tool (15 categories 10 seconds each…). One thing you will notice is that your tests in general will run far faster than through tools like VS/R# when being run from the command line.

OK so now we have basic unit test integration. There are still a lot of problems with .NET code. In the next post we will look at what some of these are and how to deal with them.

Posted in Uncategorized | Leave a comment

Sublime is Sublime 6

So far we have done quite a bit getting sublime up and going for use with .NET work but we still at this point have to compile our code from the command prompt which well sucks. In this post we will look at how to get compiles working from within sublime by adding a custom build system for xbuild.

Go to Tools->Build System->new build. A file will open. Drop in:

{
“cmd”: ["xbuild"],
“path”: “/opt/mono/bin/”,
“working_dir”: “${project_path:${folder}}”,
“file_regex”: “^ (.*)\\(([0-9]*),([0-9]*)”
}

Then save this file named xbuild. You can now choose xbuild as a build platform.

Is is important to note that you have to point at the correct xbuild (I run off trunk so I compile with a /opt prefix if you get from say apt-get it will be some place else) and you must have the correct mcs in your path when doing this. This code also assumes that you have only a single solution in the root folder of your code.

Once this is done you can choose xbuild as your current build provider. Then you can use either f7 or ctrl+b to build your code on demand.

Now we are really starting to get there. In the next post we will look at how to run unit tests from within sublime manually.

Posted in Uncategorized | Leave a comment

Sublime is Sublime 5

So far we have learned how to install packages and have setup some basic packages for color schemes and for git. In this post we will get better support for the command line as there is lots of useful things that can be done on the command line in a linux system and as a developer you tend to be there often.

To do this bring up the command pallette (ctrl+shift+p) and type install which should bring you to install package. Hit enter and you will get the same popup as when installing the git support in the last post.

In the box type shell turtlestein to install this package https://github.com/misfo/Shell-Turtlestein. This is a very simple package but its also very powerful.

Once it is installed type ctrl+shift+c and a textbox will come up at the bottom of your screen. Any text you type here will be executed. As an example you can try ls -al and you will see the results of your command. This is how you can run arbitrary commands from directly in sublime.

There are however some other features of this command prompt such as being able to take text from in sublime and move them to the command prompt or to take text from the shell and move it to a buffer.

To move text from your command back to a buffer you use the > key trailing your command. As example try ctrl+shift+c then type ps -ax >. This will create a new buffer in sublime with the results of your command. We could even build this way xbuild yoursolution.sln > would bring up a new buffer with the build results but it is not the best way of doing this. This is very useful when writing documentation of say a restful service and interacting via curl

You can also take a document and pipe it to the command (it gets passed as stdin). An example of this can be seen with | wc or | wc > to get the result into a new buffer. The | will either take your selected text in the buffer or the whole text if nothing else is selected.

You can even combine things and do a transformation on your buffer through the command line. An example of this might be | sort | or | transform | which transforms the text then replaces the text within your document.

As you can imagine there are a huge number of possibilities that are now available to you from just interacting with the command line and we will use some of these in the next few posts to do other things that you will need to do on a daily basis.

Posted in Uncategorized | Leave a comment

Sublime is Sublime 4

Now we are heading into our fourth post about sublime. So far we have looked at why we might want to use sublime. We have installed sublime and learned some basic key shortcuts and we have installed a package manager with our first package. In this post we will install git integration into sublime and look at how its used.

This post assumes that the code you have opened in sublime is in a git repository!

So let’s start by installing the git package.

Hit ctrl+shift+p (you should be good at this)
Type install wait for 2-3 seconds
Type git and hit enter to install https://github.com/kemayo/sublime-text-git/wiki

After a few moments the git plugin will be installed. You may or may not need to restart sublime at this point I have heard mixed results.

Now let’s try using our git plugin. Let’s start by being in a file under source control and hitting

ctrl+shift+p git log

You will see the full log of your code. If you select one you can view the commit in a text window.

Let’s try another common one

ctrl+shift+p git pull

This will do a git pull. This is just the very beginning of the integration though. One of my favorite features. Add a new file foo.cs. Then in that file do a

ctrl+shift+p git add (current file)

if you then do a ctrl+shift+p git status you can see that the file has been added. We can also add such fun functionality as ctrl+shift+p blame :)

When you want to commit:

ctrl+shift+p git commit

this will bring up a buffer of your commit. Just type it your comment and hit ctrl+w to close the window and commit.

This plugin has very deep git integration including diff viewing and annotating code while working in it! You can find more on its feature set here https://github.com/kemayo/sublime-text-git/wiki

It takes a bit of exploring but you can do quite a bit with git integration in sublime and its language agnostic which is really nice.

While we are on the topic let’s install the github plugin since many of you are probably using github. The package is sublime-github https://github.com/bgreenlee/sublime-github. You can read more about the configuration of the plugin on their website but it allows you to do things like

view on github (opens code in browser)
manage gists (eg file or selection to public gist)
browse gists
gist->clipboard

Overall its quite well done as well.

So now you have gotten full git and github integration into sublime very soon we will start getting into the C# specific stuff but before that we need some better linux specific handling.

Posted in Uncategorized | Leave a comment

Sublime is Sublime 3

In the last post we installed sublime and learned (hopefully) some of the basic operations in it. In that setup however you still have a long way to go to being effective in sublime actually doing much of the stuff in your development process will be quite painful (try adding a file and having the joy of manually editing .prj files). In this post we are going to install a package manager and become comfortable with its basic operations. We will need it for the next few posts where we will add on some functionality to sublime.

To install the package manager browse here: https://sublime.wbond.net/installation there are instructions on how to install it. Select Sublime 2 copy the related python code. Go into sublime and hit ctrl+` this will open your command window. Paste the python code and hit enter the package manager will now be installed. You will need to restart sublime for this change to take effect.

Once you have restarted sublime let’s try to install a package.

hit ctrl+shift+p
type inst (it should bring you to install package) hit enter it make take a few seconds to pop up.
you should now have a list of packages
type Dayle Re and you should see https://github.com/daylerees/colour-schemes this theme.
Hit enter to install the theme. You will see in the status bar the status of installing it.

If you now go to preferences->color scheme you will see the color scheme that you just installed I personally like sublime->darkside try setting it.

In this post we have installed a package manager and learned how to install a package. In the next few posts we will install some other useful packages.

Posted in Uncategorized | Leave a comment