<commit_before>/**
 * Copyright (C) 2012 Typesafe, Inc. <http://www.typesafe.com>
 */

import sbt._
import sbt.complete._
import sbt.Keys._
import sbt.Project.Initialize

object Scriptit {
  import Script._

  val scriptitBase = SettingKey[File]("scriptit-base")
  val scriptitTestName = SettingKey[String]("scriptit-test-name")
  val scriptitCommands = TaskKey[Seq[Command]]("scriptit-commands")
  val scriptitScalaVersions = SettingKey[Seq[String]]("scriptit-scala-versions")
  val scriptitProperties = TaskKey[Map[String, String]]("scriptit-properties")
  val scriptit = InputKey[Unit]("scriptit")

  lazy val settings: Seq[Setting[_]] = Seq(
    scriptitBase <<= sourceDirectory / "scriptit",
    scriptitTestName := "test",
    scriptitCommands := Commands.defaultCommands,
    scriptitCommands <+= (Dist.create in ZincBuild.dist) map Commands.zincCommand,
    scriptitScalaVersions := Seq("2.9.2", "2.10.0"),
    scriptitProperties <<= (appConfiguration, scriptitScalaVersions) map scalaProperties,
    scriptitProperties ++= javaProperties,
    scriptit <<= scriptitTask
  )

  def scriptitTask = InputTask((scriptitBase, scriptitTestName)((dir, name) => (s: State) => scriptitParser(dir, name))) { input =>
    (scriptitBase, scriptitTestName, scriptitCommands, scriptitProperties, input, streams) map { (base, scriptName, commands, properties, args, s) =>
      val tests = if (args.isEmpty) scriptitTests(base, scriptName) else args
      val parse = new ScriptParser
      val results = tests map { test =>
        val dir = base / test
        val scriptFile = dir / scriptName
        val script = parse(IO.read(scriptFile))
        withTestDirectory(dir)(runTest(test, scriptFile.getPath, script, commands, properties, s.log))
      }
      val failed = results count (r => !r.success)
      if (failed > 0) {
        val counted = sbt.Util.counted("test", "", "s", failed).getOrElse("test")
        sys.error(counted + " failed")
      }
    }
  }

  def scriptitParser(scriptitBase: File, script: String): Parser[Seq[String]] =
    Defaults.distinctParser(scriptitTests(scriptitBase, script).toSet, raw = false)

  def scriptitTests(scriptitBase: File, script: String): Seq[String] =
    (scriptitBase ** script).get map (_.getParentFile) x relativeTo(scriptitBase) map (_._2)

  def runTest(name: String, path: String, script: Seq[Line], commands: Seq[Command], properties: Map[String, String], log: Logger)(dir: File): Result = {
    val runner = new ScriptRunner(name, path, script)<commit_msg>Update test scala versions to 2.9.3 and 2.10.2<commit_after>/**
 * Copyright (C) 2012 Typesafe, Inc. <http://www.typesafe.com>
 */

import sbt._
import sbt.complete._
import sbt.Keys._
import sbt.Project.Initialize

object Scriptit {
  import Script._

  val scriptitBase = SettingKey[File]("scriptit-base")
  val scriptitTestName = SettingKey[String]("scriptit-test-name")
  val scriptitCommands = TaskKey[Seq[Command]]("scriptit-commands")
  val scriptitScalaVersions = SettingKey[Seq[String]]("scriptit-scala-versions")
  val scriptitProperties = TaskKey[Map[String, String]]("scriptit-properties")
  val scriptit = InputKey[Unit]("scriptit")

  lazy val settings: Seq[Setting[_]] = Seq(
    scriptitBase <<= sourceDirectory / "scriptit",
    scriptitTestName := "test",
    scriptitCommands := Commands.defaultCommands,
    scriptitCommands <+= (Dist.create in ZincBuild.dist) map Commands.zincCommand,
    scriptitScalaVersions := Seq("2.9.3", "2.10.2"),
    scriptitProperties <<= (appConfiguration, scriptitScalaVersions) map scalaProperties,
    scriptitProperties ++= javaProperties,
    scriptit <<= scriptitTask
  )

  def scriptitTask = InputTask((scriptitBase, scriptitTestName)((dir, name) => (s: State) => scriptitParser(dir, name))) { input =>
    (scriptitBase, scriptitTestName, scriptitCommands, scriptitProperties, input, streams) map { (base, scriptName, commands, properties, args, s) =>
      val tests = if (args.isEmpty) scriptitTests(base, scriptName) else args
      val parse = new ScriptParser
      val results = tests map { test =>
        val dir = base / test
        val scriptFile = dir / scriptName
        val script = parse(IO.read(scriptFile))
        withTestDirectory(dir)(runTest(test, scriptFile.getPath, script, commands, properties, s.log))
      }
      val failed = results count (r => !r.success)
      if (failed > 0) {
        val counted = sbt.Util.counted("test", "", "s", failed).getOrElse("test")
        sys.error(counted + " failed")
      }
    }
  }

  def scriptitParser(scriptitBase: File, script: String): Parser[Seq[String]] =
    Defaults.distinctParser(scriptitTests(scriptitBase, script).toSet, raw = false)

  def scriptitTests(scriptitBase: File, script: String): Seq[String] =
    (scriptitBase ** script).get map (_.getParentFile) x relativeTo(scriptitBase) map (_._2)

  def runTest(name: String, path: String, script: Seq[Line], commands: Seq[Command], properties: Map[String, String], log: Logger)(dir: File): Result = {
    val runner = new ScriptRunner(name, path, script)
{'fraction_non_alphanumeric': 0.1332279106542795, 'fraction_numerical': 0.006523028266455821, 'mean_word_length': 4.326315789473684, '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': '3477515', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1565, 'n_words': 380}