MarkusAmshove / Kluent

Fluent Assertion-Library for Kotlin
https://markusamshove.github.io/Kluent/
MIT License
867 stars 64 forks source link

How to configure Kluent for kotlin native? #145

Closed tgeng closed 5 years ago

tgeng commented 5 years ago

Hi! First of all, thank you for this awesome testing library! It's very idiomatic and I have been enjoying using it very much!

So I am just trying to make it work with Kotlin native. Currently in my build.gradle, I have

        linuxTest {
            dependencies {
                implementation 'org.amshove.kluent:kluent-common:1.51'
            }
        }

But linking failed with

> Task :linkDebugTestLinux FAILED
e: /home/.../ReductionTest.kt: (3, 8): Unresolved reference: org
e: /home/.../ReductionTest.kt: (138, 77): Unresolved reference: shouldEqual

Am I missing something? Any help would be great! Thank you!

BTW, it would be great if this could be documented :smile:

MarkusAmshove commented 5 years ago

Thank you for the kind works :-)

Publishing a Native artifact is something I've been trying to do several times, as the recommended ways to do so change from time to time (on the side of Jetbrains).

I'm actually not sure if depending on the common artifact is supposed to work, although it makes sense. My current go to reference is the Gradle plugin

I'll give it another shot, since you're specifically asking for this :-) Do you have by any chance experience in distributing/publishing native libraries?

If you build Kluent with gradlew build -PNATIVE you can see that the native module runs all tests of the common project.

MarkusAmshove commented 5 years ago

You could give expectedBy instead of implementation a shot a and see if that works

MarkusAmshove commented 5 years ago

I think I've got something for you :-)

I have tried to implement the kotlin multiplatform plugin in gradle in this pr and got a working example project locally.

Can you give this a try?

build.gradle

plugins {
    id 'org.jetbrains.kotlin.multiplatform' version '1.3.41'
}
repositories {
    mavenCentral()
    maven { url "https://dl.bintray.com/markusamshove/maven" } // temporary until moved to jcenter
}
kotlin {
    linuxX64("linux") {
        binaries {
            executable {
               entryPoint = 'sample.main'
                runTask?.args('')
            }
        }
    }
    sourceSets {
        linuxMain {
            dependencies {
                implementation 'org.amshove.kluent:kluent-linux:+'
            }
        }
        linuxTest {
        }
    }
}

// Use the following Gradle tasks to run your application:
// :runReleaseExecutableLinux - without debug symbols
// :runDebugExecutableLinux - with debug symbols

My main:

package sample

import org.amshove.kluent.shouldEqual

fun hello(): String = "Hello, Kotlin/Native!"

fun main() {
    hello().shouldEqual("oops")
    println(hello())
}

results in (as expected):

13:59:26: Executing task 'runReleaseExecutableLinux'...

> Task :runReleaseExecutableLinux FAILED
Uncaught Kotlin exception: kotlin.AssertionError: Expected <oops>, actual <Hello, Kotlin/Native!>.
        at Init_and_run_start (0x21d25f)
        at __libc_start_main (0x7fc00ad8bf8a)
        at  (0x20f029)
        at  ((nil))
tgeng commented 5 years ago

Thanks for the super quick and very detailed replies! :smile:

Sorry I don't have experiences in publishing with Gradle and I am still learning how Gradle works in general.

So I tried with org.amshove.kluent:kluent-linux:1.52 and got permission error.

Execution failed for task ':linkDebugTestLinux'.
> Could not resolve all files for configuration ':linuxTestCompileKlibraries'.
   > Could not resolve org.amshove.kluent:kluent-linux:1.52.
     Required by:
         project :
      > Could not resolve org.amshove.kluent:kluent-linux:1.52.
         > Could not get resource 'https://dl.bintray.com/markusamshove/maven/org/amshove/kluent/kluent-linux/1.52/kluent-linux-1.52.pom'.
            > Could not GET 'https://dl.bintray.com/markusamshove/maven/org/amshove/kluent/kluent-linux/1.52/kluent-linux-1.52.pom'. Received status code 401 from server: Unauthorized

I suppose once this is published to jcenter it should work for me. :+1:

MarkusAmshove commented 5 years ago

The resolution itself is working then, which is great. I'll work out the PR cleanly and then update the issue when a proper version is released :-)

tgeng commented 5 years ago

Awesome! Thank you so much!

MarkusAmshove commented 5 years ago

Can you give it a try again? Current version which should work is 2.0 which I'll rerelease once ironed out. But it would be nice to get a second external test :-)

tgeng commented 5 years ago

Absolutely! I just tried with 2.0 and it works like charm! Thank you!

Tapchicoma commented 4 years ago

How could I access this 2.0 version to use kluent with linux native target?

I don't see it in this artifactory: https://dl.bintray.com/markusamshove/maven/org/amshove/kluent/

MarkusAmshove commented 4 years ago

Hi @Tapchicoma ,

my work on 2.0 is currently stalled because I don't have a lot of time to invest into it, but I'll invest some time to update the buildfiles (I guess they changed again for multiplatform) and try to republish the artifact

MarkusAmshove commented 4 years ago

You can give it a try now: https://bintray.com/markusamshove/maven/kluent/2.0#files/org%2Famshove%2Fkluent%2Fkluent-linux%2F2.0

Tapchicoma commented 4 years ago

This works :+1:

Though it is only available for linux native target and requires usage of separate artifact. If you want I could help with setting up library multiplatform publishing.

MarkusAmshove commented 4 years ago

I've only published Linux artifacts so you can try them out :-) I think I might have forgotten to publish the common part of the multiplatform project, is that the artifact you're refering to? The specific native project is going to have assertions for K/N, which aren`t implemented yet (think about Pointer assertions and such).

I'll gladly accept help in the port to 2.0, you can open PRs against kluent-v2 or look at #148 The build pipeline is already configured for multiplatform