All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sbt.testing.TaskDef.scala Maven / Gradle / Ivy

The newest version!
/*
 * Scala.js (https://www.scala-js.org/)
 *
 * Copyright EPFL.
 *
 * Licensed under Apache License 2.0
 * (https://www.apache.org/licenses/LICENSE-2.0).
 *
 * See the NOTICE file distributed with this work for
 * additional information regarding copyright ownership.
 */

package sbt.testing

import java.util.Arrays
import java.io.Serializable

/** A bundle of information used to request a Task from a test
 *  framework.
 *
 *  An array of TaskDef is passed to
 *  Runner's tasks method,
 *  which returns an array of Tasks.  Each returned task, when
 *  executed, will run tests and suites determined by the test class name,
 *  fingerprints, "explicitly specified" field, and selectors of one of the
 *  passed TaskDefs.
 *
 *  The "Explicitly specified" field means the user supplied a complete fully
 *  qualified test name, such as with the command:
 *
 *  {{{
 *  > test-only com.mycompany.myproject.WholeNameSpec
 *  }}}
 *
 *  as opposed to commands like:
 *
 *  {{{
 *  > test-only *WholeNameSpec
 *  }}}
 *
 *  or simply:
 *
 *  {{{
 *  > test
 *  }}}
 *
 *  The explicitlySpecified field will be true for in the first
 *  case, and false in the last two cases, because only in the first case was
 *  the fully qualified test class name completely specified by the user. The
 *  test framework can use this information to decide whether to ignore an
 *  annotation requesting a class not be discovered.
 *
 *  The fingerprint parameter indicates how the test suite was
 *  identified as a test suite. This tasks method may be called
 *  with TaskDefs containing the same value for
 *  testClassName but different fingerprints. For example, if both
 *  a class and its companion object were test classes, the tasks
 *  method could be passed an array containing TaskDefs with the
 *  same name but with a different value for fingerprint.isModule.
 *
 *  A test framework may "reject" a requested task by returning no
 *  Task for that TaskDef.
 *
 *  @param fullyQualifiedName the fully qualified name of the test class to be
 *            run by the requested task
 *  @param fingerprint indicates how the test suite was identified as a test
 *            suite
 *  @param explicitlySpecified indicates whether the test class was explicitly
 *            specified by user.
 *  @param selectors a possibly empty array of Selectors
 *            determining suites and tests to run
 */
final class TaskDef(_fullyQualifiedName: String, _fingerprint: Fingerprint,
    _explicitlySpecified: Boolean,
    _selectors: Array[Selector]) extends Serializable {

  if (_fullyQualifiedName == null)
    throw new NullPointerException("fullyQualifiedName was null");
  if (_fingerprint == null)
    throw new NullPointerException("fingerprint was null");
  if (_selectors == null)
    throw new NullPointerException("selectors was null");

  /** The fully qualified name of the test class requested by this
   *  TaskDef.
   */
  def fullyQualifiedName(): String = _fullyQualifiedName

  /** The fingerprint that the test class requested by this
   *  TaskDef matches.
   */
  def fingerprint(): Fingerprint = _fingerprint

  /** Indicates whether or not the test class requested by this
   *  TaskDef was "explicitly specified."
   *
   *  For more information on what explicitly specified means, see the main
   *  documentation for this class.
   */
  def explicitlySpecified(): Boolean = _explicitlySpecified

  /** One to many selectors describing the nature of the Task
   *  requested by this TaskDef.
   *
   *  A Selector can indicate a direct, such as command-line,
   *  request from the user or a "rerun" of previously run tests. In the latter
   *  case, the Selectors would be taken from those passed in
   *  events of a previous run or runs.
   */
  def selectors(): Array[Selector] = _selectors

  override def equals(that: Any): Boolean = that match {
    case that: TaskDef =>
      this.fullyQualifiedName()  == that.fullyQualifiedName() &&
      this.fingerprint()         == that.fingerprint() &&
      this.explicitlySpecified() == that.explicitlySpecified() &&
      Arrays.equals(
          this.selectors().asInstanceOf[Array[AnyRef]],
          that.selectors().asInstanceOf[Array[AnyRef]])
    case _ => false
  }

  override def hashCode(): Int = {
    var retVal = 17
    retVal = 31 * retVal + _fullyQualifiedName.hashCode()
    retVal = 31 * retVal + _fingerprint.hashCode()
    retVal = 31 * retVal + (if (_explicitlySpecified) 1 else 0)
    retVal = 31 * retVal + Arrays.hashCode(
        _selectors.asInstanceOf[Array[AnyRef]])
    retVal
  }

  override def toString(): String = {
    "TaskDef(" + _fullyQualifiedName + ", " + _fingerprint + ", " +
    _explicitlySpecified + ", " + _selectors.mkString("[", ", ", "]") + ")"
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy