Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gradle: fix test target for cli, examples, pts #351

Merged
merged 3 commits into from
Jan 6, 2021
Merged

gradle: fix test target for cli, examples, pts #351

merged 3 commits into from
Jan 6, 2021

Conversation

evanj
Copy link
Contributor

@evanj evanj commented Dec 24, 2020

Description of changes:

The following gradle targets were not running any of the unit tests
contained in their directories due to incorrect test dependencies. It
appears these projects all use JUnit 5 "vintage" tests, so need that
engine as a test dependency.

:cli:test
:examples:test
:pts:test

CliTest: Add test for the PARTIQL_PRETTY output format added in commit
9175002. This was how I discovered this issue.

examples: Remove tests from the implementation dependencies.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

The following gradle targets were not running any of the unit tests
contained in their directories due to incorrect test dependencies. It
appears these projects all use JUnit 5 "vintage" tests, so need that
engine as a test dependency.

    :cli:test
    :examples:test
    :pts:test

CliTest: Add test for the PARTIQL_PRETTY output format added in commit
9175002. This was how I discovered this issue.

examples: Remove tests from the implementation dependencies.
Comment on lines +48 to +50
if (originalAst != deserializedAst) {
throw Exception("expected AST to be equal")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we instead use the assertEquals with a message parameter for the exception? I am not sure what we are gaining by using if and throwing our own exception here, perhaps I am missing something though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason was to avoid requiring the kotlin-test JAR from code that is technically not an automated unit test. I will revert that part of the change since you would prefer to use this dependency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining. In that case, ignore my comments for this file on using assert. Let's keep the examples clean of testing libs.

Comment on lines +60 to +62
if (statement != roundTrippedStatement) {
throw Exception("Expected statements to be the same")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same argument here concerning assertEquals

Comment on lines -60 to -61
// PTS
testImplementation project(':testscript')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this dependency breaking anything? This (I believe) is what hooks into the PTS (included in this repo) system which runs more tests focusing on spec compliance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not breaking anything, but it seems to be unnecessary as the code builds without it? I haven't read the code in detail, but it appears to me that the dependency tree is that the pts targets/directory imports the code in testscript. I was assuming that means those are the targets that actually use this code. Nothing in the lang directory references testscript AFAIK?

I barely understand this though; I just was curious if all these dependencies were actually needed. I will revert my changes to this file: the important updates are to cli, examples, and pts so ./gradlew test actually executes the tests in those directories.

Copy link
Member

@alancai98 alancai98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I think my previous PR (#338) to fix Gradle to run on ParameterizedTests introduced this testing target bug.

Only have a few nits/questions.

import com.amazon.ion.system.*
import org.partiql.examples.util.Example
import org.partiql.lang.ast.*
import org.partiql.lang.domains.PartiqlAst
import org.partiql.lang.syntax.*
import java.io.PrintStream
import java.util.Objects
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unused import

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops thanks sorry; This was a stray import from a previous edit.

Comment on lines 118 to 119
val subject = makeCli("SELECT * FROM input_data", "{a: 1, b: 2}",
outputFormat = OutputFormat.PARTIQL_PRETTY)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could move onto the same line as the previous test

Suggested change
val subject = makeCli("SELECT * FROM input_data", "{a: 1, b: 2}",
outputFormat = OutputFormat.PARTIQL_PRETTY)
val subject = makeCli("SELECT * FROM input_data", "{a: 1, b: 2}", outputFormat = OutputFormat.PARTIQL_PRETTY)

@@ -1,6 +1,5 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
id 'io.gitlab.arturbosch.detekt'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this plugin removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand gradle. I assumed since this file has no references to it, this is unnecessary?

The top level build.gradle references detekt, and I assumed the apply plugin thing attempts to apply the plugin to all subprojects? If so, doesn't that mean this is unnecessary, since the top level project includes it?

FWIW, with this change, the ./gradlew cli:detekt task still seems to work?

~/partiql-lang-kotlin $ ./gradlew cli:detekt --info
...
> Task :cli:detekt UP-TO-DATE
...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't understand gradle too well. You seem to be right regarding the top level references to detekt, which is applied to all the subprojects. Since the detekt plugin isn't referenced in the other subprojects, could you also remove the detekt plugin from

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, done, thanks.

Copy link
Contributor Author

@evanj evanj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make the suggested changes ... but maybe not for a few days; thanks for the prompt review!

Comment on lines +48 to +50
if (originalAst != deserializedAst) {
throw Exception("expected AST to be equal")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason was to avoid requiring the kotlin-test JAR from code that is technically not an automated unit test. I will revert that part of the change since you would prefer to use this dependency.

Comment on lines -60 to -61
// PTS
testImplementation project(':testscript')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not breaking anything, but it seems to be unnecessary as the code builds without it? I haven't read the code in detail, but it appears to me that the dependency tree is that the pts targets/directory imports the code in testscript. I was assuming that means those are the targets that actually use this code. Nothing in the lang directory references testscript AFAIK?

I barely understand this though; I just was curious if all these dependencies were actually needed. I will revert my changes to this file: the important updates are to cli, examples, and pts so ./gradlew test actually executes the tests in those directories.

import com.amazon.ion.system.*
import org.partiql.examples.util.Example
import org.partiql.lang.ast.*
import org.partiql.lang.domains.PartiqlAst
import org.partiql.lang.syntax.*
import java.io.PrintStream
import java.util.Objects
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops thanks sorry; This was a stray import from a previous edit.

@@ -1,6 +1,5 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
id 'io.gitlab.arturbosch.detekt'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand gradle. I assumed since this file has no references to it, this is unnecessary?

The top level build.gradle references detekt, and I assumed the apply plugin thing attempts to apply the plugin to all subprojects? If so, doesn't that mean this is unnecessary, since the top level project includes it?

FWIW, with this change, the ./gradlew cli:detekt task still seems to work?

~/partiql-lang-kotlin $ ./gradlew cli:detekt --info
...
> Task :cli:detekt UP-TO-DATE
...

CliTest.kt: format code on one line
ParserExample.kt: remove unnecessary import
lang,pts,testscript/build.gradle: remove detekt plugin (not needed)
@evanj
Copy link
Contributor Author

evanj commented Jan 5, 2021

sorry for the delay. I believe I addressed all the comments. Thanks again for the prompt review!

Copy link
Member

@alancai98 alancai98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed a deleted line in the first review. Once that's added back, should be approved and merged. Thanks again for the contribution!

testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5'
testImplementation 'pl.pragmatists:JUnitParams:[1.0.0,1.1.0)'
testImplementation 'org.assertj:assertj-core:[3.11.0,3.12.0)'

testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
Copy link
Member

@alancai98 alancai98 Jan 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this dependency to run junit ParameterizedTests with ArgumentsSource that we are starting to use (e.g. EvaluatingCompilerFromLetTests.kt). Without this dependency, these ParameterizedTests aren't being run by gradle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops nice catch thanks! This is probably why I should not make wholesale changes without understanding what I am actually doing :)

@alancai98 alancai98 merged commit 2ca7702 into partiql:master Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants