https://kotlinlang.org logo
a

amanda.hinchman-dominguez

10/25/2019, 11:01 PM
Hi! I migrated my work-in-progress PR over to
arrow-meta
, made sure that the gradle was synced to itself, set the JDK to 1.8, ran the
./gradlew
tasks in the CLI, and tried to run the tests from the IDE. Unfortunately, I'm getting this:
j

jereksel

10/25/2019, 11:06 PM
I also had similar test errors - they are gone when
Run tests using
is set to
Gradle (Default)
- in Settings -> Build, Execution, Deployment -> Build Tools -> Gradle
😮 1
a

amanda.hinchman-dominguez

10/25/2019, 11:11 PM
Okay! Imma try that
There's some improvement, but for some reason I'm unable to run the stack trace here
message has been deleted
Are there any quirks with this task?
j

jereksel

10/25/2019, 11:53 PM
a

amanda.hinchman-dominguez

10/25/2019, 11:57 PM
oh yeah - so sorry this is something I'm writing out right now - at the moment, I'm just trying to compile some source code with testing and do an IrDump to see what kind of trees I'm working with - this is something that may not be a feature until after Kotlinconf, but the linked issue is with it!
it could just be the way I set up my project
j

jereksel

10/26/2019, 12:01 AM
CI does not pass: https://github.com/arrow-kt/arrow-meta/pull/11/checks?check_run_id=275303006 It's certainly not issue with your setup
a

amanda.hinchman-dominguez

10/26/2019, 12:03 AM
Right, it would have failed for the very reason I was talking about
This is a PR marked "WIP", so it's not anywhere near done
r

Rachel

10/27/2019, 5:20 PM
Hi @amanda.hinchman-dominguez, I couldn't see the exceptions in your screenshot before
FAILURE: Build failed with an exception
so I downloaded your branch and I tried to run the tests.
I got these exceptions:
Copy code
e: (...) /EqOperatorTest.kt: (3, 12): Unresolved reference: tschuchort
e: (...) /EqOperatorTest.kt: (4, 12): Unresolved reference: tschuchort
e: (...) /EqOperatorTest.kt: (48, 5): Unresolved reference: KotlinCompilation
e: (...) /EqOperatorTest.kt: (49, 7): Unresolved reference: sources
e: (...) /EqOperatorTest.kt: (49, 24): Unresolved reference: SourceFile
e: (...) /EqOperatorTest.kt: (50, 7): Unresolved reference: classpaths
e: (...) /EqOperatorTest.kt: (51, 7): Unresolved reference: pluginClasspaths
They come from:
Copy code
import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.SourceFile
EqOperatorTest
is including these dependencies which are being used in
testing-plugin
.
testing-plugin/build.gradle
is ready to include them with
implementation "com.github.arrow-kt:kotlin-compile-testing:$kotlin_compile_testing"
.
I imagine that
compileSourceCode
and
classpathOf
were included temporarily in
EqOperatorTest
to run just a compilation without any other assertions.
In that case, to run those tests in
EqOperatorTest
, it would be necessary to include:
Copy code
testImplementation "com.github.arrow-kt:kotlin-compile-testing:1.2.3-SNAPSHOT"
in
compiler-plugin/build.gradle
.
After doing that, I got an error with:
Copy code
classpaths = listOf(classpathOf("arrow-meta-prototype:rr-meta-prototype-integration-SNAPSHOT"))
because that dependency doesn't exist.
I suppose you were looking for a dependency to use
extension
annotation.
That annotation exists in
arrow-annotations
so that line would be:
Copy code
classpaths = listOf(classpathOf("arrow-annotations:rr-meta-prototype-integration-SNAPSHOT"))
Tests will be green with those changes ✔️
However, compilation is failing.
testing-plugin
isn't being used here, only
compileSourceCode
and
classpathOf
which are in the same test class, so there aren't checks to inspect the result of the compilation.
In
EqOperatorTest
, it`s necessary to look at the log:
Copy code
e: /tmp/Kotlin-Compilation3830289531150025141/sources/Example.kt: (1, 1): Expecting a top level declaration
e: /tmp/Kotlin-Compilation3830289531150025141/sources/Example.kt: (2, 1): Expecting a top level declaration
e: /tmp/Kotlin-Compilation3830289531150025141/sources/Example.kt: (2, 4): Unresolved reference: extension
and for the second test:
Copy code
e: /tmp/Kotlin-Compilation1071656820347319429/sources/Example.kt: (1, 1): Expecting a top level declaration
e: /tmp/Kotlin-Compilation1071656820347319429/sources/Example.kt: (2, 1): Expecting a top level declaration
e: /tmp/Kotlin-Compilation1071656820347319429/sources/Example.kt: (3, 1): Expecting a top level declaration
e: /tmp/Kotlin-Compilation1071656820347319429/sources/Example.kt: (4, 1): Expecting a top level declaration
e: /tmp/Kotlin-Compilation1071656820347319429/sources/Example.kt: (5, 1): Expecting a top level declaration
e: /tmp/Kotlin-Compilation1071656820347319429/sources/Example.kt: (6, 1): Expecting an element
e: /tmp/Kotlin-Compilation1071656820347319429/sources/Example.kt: (7, 1): Expecting an element
e: /tmp/Kotlin-Compilation1071656820347319429/sources/Example.kt: (8, 1): Expecting a top level declaration
e: /tmp/Kotlin-Compilation1071656820347319429/sources/Example.kt: (9, 1): Expecting a top level declaration
e: /tmp/Kotlin-Compilation1071656820347319429/sources/Example.kt: (4, 4): Unresolved reference: extension
e: /tmp/Kotlin-Compilation1071656820347319429/sources/Example.kt: (5, 16): Unresolved reference: Eq
e: /tmp/Kotlin-Compilation1071656820347319429/sources/Example.kt: (5, 28): Unresolved reference: eq
e: /tmp/Kotlin-Compilation1071656820347319429/sources/Example.kt: (6, 8): Unresolved reference: eqv
If you look at those
Example.kt
files, you'll see the source code with
|
.
It's necessary to remove
|
from code snippets (it's already done in
testing-plugin
).
It would be necessary to execute `trimMargin`:
Copy code
compileSourceCode(EQ_FUNCTION.trimMargin())

...

compileSourceCode(EQ_EXTENSION.trimMargin())
It's also necessary to include the import for
extension
annotation at the beginning of each snippet:
Copy code
| import arrow.extension
After that, there are other compilation errors that can be seen at log.
I hope these steps are useful for you to continue.
a

amanda.hinchman-dominguez

10/27/2019, 5:28 PM
Yes, you are correct - I am just running some tests for an irTreeDump to see what I'm working with - no actual tests are being written at the moment.
👍 1
This is a really interesting insight! I was trying to mess with the compile configurations for the classpaths but couldn't understand how or why it worked.
So what you're saying is that I have to set Kotlin configurations according to the appropriate plugin the test resides in and add the snapshot, is that correct? i.e.
com.github.arrow-kt:kotlin-compile-testing:1.2.3-SNAPSHOT
👍 1
I'm taking some time to start with some of this again (and prepare notes about what I've learned so far today) - thank you so much for the pointer!
🤗 1
r

Rachel

10/27/2019, 5:49 PM
Right, that would be a necessary change and the rest of the changes:
Copy code
classpaths = listOf(classpathOf("arrow-annotations:rr-meta-prototype-integration-SNAPSHOT"))
instead of:
Copy code
classpaths = listOf(classpathOf("arrow-meta-prototype:rr-meta-prototype-integration-SNAPSHOT"))
Include trimMargin:
Copy code
compileSourceCode(EQ_FUNCTION.trimMargin())

...

compileSourceCode(EQ_EXTENSION.trimMargin())
After that, there are other compilation errors that can be seen at log.
a

amanda.hinchman-dominguez

10/27/2019, 8:16 PM
Thanks, I'll try your formatting suggestions. As for everything else, I was getting the same results with your configurations as well, which is why I wanted to pull it out and see if the behavior is still the same
👍 1
Why do you have to remove the
|
from the comments for compiling source code?
r

Rachel

10/27/2019, 9:46 PM
Because they aren't expected. Each code snippet is thought as source code in a .kt file with its imports at the beginning if they are needed.
By the way, good news Amanda! 🎉 If you rebase your branch with
master
branch, you'll get a new way to add the test you're looking for: just checking that it compiles
For instance:
Copy code
val compilerPlugin = CompilerPlugin("Arrow Meta", listOf(Dependency("compiler-plugin")))
    val arrowAnnotations = Dependency("arrow-annotations:rr-meta-prototype-integration-SNAPSHOT")

  assertThis(CompilerTest(
      config = {
        addCompilerPlugins(compilerPlugin) + addDependencies(arrowAnnotations)
      },
      code = {
        """
        |
        | (code snippet)
        | 
        """.source
      },
      assert = {
        compiles
      }
    ))
So it won't be necessary to check the log in your tests 🎉
a

amanda.hinchman-dominguez

10/27/2019, 11:22 PM
I'm not actually checking that something compiles - I'm simply trying to get an irDump in debugging
👍 1
But I can pull it down anyway to make sure the code is updated
👍 1
👏 1
7 Views