### Question:
Cli { public void run(String[] args, Writer out) { try { doRun(args, out); } catch (Exception e) { e.printStackTrace(); } }  void run(String[] args, Writer out);  }### Answer:
@Test public void testUsage() { assertThat(run()).contains("usage:"); }
@Test public void testHelp() { assertThat(run("-h")).contains("usage:"); }
@Test public void testVar() { assertThat(run("-v", "x=1", "-v", "a=3", "-e", "Int(x) + Int(a)")).isEqualTo("4"); }
@Test public void testFile() throws Exception { File file = folder.newFile(); Files.write(file.toPath(), "Int(x) + Int(a)".getBytes("UtF-8")); assertThat(run("-vx=1", "-va=3", "-e", "-f", file.getAbsolutePath())).isEqualTo("4"); }
@Test public void testError() { assertThat(run("-x")).isEqualTo("Unrecognized option: -x"); }
@Test public void testVersion() { assertThat(run("--version")).isEqualTo("unknown"); }
@Test public void testNewLine() { assertThat(run(true, "{{\"\\n\"}}")).isEqualTo("\n"); }
@Test public void testNewLineExpr() { assertThat(run(true, "-e", "'\\n'")).isEqualTo("\n"); }
@Test public void testInput() { System.setIn(new ByteArrayInputStream("line1\nline2\n".getBytes())); String sep = System.lineSeparator(); assertThat(run(true, "-e", "-in", "$ + 'a' + nl")).isEqualTo(format("line1a%sline2a%s", sep, sep)); }
@Test public void testPipe() { assertThat(run("-e", "\"hello\" | uppercase")).isEqualTo("HELLO"); }
@Test public void testNew() { genCli = new ngoy.core.gen.Cli() { @Override public void run(String[] args, Writer out) { try { out.write(asList(args).toString()); } catch (IOException e) { throw NgoyException.wrap(e); } } }; assertThat(run("new", "org.myapp.Qbert")).isEqualTo("[project, org.myapp.Qbert]"); }
@Test public void testGen() { genCli = new ngoy.core.gen.Cli() { @Override public void run(String[] args, Writer out) { try { out.write(asList(args).toString()); } catch (IOException e) { throw NgoyException.wrap(e); } } }; assertThat(run("g", "c", "person", "-p", "abc")).isEqualTo("[c, person, -p, abc]"); }
@Test public void test() { prevOut.print(run()); }