Skip to content
This repository has been archived by the owner on Dec 10, 2022. It is now read-only.

Commit

Permalink
Improve coverage based on codecov (#243)
Browse files Browse the repository at this point in the history
* Improve coverage based on codecov

https://codecov.io/gh/jtransc/jtransc/src/f544e39efb5e153403ac07d234ffca45e6592d01/jtransc-utils/src/com/jtransc/template/Minitemplate.kt

- Test Minitemplate trim filter
- Test Minitemplate image_info with file and String-like

* Created jtransc-gen-common-tests

Put each language test in its generator subproject

* Further test additions
  • Loading branch information
soywiz committed Aug 10, 2017
1 parent f544e39 commit bd0a45d
Show file tree
Hide file tree
Showing 206 changed files with 290 additions and 50 deletions.
@@ -1,3 +1,5 @@
package com.jtransc.maven.buildjar

import com.jtransc.tools.HaxeTools
import org.apache.maven.plugin.AbstractMojo
import org.apache.maven.plugins.annotations.Component
Expand Down
Expand Up @@ -5,7 +5,6 @@ import com.jtransc.ast.FqName
import com.jtransc.ast.mangle
import com.jtransc.error.noImpl


class JavaIds(val parent: JavaIds? = null) {
companion object {
val SET = setOf(
Expand Down
@@ -0,0 +1,12 @@
package com.jtransc.maven.buildjar

import org.junit.Assert
import org.junit.Test

class JTranscBuildjarMojoTest {
@Test
fun name() {
val mojo = JTranscBuildjarMojo()
Assert.assertNotNull(mojo)
}
}
@@ -0,0 +1,13 @@
package com.jtransc.tools

import org.junit.Assert
import org.junit.Assert.*
import org.junit.Test

class HaxeToolsTest {
@Test
fun name() {
val haxeTools = HaxeTools
Assert.assertNotNull(haxeTools)
}
}
@@ -0,0 +1,13 @@
package com.jtransc.tools

import org.junit.Assert
import org.junit.Assert.*
import org.junit.Test

class JavaIdsTest {
@Test
fun name() {
val ids = JavaIds.SET
Assert.assertNotNull(ids)
}
}
15 changes: 15 additions & 0 deletions jtransc-debugger/test/com/jtransc/debugger/JTranscDebuggerTest.kt
@@ -0,0 +1,15 @@
package com.jtransc.debugger

import org.junit.Assert
import org.junit.Assert.*
import org.junit.Test

class JTranscDebuggerTest {
@Test
fun name() {
val debugger = JTranscDebugger(object : JTranscDebugger.EventHandler() {

})
Assert.assertNotNull(debugger)
}
}
11 changes: 11 additions & 0 deletions jtransc-debugger/test/com/jtransc/debugger/v8/NodeJSTest.kt
@@ -0,0 +1,11 @@
package com.jtransc.debugger.v8

import org.junit.Assert.*
import org.junit.Test

class NodeJSTest {
@Test
fun name() {

}
}
1 change: 1 addition & 0 deletions jtransc-gen-as3/build.gradle
Expand Up @@ -6,4 +6,5 @@ targetCompatibility = 1.6

dependencies {
compile project(':jtransc-core')
testCompile project(':jtransc-gen-common-tests')
}
Expand Up @@ -2,6 +2,7 @@ import as3.As3PureTest
import big.BigTest
import com.jtransc.BuildBackend
import com.jtransc.gen.as3.As3Target
import com.jtransc.gen.common._Base
import issues.issue130.Issue130
import javatest.misc.BenchmarkTest
import jtransc.bug.JTranscBug127
Expand Down
3 changes: 3 additions & 0 deletions jtransc-gen-common-tests/.gitignore
@@ -0,0 +1,3 @@
/target/
/build/
/out/
31 changes: 31 additions & 0 deletions jtransc-gen-common-tests/build.gradle
@@ -0,0 +1,31 @@
apply from: '../includeCommon.gradle'
apply from: '../include.gradle'
apply plugin: 'idea'

sourceCompatibility = 1.8
targetCompatibility = 1.8

evaluationDependsOn(':jtransc-rt')

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:${project.ext.kotlin_version}"
compile "org.jetbrains.kotlin:kotlin-runtime:${project.ext.kotlin_version}"
compile "org.jetbrains.kotlin:kotlin-reflect:${project.ext.kotlin_version}"

provided project(':jtransc-rt') // Needs to be provided so it doesn't include at runtime

compile project(':jtransc-core')
compile project(":jtransc-rt-core-kotlin")
compile project(":jtransc-rt-extended-charsets")
compile project(':jtransc-utils')
compile "junit:junit:4.12"
}

idea {
module {
//COMPILE
scopes.PROVIDED.plus += [configurations.provided]
}
}

project(':jtransc-gen-common-tests').compileKotlin.dependsOn(project(':jtransc-rt').test)
File renamed without changes.
@@ -1,3 +1,5 @@
package com.jtransc.gen.common

/*
* Copyright 2016 Carlos Ballesteros Velasco
*
Expand All @@ -14,14 +16,14 @@
* limitations under the License.
*/

import big.BigTest
import com.jtransc.*
import com.jtransc.ast.AstBuildSettings
import com.jtransc.ast.AstTypes
import com.jtransc.ast.ConfigMinimizeNames
import com.jtransc.ast.ConfigTreeShaking
import com.jtransc.error.invalidOp
import com.jtransc.gen.GenTargetDescriptor
import com.jtransc.gen.js.JsTarget
import com.jtransc.injector.Injector
import com.jtransc.log.log
import com.jtransc.maven.MavenGradleLocalRepository
Expand All @@ -31,9 +33,11 @@ import com.jtransc.vfs.UnjailedLocalVfs
import com.jtransc.vfs.parent
import org.junit.Assert
import java.io.File
import java.net.JarURLConnection
import java.net.URL

open class _Base {
open val DEFAULT_TARGET: GenTargetDescriptor = JsTarget()
open val DEFAULT_TARGET: GenTargetDescriptor get() = TODO()

open val BACKEND = BuildBackend.ASM
//open val BACKEND = BuildBackend.ASM2
Expand Down Expand Up @@ -72,19 +76,6 @@ open class _Base {
, MavenGradleLocalRepository.locateJars("org.jetbrains:annotations:13.0")
).flatMap { it }

val testClassesPaths = listOf(
// intellij
File("out/test/classes").absolutePath,
File("out/test/resources").absolutePath,
File("target/test-classes").absolutePath,
// gradle
File("build/classes/test").absolutePath,
File("build/resources/test").absolutePath,
// gradle >= 4
File("build/classes/java/test").absolutePath,
File("build/classes/kotlin/test").absolutePath
)

fun testClassNoLog(params: Params) {
println(params.clazz.name)
val expected = params.transformerOut(ClassUtils.callMain(params.clazz))
Expand Down Expand Up @@ -132,12 +123,63 @@ open class _Base {
return process.outerr;
}

fun getRootFromUrl(url: URL, numberOfPackages: Int): File {
val uri = url.toURI()
println("locateTestRootByClass.URI: $uri")
if (uri.toString().startsWith("jar:")) {
return File((url.openConnection() as JarURLConnection).jarFileURL.file)
} else {
val file = File(uri)
var out = file
for (n in 0 until numberOfPackages) out = out.parentFile
return out
}
}

fun locateTestRootByClass(clazz: Class<*>): File {
val canonicalName = clazz.canonicalName
val numberOfPackages = canonicalName.count { it == '.' || it == '/' } + 1
val bigTestPath = "${canonicalName.replace('.', '/')}.class"
//val path = ClassLoader.getSystemClassLoader().getResource(bigTestPath)
val url = this.javaClass.classLoader.getResource(bigTestPath)
return getRootFromUrl(url, numberOfPackages)
}

fun locateTestRootByResource(resourceName: String): File {
val numberOfPackages = resourceName.count { it == '/' } + 1
val url = this.javaClass.classLoader.getResource(resourceName)
return getRootFromUrl(url, numberOfPackages)
}

fun _action(params: Params, run: Boolean): JTranscBuild.Result {
val injector = Injector()
val projectRoot = locateProjectRoot()

val testRoot = locateTestRootByClass(BigTest::class.java)
val resourceRoot = locateTestRootByResource("filetoinclude.txt")

println("testRoot: $testRoot")
println("resourceRoot: $resourceRoot")

val rtAndCoreUnfiltered = listOf(
"jtransc-rt", "jtransc-rt-core",
"jtransc-rt-core-kotlin", "jtransc-rt-extended-charsets",
"jtransc-annotations"
).flatMap {
listOf(
testRoot.absolutePath.replace("jtransc-gen-common-tests", it),
resourceRoot.absolutePath.replace("jtransc-gen-common-tests", it)
)
}
val rtAndCoreFiltered = rtAndCoreUnfiltered.filter { File(it).exists() }

for (file in rtAndCoreUnfiltered) {
println("- RT: '$file': exists=${File(file).exists()}")
}
injector.mapInstances(
params.backend ?: BACKEND, ConfigClassPaths(testClassesPaths + kotlinPaths)
params.backend ?: BACKEND, ConfigClassPaths(
listOf(testRoot.absolutePath, resourceRoot.absolutePath) + kotlinPaths
)
)

injector.mapImpl<AstTypes, AstTypes>()
Expand All @@ -160,34 +202,9 @@ open class _Base {
debug = params.debug ?: DEBUG,
optimize = params.optimize ?: OPTIMIZE,
relooper = RELOOPER,
//relooper = false,
extra = params.extra ?: mapOf(),
analyzer = params.analyze ?: ANALYZER,
rtAndRtCore = listOf(
"jtransc-rt", "jtransc-rt-core",
"jtransc-rt-core-kotlin", "jtransc-rt-extended-charsets",
"jtransc-annotations"
).flatMap {
listOf(
// intellij
"$it/out/test/classes",
"$it/out/production/classes",
"$it/out/production/resources",
"$it/target/classes",
// gradle
"$it/build/classes/main",
"$it/build/resources/main",
// gradle >= 4
"$it/build/classes/java/main",
"$it/build/classes/kotlin/main",
"$it/build/classes/java/test",
"$it/build/classes/kotlin/test"
)
}.map {
projectRoot[it].realpathOS
}
.filter { File(it).exists() }
//.map { it.apply { println(it) } }
rtAndRtCore = rtAndCoreFiltered
)
)
if (run) build.buildAndRunCapturingOutput() else build.buildWithoutRunning()
Expand Down
@@ -1,3 +1,7 @@
package com.jtransc.gen.common

import com.jtransc.gen.common._Base

class _ManualTests : _Base() {
//@Test fun test123() {
// val classPaths = arrayListOf<String>()
Expand Down
1 change: 1 addition & 0 deletions jtransc-gen-cpp/build.gradle
Expand Up @@ -7,4 +7,5 @@ targetCompatibility = 1.6
dependencies {
compile project(':jtransc-core')
compile "org.rauschig:jarchivelib:0.7.1"
testCompile project(':jtransc-gen-common-tests')
}
Expand Up @@ -16,6 +16,7 @@

import big.BigTest
import big.HelloWorldTest
import com.jtransc.gen.common._Base
import com.jtransc.gen.cpp.CppTarget
import issues.issue130.Issue130
import javatest.finalize.FinalizeTest
Expand Down
1 change: 1 addition & 0 deletions jtransc-gen-cs/build.gradle
Expand Up @@ -6,4 +6,5 @@ targetCompatibility = 1.6

dependencies {
compile project(':jtransc-core')
testCompile project(':jtransc-gen-common-tests')
}
Expand Up @@ -3,6 +3,7 @@ import big.BigIOTest
import big.BigTest
import big.HelloWorldTest
import com.jtransc.BuildBackend
import com.jtransc.gen.common._Base
import com.jtransc.gen.cs.CSharpTarget
import issues.issue130.Issue130
import jtransc.ProcessTest
Expand Down
1 change: 1 addition & 0 deletions jtransc-gen-d/build.gradle
Expand Up @@ -6,4 +6,5 @@ targetCompatibility = 1.6

dependencies {
compile project(':jtransc-core')
testCompile project(':jtransc-gen-common-tests')
}
1 change: 1 addition & 0 deletions jtransc-main/test/DTest.kt → jtransc-gen-d/test/DTest.kt
@@ -1,6 +1,7 @@
import big.BigTest
import big.HelloWorldTest
import com.jtransc.BuildBackend
import com.jtransc.gen.common._Base
import com.jtransc.gen.d.DTarget
import issues.Issue100Double
import issues.issue130.Issue130
Expand Down
1 change: 1 addition & 0 deletions jtransc-gen-dart/build.gradle
Expand Up @@ -6,4 +6,5 @@ targetCompatibility = 1.6

dependencies {
compile project(':jtransc-core')
testCompile project(':jtransc-gen-common-tests')
}
Expand Up @@ -2,6 +2,7 @@ import big.AsyncIOTest
import big.BigIOTest
import big.BigTest
import com.jtransc.BuildBackend
import com.jtransc.gen.common._Base
import com.jtransc.gen.dart.DartTarget
import issues.issue130.Issue130
import jtransc.ProcessTest
Expand Down
1 change: 1 addition & 0 deletions jtransc-gen-haxe/build.gradle
Expand Up @@ -6,4 +6,5 @@ targetCompatibility = 1.6

dependencies {
compile project(':jtransc-core')
testCompile project(':jtransc-gen-common-tests')
}
Expand Up @@ -16,9 +16,9 @@

import big.BigTest
import big.HelloWorldTest
import com.jtransc.gen.common._Base
import com.jtransc.gen.haxe.HaxeTarget
import issues.Issue103
import issues.Issue219
import issues.Issue94Enum
import issues.issue130.Issue130
import issues.issue136.Issue136
Expand Down
5 changes: 3 additions & 2 deletions jtransc-gen-js/build.gradle
@@ -1,9 +1,10 @@
apply from: '../includeCommon.gradle'
apply from: '../include.gradle'

sourceCompatibility = 1.6
targetCompatibility = 1.6
sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile project(':jtransc-core')
testCompile project(':jtransc-gen-common-tests')
}

0 comments on commit bd0a45d

Please sign in to comment.