ruanyl / vim-gh-line

vim plugin that open the link of current line on github
MIT License
408 stars 37 forks source link

Added the first unit test #20

Closed ahakanbaba closed 5 years ago

ahakanbaba commented 5 years ago

Hi @ruanyl , while I was working on adding the cgit support, I felt the dire need to add some test coverage to the plugin. With expanding support for github, gitlab, bitbucket and cgit, the different ways the plugin can fail increases rapidly. It felt impossible to add cgit support and not break something else.

So here we go. This PR is my take to adding unit tests. Right now the only test is for s:Github function. I added that as an example for how tests should look like. We can discuss further. If this looks reasonable to you I will add more test coverage in my cgit related PR.

The approach looks similar to what the actual vim upstream does. Take a look at their unit test runner here and an example test file here.

This is all vim-native no other plugin or dependency is necessary. I have tested it in maxOS ElCapitan 10.11.6 and vim 8.1. But it should work in vim7x too. (I think)

One quirk in this PR is the implementation for testing script-local functions (s:funcName). Since most of the functions are in a "plugin" directory and they are defined as script local, we need to do some extra work in the test file to call them. You can read here for more about it.

references #18 Someone else needs to add the travisci or circleci config so that the unit tests are executed pre merge.

KostyaEsmukov commented 5 years ago

Someone else needs to add the travisci or circleci config so that the unit tests are executed pre merge.

Feel free to ping me here on this matter, if needed. I can open a PR adding a Travis CI configuration so it would be enough to just flip a switch on travis-ci.com/travis-ci.org.

ruanyl commented 5 years ago

@ahakanbaba thank you very much for adding the first test 🎉

ruanyl commented 5 years ago

@KostyaEsmukov feel free to add a Travis CI integration to this repo :D

KostyaEsmukov commented 5 years ago

But it should work in vim7x too. (I think)

It doesn't seem to work on 7.4: https://travis-ci.org/KostyaEsmukov/vim-gh-line/jobs/454142549

Exception: Vim(let):E117: Unknown function: execute (in function <SNR>2_tryRunA
(let):E117: Unknown function: execute (in function <SNR>2_tryRunAllTests..<SNR>2_runAllTests..<SNR>2_getScriptID, line 2)

I don't think this is an issue actually, so this is just FYI.