Skip to content

Commit

Permalink
Add version command (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith Smiley authored Apr 29, 2017
1 parent 48b7cde commit 5f4e15c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
8 changes: 7 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <sourcekitd/sourcekitd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

char *copy_file_contents(char *path);
Expand Down Expand Up @@ -98,10 +99,15 @@ int perform_sourcekit_request_from_yamlfile(char *filepath) {

int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: skit YAMLFILE\n");
fprintf(stderr, "Usage: skit [YAMLFILE|-v|--version]\n");
return 1;
}

if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) {
printf("0.1.2\n");
return 0;
}

char *filepath = argv[1];
if (!file_readable(filepath)) {
fprintf(stderr, "No readable file exists at '%s'\n", filepath);
Expand Down
20 changes: 19 additions & 1 deletion tests/test_executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,22 @@ def test_no_argument(self):
code, out, err = run_command(None)
self.assertEqual(code, 1)
self.assertEqual(out, "")
self.assertEqual(err, "Usage: skit YAMLFILE\n")
self.assertEqual(err, "Usage: skit [YAMLFILE|-v|--version]\n")

def test_invalid_flag(self):
code, out, err = run_command("--versionfoobar")
self.assertEqual(code, 1)
self.assertEqual(out, "")
self.assertEqual(err, "No readable file exists at '--versionfoobar'\n")

def test_version_command(self):
code, out, err = run_command("--version")
self.assertEqual(code, 0)
self.assertRegexpMatches(out, r"\d+\.\d+\.\d+")
self.assertEqual(err, "")

def test_short_version_command(self):
code, out, err = run_command("-v")
self.assertEqual(code, 0)
self.assertRegexpMatches(out, r"\d+\.\d+\.\d+")
self.assertEqual(err, "")

0 comments on commit 5f4e15c

Please sign in to comment.