<commit_before>/*
Copyright 2007-2009 WebDriver committers
Copyright 2007-2009 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */

package org.openqa.selenium;

import com.google.common.base.Supplier;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.IgnoredTestCallback;
import org.openqa.selenium.testing.InProject;
import org.openqa.selenium.testing.JavascriptEnabled;
import org.openqa.selenium.testing.drivers.Browser;
import org.openqa.selenium.testing.drivers.SauceDriver;
import org.openqa.selenium.testing.drivers.TestIgnorance;
import org.openqa.selenium.testing.drivers.WebDriverBuilder;

import java.io.File;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Set;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertTrue;

public class TestSuiteBuilder {
  private Set<File> sourceDirs = Sets.newHashSet();
  private boolean keepDriver;
  private boolean includeJavascript;
  private boolean withDriver = true;
  private boolean withEnvironment = true;
  private List<String> onlyRun = Lists.newArrayList();
  private Set<String> patterns = Sets.newHashSet();
  private Set<String> excludePatterns = Sets.newHashSet();
  private Set<String> testMethodNames = Sets.newHashSet();
  private Set<String> decorators = Sets.newLinkedHashSet();
  private Set<Package> packages = Sets.newLinkedHashSet();
  private Set<IgnoredTestCallback> ignoredTestCallbacks = Sets.newHashSet();
  private boolean outputTestNames = false;
  private File baseDir;
  private TestIgnorance ignorance = new TestIgnorance(Browser.none);
  private Browser browser;

  public TestSuiteBuilder() {
    baseDir = InProject.locate("Rakefile").getParentFile();
  }

  public TestSuiteBuilder addSourceDir(String dirName) {
    File toAdd = new File(baseDir, dirName);
    assertTrue("Directory does not exist:" + dirName, toAdd.exists());
    assertTrue("Directory is not a directory:" + dirName, toAdd.isDirectory());
    sourceDirs.add(toAdd);
    return this;
  }

  public TestSuiteBuilder using(Browser browser) {
    this.browser = browser;
    ignorance.setBrowser(browser);
    return this;
  }

  public TestSuiteBuilder keepDriverInstance() {
    keepDriver = true;

    return this;
  }

  /**
   * If the onlyRun list and the testMethodNames list are empty, the class name and the method name
   * defined in the system properties are added to the lists if they exist.
   */
  private void applySystemProperties() {
    // Add the test case rules defined in the system properties only if there
    // were no other test cases specified in the test suite specification.
    if (onlyRun.isEmpty()) {
      String onlyRunProperty = System.getProperty("only_run", "");
      if (!onlyRunProperty.equals("")) {
        onlyRun(onlyRunProperty);
      }
    }

    if (testMethodNames.isEmpty()) {
      String methodProperty = System.getProperty("method", "");
      if (!methodProperty.equals("")) {
        method(methodProperty);
      }
    }
  }

  public Test create() throws Exception {
    applySystemProperties();

    if (ignoredTestCallbacks.isEmpty()) {
      ignoredTestCallbacks.add(new LoggingIgnoreCallback());
    }

    if (withDriver) {
      assertThat("No driver class set", browser, is(notNullValue()));
    }

    TestSuite suite = new TestSuite();
    for (File dir : sourceDirs) {
      addTestsRecursively(suite, dir);
    }<commit_msg>DanielWagnerHall: Allow comma-delimited onlyrun property<commit_after>/*
Copyright 2007-2009 WebDriver committers
Copyright 2007-2009 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */

package org.openqa.selenium;

import com.google.common.base.Supplier;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.IgnoredTestCallback;
import org.openqa.selenium.testing.InProject;
import org.openqa.selenium.testing.JavascriptEnabled;
import org.openqa.selenium.testing.drivers.Browser;
import org.openqa.selenium.testing.drivers.SauceDriver;
import org.openqa.selenium.testing.drivers.TestIgnorance;
import org.openqa.selenium.testing.drivers.WebDriverBuilder;

import java.io.File;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Set;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertTrue;

public class TestSuiteBuilder {
  private Set<File> sourceDirs = Sets.newHashSet();
  private boolean keepDriver;
  private boolean includeJavascript;
  private boolean withDriver = true;
  private boolean withEnvironment = true;
  private List<String> onlyRun = Lists.newArrayList();
  private Set<String> patterns = Sets.newHashSet();
  private Set<String> excludePatterns = Sets.newHashSet();
  private Set<String> testMethodNames = Sets.newHashSet();
  private Set<String> decorators = Sets.newLinkedHashSet();
  private Set<Package> packages = Sets.newLinkedHashSet();
  private Set<IgnoredTestCallback> ignoredTestCallbacks = Sets.newHashSet();
  private boolean outputTestNames = false;
  private File baseDir;
  private TestIgnorance ignorance = new TestIgnorance(Browser.none);
  private Browser browser;

  public TestSuiteBuilder() {
    baseDir = InProject.locate("Rakefile").getParentFile();
  }

  public TestSuiteBuilder addSourceDir(String dirName) {
    File toAdd = new File(baseDir, dirName);
    assertTrue("Directory does not exist:" + dirName, toAdd.exists());
    assertTrue("Directory is not a directory:" + dirName, toAdd.isDirectory());
    sourceDirs.add(toAdd);
    return this;
  }

  public TestSuiteBuilder using(Browser browser) {
    this.browser = browser;
    ignorance.setBrowser(browser);
    return this;
  }

  public TestSuiteBuilder keepDriverInstance() {
    keepDriver = true;

    return this;
  }

  /**
   * If the onlyRun list and the testMethodNames list are empty, the class name and the method name
   * defined in the system properties are added to the lists if they exist.
   */
  private void applySystemProperties() {
    // Add the test case rules defined in the system properties only if there
    // were no other test cases specified in the test suite specification.
    String onlyRunProperty = System.getProperty("only_run", "");
    if (!onlyRunProperty.equals("")) {
      for (String classname : onlyRunProperty.split(",")) {
        onlyRun(classname);
      }
    }

    if (testMethodNames.isEmpty()) {
      String methodProperty = System.getProperty("method", "");
      if (!methodProperty.equals("")) {
        method(methodProperty);
      }
    }
  }

  public Test create() throws Exception {
    applySystemProperties();

    if (ignoredTestCallbacks.isEmpty()) {
      ignoredTestCallbacks.add(new LoggingIgnoreCallback());
    }

    if (withDriver) {
      assertThat("No driver class set", browser, is(notNullValue()));
    }

    TestSuite suite = new TestSuite();
    for (File dir : sourceDirs) {
      addTestsRecursively(suite, dir);
    }
{'fraction_non_alphanumeric': 0.09547267182735163, 'fraction_numerical': 0.004691531785127844, 'mean_word_length': 4.33270794246404, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6886561', 'n_tokens_mistral': 2458, 'n_tokens_neox': 2379, 'n_words': 704}