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

Shared: Inline test expectations #11778

Merged
merged 16 commits into from Jan 9, 2023
Merged

Shared: Inline test expectations #11778

merged 16 commits into from Jan 9, 2023

Conversation

yoff
Copy link
Contributor

@yoff yoff commented Dec 21, 2022

Moves the inline test implementation to a shared module.

yoff added 9 commits Dec 22, 2022
- remove from identical-files
 - remove from identical-files
 - remove from identical-files
- remove from identical-files
 - remove from identical-files
 - add util shared pack to ql
 - remove from identical-files
 - remove from identical-files
 - add util shared pack to swift
 - remove from identical-files
@yoff yoff force-pushed the shared/inline-tests branch from d5ec32d to 08e9d33 Compare Dec 22, 2022
@yoff yoff marked this pull request as ready for review Dec 22, 2022
@yoff yoff requested review from a team as code owners Dec 22, 2022
@erik-krogh
Copy link
Contributor

erik-krogh commented Dec 22, 2022

I had an idea of how to simplify the signature even further: We could make a newtype based implementation of Location inside the Make module, and by doing that just use a hasLocationInfo predicate instead of getLocation().

That way the signature just becomes a single class signature ExpectationCommentSig { .. }, which should be easier for new languages to implement.

I've implemented it as a PR against this PR here: yoff#37

Copy link
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

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

When expanding some of the individual files in the "Files changed" view I still see some QL-for-QL warnings, e.g., on line 16 of the new cpp/ql/test/TestUtilities/InlineExpectationsTest.qll. Those should probably be resolved.

Copy link
Contributor

@atorralba atorralba left a comment

Choose a reason for hiding this comment

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

Java mostly LGTM, with a small suggestion:

GoodExpectation() { getKnownFailure() = "" }
}
private class XmlExpectationComment extends ExpectationComment instanceof J::XmlComment {
override string getContents() { result = this.(J::XmlComment).getText().trim() }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
override string getContents() { result = this.(J::XmlComment).getText().trim() }
override string getContents() { result = super.getText().trim() }

class FalsePositiveExpectation extends ValidExpectation {
FalsePositiveExpectation() { getKnownFailure() = "SPURIOUS" }
}
override Location getLocation() { result = this.(J::XmlComment).getLocation() }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
override Location getLocation() { result = this.(J::XmlComment).getLocation() }
override Location getLocation() { result = J::XmlComment.super.getLocation() }

FalseNegativeExpectation() { getKnownFailure() = "MISSING" }
}
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
this.(J::XmlComment).hasLocationInfo(path, sl, sc, el, ec)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.(J::XmlComment).hasLocationInfo(path, sl, sc, el, ec)
J::XmlComment.super.hasLocationInfo(path, sl, sc, el, ec)

string expectation;

InvalidExpectation() { this = TInvalidExpectation(comment, expectation) }
override string toString() { result = this.(J::XmlComment).toString() }
Copy link
Contributor

@atorralba atorralba Dec 22, 2022

Choose a reason for hiding this comment

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

Suggested change
override string toString() { result = this.(J::XmlComment).toString() }
override string toString() { result = J::XmlComment.super.toString() }

aibaars
aibaars previously approved these changes Dec 23, 2022
Copy link
Contributor

@aibaars aibaars left a comment

Choose a reason for hiding this comment

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

👍 For Ruby

@yoff
Copy link
Contributor Author

yoff commented Dec 23, 2022

@erik-krogh nice, I agree we might prefer that..

inline Location into the shared implementation of InlineExpectationsTest
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

👍 for CPP and Swift, if the warnings pointed out by @jketema are addressed.

"ql/ql/test/TestUtilities/InlineExpectationsTest.qll",
"go/ql/test/TestUtilities/InlineExpectationsTest.qll",
"swift/ql/test/TestUtilities/InlineExpectationsTest.qll"
],
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

Copy link
Contributor

Choose a reason for hiding this comment

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

Friday win for sure.

@yoff
Copy link
Contributor Author

yoff commented Jan 5, 2023

Unfortunately we do have to assume a Location class, otherwise users cannot implement hasActualResult. (And I think that changing the signature of that predicate to not use Location would be cumbersome.)

erik-krogh
erik-krogh previously approved these changes Jan 5, 2023
Copy link
Contributor

@erik-krogh erik-krogh left a comment

Choose a reason for hiding this comment

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

👍

owen-mc
owen-mc previously approved these changes Jan 5, 2023
go/ql/test/TestUtilities/InlineExpectationsTest.qll Outdated Show resolved Hide resolved
Co-authored-by: Owen Mansel-Chan <62447351+owen-mc@users.noreply.github.com>
@yoff yoff dismissed stale reviews from owen-mc and erik-krogh via a74062c Jan 5, 2023
@yoff yoff requested review from atorralba and jketema Jan 5, 2023
jketema
jketema previously approved these changes Jan 5, 2023
jketema
jketema approved these changes Jan 6, 2023
owen-mc
owen-mc approved these changes Jan 6, 2023
Copy link
Contributor

@atorralba atorralba left a comment

Choose a reason for hiding this comment

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

Java 👍

Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

C# LGTM!
Very nice application of param modules!!!

@calumgrant calumgrant requested a review from tausbn Jan 9, 2023
tausbn
tausbn approved these changes Jan 9, 2023
Copy link
Contributor

@tausbn tausbn left a comment

Choose a reason for hiding this comment

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

Python 👍

@yoff yoff merged commit c01ce95 into github:main Jan 9, 2023
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants