### Question:
GroovyCommand implements CliCommand { @Override public int run(ProcessStream process) throws CmdLineException { Binding binding = CONFIG.getDefaultBinding(process, args, runtime); if (runtime != null) { binding.setProperty("runtime", runtime); } GroovyShell shell = new GroovyShell(binding, CONFIG.getCompilerConfiguration()); CONFIG.setupDecorateMethods(); Object exitVal = shell.run(getScript(process), "dumpling-script", args.toArray(new String[args.size()])); if (exitVal != null) { if (exitVal instanceof ModelObject) { final ModelObject model = (ModelObject) exitVal; model.toString(process.out(), porcelain ? Mode.MACHINE : Mode.HUMAN); } else { process.out().println(exitVal); } } if (exitVal instanceof Boolean) { return Boolean.TRUE.equals(exitVal) ? 0 : -1; } else if (exitVal instanceof Integer) { return ((Integer) exitVal); } return 0; }  @Override String getName(); @Override String getDescription(); @Override int run(ProcessStream process);  }### Answer:
@Test public void runScriptThatDoesNotExist() { run("groovy", "--script", "no_such_file"); assertThat(out.toString(), equalToString("")); assertThat(err.toString(), containsString("no_such_file")); assertThat(exitValue, not(equalTo(0))); }
@Test public void runScriptThatDoesExist() throws Exception { File file = File.createTempFile("dumpling-GroovyCommandTest", "script"); try { PrintWriter writer = new PrintWriter(file); writer.println("println 'groovy out'; return 42;"); writer.close(); run("groovy", "--script", file.getAbsolutePath()); assertThat(out.toString(), equalToString("groovy out%n42%n")); assertThat(err.toString(), equalToString("")); assertThat(exitValue, equalTo(42)); } finally { file.delete(); } }
@Test public void porcelain() throws Exception { final String log = Util.asFile(Util.resource("jstack/producer-consumer.log")).getAbsolutePath(); stdin("D.runtime.threads%n"); run("groovy", "--in", "threaddump:" + log); assertThat(this, succeeded()); assertThat(out.toString(), containsString("\"blocked_thread\" prio=10 tid=0x2ad39c16b800 nid=32297")); assertThat(out.toString(), containsString("- waiting to lock <0x4063a9378> (a hudson.model.Queue)")); stdin("D.runtime.threads%n"); run("groovy", "--in", "threaddump:" + log, "--porcelain"); assertThat(this, succeeded()); assertThat(out.toString(), containsString("\"blocked_thread\" prio=10 tid=0x00002ad39c16b800 nid=0x7e29")); assertThat(out.toString(), containsString("- waiting to lock <0x00000004063a9378> (a hudson.model.Queue)")); }
@Test public void scriptFromStdinExplicit() throws Exception { stdin("7*6%n"); run("groovy", "--script", "-"); assertThat(exitValue, equalTo(42)); assertThat(out.toString(), containsString("42")); }
@Test public void verbatimScript() throws Exception { run("groovy", "--expression", "7*6"); assertThat(exitValue, equalTo(42)); assertThat(out.toString(), containsString("42")); }
@Test public void groovyNativeArgsVar() { run("groovy", "-e", "assert args[0] == D.args[0] && args[1] != D.args[0]", "1", "2"); assertThat(exitValue, equalTo(0)); }
@Test public void hasHelp() { run("help", "groovy"); assertThat(out.toString(), containsString("All Dumpling DSL classes and methods are imported")); }