<commit_before>package com.google.javascript.clutz;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.*;

import com.google.javascript.clutz.Options;

import org.junit.Test;
import org.kohsuke.args4j.CmdLineException;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class OptionsTest {

  @Test
  public void testFullUsage() throws Exception {
    Options opts = new Options(new String[] {
        "foo.js", "--externs", "extern1.js", "extern2.js", "-o", "output.d.ts"
    });
    assertThat(opts.arguments).containsExactly("foo.js");
    assertThat(opts.externs).containsExactly("extern1.js", "extern2.js").inOrder();
    assertThat(opts.output).isEqualTo("output.d.ts");
  }

  @Test
  public void testFilterSourcesDepgraphs() throws Exception {
    Options opts = new Options(new String[] {
        "javascript/closure/other_file_not_in_depgraph.js",
        "javascript/closure/string/string.js",
        "blaze-out/blah/my/blaze-out-file.js",
        "--externs", "extern1.js", "extern2.js",
        "--depgraphs", DepgraphTest.DEPGRAPH_PATH.toFile().toString(),
        "--depgraphs_filter_sources",
        "-o", "output.d.ts"
    });
    // Outputs are filtered by what appears in the depgraph.
    assertThat(opts.arguments).containsExactly("javascript/closure/string/string.js",
        "blaze-out/blah/my/blaze-out-file.js").inOrder();
    assertThat(opts.externs)
        .containsExactly("extern1.js", "extern2.js", "javascript/common/dom.js")
        .inOrder();
    assertThat(opts.output).isEqualTo("output.d.ts");
  }

  @Test
  public void testClosureEntryPoint() throws Exception {
    Options opts = new Options(new String[] {
            "foo.js", "--closure_entry_points", "ns.entryPoint1", "ns.entryPoint2", "--externs", "extern1.js", "extern2.js", "-o", "output.d.ts"
    });
    assertThat(opts.arguments).containsExactly("foo.js");
    assertThat(opts.entryPoints).containsExactly("ns.entryPoint1", "ns.entryPoint2");
    assertThat(opts.externs).containsExactly("extern1.js", "extern2.js").inOrder();
    assertThat(opts.output).isEqualTo("output.d.ts");
  }

  @Test
  public void testHandleEmptyCommandLine() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    System.setErr(new PrintStream(out));
    try {
      new Options(new String[0]);
      fail("Should throw");
    } catch (CmdLineException expected) {
      assertThat(expected.getMessage()).isEqualTo("No files were given");
    }
  }
}
<commit_msg>Fixes tests for Options.<commit_after>package com.google.javascript.clutz;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.*;

import com.google.javascript.clutz.Options;

import org.junit.Test;
import org.kohsuke.args4j.CmdLineException;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class OptionsTest {

  @Test
  public void testFullUsage() throws Exception {
    Options opts = new Options(new String[] {
        "foo.js", "--externs", "extern1.js", "extern2.js", "-o", "output.d.ts"
    });
    assertThat(opts.arguments).containsExactly("foo.js");
    assertThat(opts.externs).containsExactly("extern1.js", "extern2.js").inOrder();
    assertThat(opts.output).isEqualTo("output.d.ts");
  }

  @Test
  public void testFilterSourcesDepgraphs() throws Exception {
    Options opts = new Options(new String[] {
        "javascript/closure/other_file_not_in_depgraph.js",
        "javascript/closure/string/string.js",
        "blaze-out/blah/my/blaze-out-file.js",
        "--externs", "extern1.js", "extern2.js",
        "--depgraphs", DepgraphTest.DEPGRAPH_PATH.toFile().toString(),
        "--depgraphs_filter_sources",
        "-o", "output.d.ts"
    });
    // Outputs are filtered by what appears in the depgraph.
    assertThat(opts.arguments).containsExactly("javascript/closure/string/string.js",
        "blaze-out/blah/my/blaze-out-file.js").inOrder();
    assertThat(opts.externs)
        .containsExactly("extern1.js", "extern2.js", "javascript/common/dom.js")
        .inOrder();
    assertThat(opts.output).isEqualTo("output.d.ts");
  }

  @Test
  public void testClosureEntryPoint() throws Exception {
    Options opts = new Options(new String[] {
            "foo.js", "--closure_entry_points", "ns.entryPoint1", "ns.entryPoint2", "--externs", "extern1.js", "extern2.js", "-o", "output.d.ts"
    });
    assertThat(opts.arguments).containsExactly("foo.js");
    assertThat(opts.entryPoints).containsExactly("ns.entryPoint1", "ns.entryPoint2");
    assertThat(opts.externs).containsExactly("extern1.js", "extern2.js").inOrder();
    assertThat(opts.output).isEqualTo("output.d.ts");
  }

  @Test
  public void testHandleEmptyCommandLine() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    System.setErr(new PrintStream(out));
    try {
      new Options(new String[0]);
      fail("Should throw");
    } catch (CmdLineException expected) {
      assertThat(expected.getMessage()).isEqualTo("No files or externs were given");
    }
  }

  @Test
  public void testShouldSupportExternsOnly() throws Exception {
    Options opts = new Options(new String[] { "--externs", "extern1.js"});
    assertThat(opts.externs).containsExactly("extern1.js");
  }
}

{'fraction_non_alphanumeric': 0.15567282321899736, 'fraction_numerical': 0.007161703731624576, 'mean_word_length': 3.8157894736842106, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2979099', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1655, 'n_words': 283}