From faabb01d0b295bf1c98544b8dc59515a9d534877 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Fri, 6 Nov 2015 04:04:12 -0500 Subject: [PATCH] Add test suite --- Dockerfile | 3 ++- engine.json | 11 +++++++++++ index.js | 10 +++++----- test/integration/fixme.rb | 41 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 engine.json create mode 100644 test/integration/fixme.rb diff --git a/Dockerfile b/Dockerfile index bcb85c8..1aecb17 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,12 +2,13 @@ FROM node MAINTAINER Michael R. Bernstein -RUN useradd -u 9000 -r -s /bin/false app +RUN useradd -u 9000 -r -s /bin/false app RUN npm install glob WORKDIR /code COPY . /usr/src/app +COPY engine.json / USER app VOLUME /code diff --git a/engine.json b/engine.json new file mode 100644 index 0000000..a37f3c9 --- /dev/null +++ b/engine.json @@ -0,0 +1,11 @@ +{ + "name": "fixme", + "description": "Discover lurking FIXMEs, BUGs, TODOs, etc. in your code", + "maintainer": { + "name": "Michael R. Bernstein", + "email": "mrb@codeclimate.com" + }, + "test_paths": [ + "/usr/src/app/test/integration/" + ] +} diff --git a/index.js b/index.js index e73b976..ad1a2db 100644 --- a/index.js +++ b/index.js @@ -16,14 +16,14 @@ var excludeExtensions = [".jpg", ".jpeg", ".png", ".gif"]; var printIssue = function(fileName, lineNum, matchedString){ var issue = { "type": "issue", - "check_name": "FIXME found", + "check_name": matchedString, "description": matchedString + " found", "categories": ["Bug Risk"], "location":{ "path": fileName, "lines": { "begin": lineNum, - "end": lineNum + "end": lineNum } } }; @@ -44,7 +44,7 @@ var findFixmes = function(file){ if (results !== ""){ // Parses grep output var lines = results.split("\n"); - + lines.forEach(function(line, index, array){ // grep spits out an extra line that we can ignore if(index < (array.length-1)){ @@ -57,7 +57,7 @@ var findFixmes = function(file){ var matchedString = cols[2]; if (matchedString !== undefined){ - printIssue(fileName, lineNum, matchedString); + printIssue(fileName, parseInt(lineNum), matchedString); } } }) @@ -82,7 +82,7 @@ var fileWalk = function(excludePaths){ analysisFiles.push(file); } }); - + return analysisFiles; } diff --git a/test/integration/fixme.rb b/test/integration/fixme.rb new file mode 100644 index 0000000..fa5c42c --- /dev/null +++ b/test/integration/fixme.rb @@ -0,0 +1,41 @@ +##################################################################### +##################################################################### +## Integration tests for this engine must escape uses of the magic +## keywords, otherwise the engine will flag additional issues on the +## lines with the test markers themselves. We use backslash escaping +## to avoid this problem. +##################################################################### +##################################################################### + +# [issue] check_name="F\IXME" description="F\IXME found" category="Bu\g Risk" +# FIXME: This is broken +x = x + +############################ + +foo = $stdin.gets +# [issue] check_name="B\UG" description="B\UG found" category="Bu\g Risk" +# BUG: This should use double equals +if (foo = "foo") + puts "You said foo" +end + +############################ + +foo = $stdin.gets +# [issue] check_name="X\XX" description="X\XX found" category="Bu\g Risk" +# XXX: This should use double equals +if (foo = "foo") + puts "You said foo" +end + +############################ + +# [issue] check_name="T\ODO" description="T\ODO found" category="Bu\g Risk" +# TODO: Add more tests + +############################ + +# [issue] check_name="H\ACK" description="H\ACK found" category="Bu\g Risk" +# HACK +instance_eval "CRAZY STUFF"