diff --git a/bin/codeclimate-checkstyle b/bin/codeclimate-checkstyle index 8958780..e87147a 100755 --- a/bin/codeclimate-checkstyle +++ b/bin/codeclimate-checkstyle @@ -7,10 +7,13 @@ $:.unshift(File.expand_path("../lib", File.dirname(__FILE__))) require "cc/engine/checkstyle" -if File.exist?("/config.json") - engine_config = JSON.parse(File.read("/config.json")) +config_file = ARGV[0] || "/config.json" + +if File.exist?(config_file) + engine_config = JSON.parse(File.read(config_file)) else engine_config = {} end CC::Engine::Checkstyle.new("/code", engine_config, STDOUT).run +exit($?.exitstatus) diff --git a/fixtures/Main.java b/fixtures/default/Main.java similarity index 100% rename from fixtures/Main.java rename to fixtures/default/Main.java diff --git a/fixtures/default/config.json b/fixtures/default/config.json new file mode 100644 index 0000000..41c1852 --- /dev/null +++ b/fixtures/default/config.json @@ -0,0 +1,6 @@ +{ + "enabled": true, + "include_paths": [ + "/usr/src/app/fixtures/default/Main.java" + ] +} diff --git a/fixtures/not_parseable/Template.java b/fixtures/not_parseable/Template.java new file mode 100644 index 0000000..8098a97 --- /dev/null +++ b/fixtures/not_parseable/Template.java @@ -0,0 +1,31 @@ +/* + * Generated by Mavanagaiata ${MAVANAGAIATA_VERSION} at ${TIMESTAMP} + */ + +package ${PACKAGE_NAME}; + +public final class ${CLASS_NAME} { + + public static final String BRANCH = "${BRANCH}"; + + public static final String COMMIT_ABBREV = "${COMMIT_ABBREV}"; + + public static final String COMMIT_SHA = "${COMMIT_SHA}"; + + public static final String DESCRIBE = "${DESCRIBE}"; + + public static final boolean DIRTY = ${DIRTY}; + + public static final String TAG = "${TAG_NAME}"; + + public static final String VERSION = "${VERSION}"; + + public static String getVersion() { + if (TAG.equals(VERSION) && TAG.equals(DESCRIBE)) { + return TAG; + } + + return String.format("%s (%s)", VERSION, DESCRIBE); + } + +} diff --git a/fixtures/not_parseable/config.json b/fixtures/not_parseable/config.json new file mode 100644 index 0000000..94f8a2c --- /dev/null +++ b/fixtures/not_parseable/config.json @@ -0,0 +1,6 @@ +{ + "enabled": true, + "include_paths": [ + "/usr/src/app/fixtures/not_parseable/Template.java" + ] +} diff --git a/spec/lib/cc/engine/checkstyle_spec.rb b/spec/lib/cc/engine/checkstyle_spec.rb index bb20d65..19ffa45 100644 --- a/spec/lib/cc/engine/checkstyle_spec.rb +++ b/spec/lib/cc/engine/checkstyle_spec.rb @@ -18,27 +18,27 @@ module Engine end it "uses default config" do - run_with("include_paths" => ["fixtures/Main.java"]) + run_with("include_paths" => ["fixtures/default/Main.java"]) end it "accepts config path" do run_with( "config" => "config/codeclimate_checkstyle.xml", - "include_paths" => ["fixtures/Main.java"], + "include_paths" => ["fixtures/default/Main.java"], ) end it "accepts config hash" do run_with( "config" => { "file" => "config/codeclimate_checkstyle.xml" }, - "include_paths" => ["fixtures/Main.java"], + "include_paths" => ["fixtures/default/Main.java"], ) end it "accepts config hash without file" do run_with( "config" => { "key" => "value" }, - "include_paths" => ["fixtures/Main.java"], + "include_paths" => ["fixtures/default/Main.java"], ) end diff --git a/spec/sanity_check_spec.rb b/spec/sanity_check_spec.rb index c9a5a09..401d6cc 100644 --- a/spec/sanity_check_spec.rb +++ b/spec/sanity_check_spec.rb @@ -2,10 +2,18 @@ describe "Sanity Check" do it "executes successfully with default config" do - pid, _, out, err = POSIX::Spawn.popen4("/usr/src/app/bin/codeclimate-checkstyle") + pid, _, out, err = POSIX::Spawn.popen4("/usr/src/app/bin/codeclimate-checkstyle", "/usr/src/app/fixtures/default/config.json") _, status = Process::waitpid2(pid) expect(status.exitstatus).to eq(0) expect(err.read).to be_empty end + + it "forwards exit code" do + pid, _, out, err = POSIX::Spawn.popen4("/usr/src/app/bin/codeclimate-checkstyle", "/usr/src/app/fixtures/not_parseable/config.json") + _, status = Process::waitpid2(pid) + + expect(status.exitstatus).to_not eq(0) + expect(err.read).to_not be_empty + end end
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: