<commit_before>/*  ___ _  ___ _ _                                                            *\
** / __| |/ (_) | |       The SKilL Generator                                 **
** \__ \ ' <| | | |__     (c) 2013-16 University of Stuttgart                 **
** |___/_|\_\_|_|____|    see LICENSE                                         **
\*                                                                            */
package de.ust.skill.generator.interoperability

import java.io.BufferedWriter
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStreamWriter
import java.io.PrintWriter

import scala.reflect.io.Path.jfile2path

import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

import de.ust.skill.generator.common
import de.ust.skill.main.CommandLine
import org.json.JSONTokener
import org.json.JSONObject
import org.json.JSONArray
import scala.collection.JavaConverters._

/**
 * Generic tests built for interoparability.
 * Generic tests have an implementation for each programming language, because otherwise deleting the generated code
 * upfront would be ugly.
 *
 * @author <NAME>
 */
@RunWith(classOf[JUnitRunner])
class InteroperabilityTests extends common.GenericTests {

  override def language: String = "scala"

  override def deleteOutDir(out: String) {
    import scala.reflect.io.Directory
    Directory(new File("testsuites/interoperability/src/main/scala/", out)).deleteRecursively
  }

  override def callMainFor(name: String, source: String, options: Seq[String]) {
    CommandLine.exit = s ⇒ throw new RuntimeException(s)
    CommandLine.main(Array[String](source,
      "--debug-header",
      "-L", "scala",
      "-p", name,
      "-d", "testsuites/interoperability/lib",
      "-o", "testsuites/interoperability/src/main/scala") ++ options)
  }

  def newTestFile(packagePath: String, name: String): PrintWriter = {
    val f = new File(s"testsuites/interoperability/src/test/scala/$packagePath/Generic${name}Test.generated.scala")
    f.getParentFile.mkdirs
    f.createNewFile
    val rval = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "UTF-8")))

    rval.write(s"""
package $packagePath

mport scala.collection.mutable.HashSet
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.global
import scala.concurrent.Future
import scala.concurrent.duration.Duration.Inf

import de.ust.skill.common.scala.api.Access
import de.ust.skill.common.scala.api.Read
import de.ust.skill.common.scala.api.ReadOnly
import de.ust.skill.common.scala.api.SkillObject
import de.ust.skill.common.scala.internal.fieldTypes.MapType
import de.ust.skill.common.scala.internal.fieldTypes.SetType
import de.ust.skill.common.scala.internal.fieldTypes.SingleBaseTypeContainer


import $packagePath.api.SkillFile


/**
 * Tests the file reading capabilities.
 */
class Generic${name}Test extends CommonTest {
  test("${packagePath} - Java${name}Test") {
    compareFiles("src/test/resources/serializedTestfiles/java/${packagePath}/blub.sf",
                              "src/test/resources/serializedTestfiles/orakel/${packagePath}/blub.sf" );
  }

  test("${packagePath} - Scala${name}Test") {
    compareFiles("src/test/resources/serializedTestfiles/scala/${packagePath}/blub.sf",
                              "src/test/resources/serializedTestfiles/orakel/${packagePath}/blub.sf" );<commit_msg>Get files for the interoparabilityTest from src/test/resources/...<commit_after>/*  ___ _  ___ _ _                                                            *\
** / __| |/ (_) | |       The SKilL Generator                                 **
** \__ \ ' <| | | |__     (c) 2013-16 University of Stuttgart                 **
** |___/_|\_\_|_|____|    see LICENSE                                         **
\*                                                                            */
package de.ust.skill.generator.interoperability

import java.io.BufferedWriter
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStreamWriter
import java.io.PrintWriter

import scala.reflect.io.Path.jfile2path

import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

import de.ust.skill.generator.common
import de.ust.skill.main.CommandLine
import org.json.JSONTokener
import org.json.JSONObject
import org.json.JSONArray
import scala.collection.JavaConverters._

/**
 * Generic tests built for interoparability.
 * Generic tests have an implementation for each programming language, because otherwise deleting the generated code
 * upfront would be ugly.
 *
 * @author <NAME>
 */
@RunWith(classOf[JUnitRunner])
class InteroperabilityTests extends common.GenericTests {

  override def language: String = "scala"

  override def deleteOutDir(out: String) {
    import scala.reflect.io.Directory
    Directory(new File("testsuites/interoperability/src/main/scala/", out)).deleteRecursively
  }

  override def callMainFor(name: String, source: String, options: Seq[String]) {
    CommandLine.exit = s ⇒ throw new RuntimeException(s)
    CommandLine.main(Array[String](source,
      "--debug-header",
      "-L", "scala",
      "-p", name,
      "-d", "testsuites/interoperability/lib",
      "-o", "testsuites/interoperability/src/main/scala") ++ options)
  }

  def newTestFile(packagePath: String, name: String): PrintWriter = {
    val f = new File(s"testsuites/interoperability/src/test/scala/$packagePath/Generic${name}Test.generated.scala")
    f.getParentFile.mkdirs
    f.createNewFile
    val rval = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "UTF-8")))

    rval.write(s"""
package $packagePath

mport scala.collection.mutable.HashSet
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.global
import scala.concurrent.Future
import scala.concurrent.duration.Duration.Inf

import de.ust.skill.common.scala.api.Access
import de.ust.skill.common.scala.api.Read
import de.ust.skill.common.scala.api.ReadOnly
import de.ust.skill.common.scala.api.SkillObject
import de.ust.skill.common.scala.internal.fieldTypes.MapType
import de.ust.skill.common.scala.internal.fieldTypes.SetType
import de.ust.skill.common.scala.internal.fieldTypes.SingleBaseTypeContainer


import $packagePath.api.SkillFile


/**
 * Tests the file reading capabilities.
 */
class Generic${name}Test extends CommonTest {
  test("${packagePath} - Java${name}Test") {
    compareFiles("src/test/resources/serializedTestfiles/java/${packagePath}/blub.sf",
                              "src/test/resources/serializedTestfiles/orakel/${packagePath}/blub.sf");
  }

  test("${packagePath} - Scala${name}Test") {
    compareFiles("src/test/resources/serializedTestfiles/scala/${packagePath}/blub.sf",
                              "src/test/resources/serializedTestfiles/orakel/${packagePath}/blub.sf");
{'fraction_non_alphanumeric': 0.118488253319714, 'fraction_numerical': 0.0023347439077776155, 'mean_word_length': 3.0676557863501484, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6651247', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1994, 'n_words': 360}