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

Fix part of #4044: Add math tokenizer & parameterized test support #4051

Merged
merged 122 commits into from
Mar 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
17472e7
Copy proto-based changes from #2173.
BenHenning Dec 14, 2021
fe73a2f
Introduce math.proto & refactor math extensions.
BenHenning Dec 15, 2021
d17e3dc
Migrate tests & remove unneeded prefix.
BenHenning Dec 15, 2021
fb61e39
Add needed newline.
BenHenning Dec 15, 2021
acab98b
Some needed Fraction changes.
BenHenning Dec 15, 2021
02e930f
Introduce math expression + equation protos.
BenHenning Dec 15, 2021
e45635d
Add protos + testing lib for commutative exprs.
BenHenning Dec 15, 2021
da5d72d
Add protos & test libs for polynomials.
BenHenning Dec 15, 2021
7c36fdf
Lint fix.
BenHenning Dec 15, 2021
ed290a0
Merge branch 'add-support-for-math-expressions-pt2-math-utility-refac…
BenHenning Dec 15, 2021
70e8039
Merge branch 'add-support-for-math-expressions-pt3-math-expression-pr…
BenHenning Dec 15, 2021
b957284
Merge branch 'add-support-for-math-expressions-pt4-commutative-compar…
BenHenning Dec 15, 2021
d430f8c
Lint fixes.
BenHenning Dec 15, 2021
0099d67
Add math tokenizer + utility & tests.
BenHenning Dec 15, 2021
d5dd596
Fix broken test post-refactor.
BenHenning Dec 16, 2021
ff813ad
Merge branch 'add-support-for-math-expressions-pt2-math-utility-refac…
BenHenning Dec 16, 2021
a77499c
Merge branch 'add-support-for-math-expressions-pt3-math-expression-pr…
BenHenning Dec 16, 2021
31022f0
Merge branch 'add-support-for-math-expressions-pt4-commutative-compar…
BenHenning Dec 16, 2021
028e821
Merge branch 'add-support-for-math-expressions-pt5-polynomial-protos'…
BenHenning Dec 16, 2021
a1d481d
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Jan 13, 2022
7740c81
Post-merge fix.
BenHenning Jan 13, 2022
929de4f
Add regex check, docs, and resolve TODOs.
BenHenning Jan 14, 2022
e50a50f
Lint fix.
BenHenning Jan 14, 2022
c2726ac
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Jan 14, 2022
ec575b7
Fix failing static checks.
BenHenning Jan 14, 2022
5fe790a
Merge branch 'add-support-for-math-expressions-pt2-math-utility-refac…
BenHenning Jan 14, 2022
1268fc5
Fix broken CI checks.
BenHenning Jan 14, 2022
977eb9e
Lint fixes.
BenHenning Jan 14, 2022
a7ab1a5
Merge branch 'add-support-for-math-expressions-pt3-math-expression-pr…
BenHenning Jan 14, 2022
eed21d5
Add docs & exempted tests.
BenHenning Jan 14, 2022
b1102a3
Merge branch 'add-support-for-math-expressions-pt4-commutative-compar…
BenHenning Jan 14, 2022
080e7dd
Remove blank line.
BenHenning Jan 14, 2022
904aad8
Add docs + tests.
BenHenning Jan 19, 2022
61fbfe5
Merge branch 'add-support-for-math-expressions-pt5-polynomial-protos'…
BenHenning Jan 19, 2022
fca0cd9
Add parameterized test runner.
BenHenning Jan 21, 2022
83e800c
Add & update tests.
BenHenning Jan 21, 2022
3fa8dad
Lint fixes.
BenHenning Jan 21, 2022
87a41db
Remove internals that broke things.
BenHenning Jan 21, 2022
c0172ce
Add regex exemptions.
BenHenning Jan 21, 2022
444d3d0
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Jan 26, 2022
cb5c5d1
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Jan 27, 2022
7a364c3
Address reviewer comments + other stuff.
BenHenning Jan 27, 2022
2c0b9cd
Merge branch 'add-support-for-math-expressions-pt2-math-utility-refac…
BenHenning Jan 27, 2022
4364d7f
Merge branch 'add-support-for-math-expressions-pt3-math-expression-pr…
BenHenning Jan 27, 2022
cfe6cab
Move StringExtensions & fraction parsing.
BenHenning Jan 27, 2022
5e83a33
Merge branch 'add-support-for-math-expressions-pt2-math-utility-refac…
BenHenning Jan 27, 2022
c6cf5f5
Merge branch 'add-support-for-math-expressions-pt3-math-expression-pr…
BenHenning Jan 27, 2022
73dccd8
Address reviewer comments.
BenHenning Jan 27, 2022
b7535fa
Alphabetize test exemptions.
BenHenning Jan 27, 2022
f4cd6cd
Merge branch 'add-support-for-math-expressions-pt4-commutative-compar…
BenHenning Jan 27, 2022
574ebb8
Merge branch 'add-support-for-math-expressions-pt5-polynomial-protos'…
BenHenning Jan 27, 2022
a00164c
Fix typo & add regex check.
BenHenning Jan 27, 2022
0287f19
Add missing KDocs.
BenHenning Jan 27, 2022
75103d5
Merge branch 'add-support-for-math-expressions-pt2-math-utility-refac…
BenHenning Jan 27, 2022
52d2605
Merge branch 'add-support-for-math-expressions-pt3-math-expression-pr…
BenHenning Jan 27, 2022
37dbc85
Merge branch 'add-support-for-math-expressions-pt4-commutative-compar…
BenHenning Jan 27, 2022
385d2d3
Merge branch 'add-support-for-math-expressions-pt5-polynomial-protos'…
BenHenning Jan 27, 2022
65a9fe1
Remove the ComparableOperationList wrapper.
BenHenning Jan 28, 2022
fa4de34
Merge branch 'add-support-for-math-expressions-pt4-commutative-compar…
BenHenning Jan 28, 2022
e2d226f
Merge branch 'add-support-for-math-expressions-pt5-polynomial-protos'…
BenHenning Jan 28, 2022
fbd935c
Change parameterized method delimiter.
BenHenning Jan 28, 2022
d20256c
Use more intentional epsilons for float comparing.
BenHenning Feb 4, 2022
cdaf778
Merge branch 'add-support-for-math-expressions-pt5-polynomial-protos'…
BenHenning Feb 4, 2022
7e97d0b
Treat en-dash as a subtraction symbol.
BenHenning Feb 4, 2022
a9c68b1
Add explicit platform selection for paramerized.
BenHenning Feb 5, 2022
a273ee6
Exemption fixes.
BenHenning Feb 5, 2022
924214d
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Feb 5, 2022
686c4b6
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Feb 5, 2022
1a3cba5
Merge branch 'add-support-for-math-expressions-pt2-math-utility-refac…
BenHenning Feb 5, 2022
bff824e
Merge branch 'add-support-for-math-expressions-pt3-math-expression-pr…
BenHenning Feb 5, 2022
90b05bf
Merge branch 'add-support-for-math-expressions-pt4-commutative-compar…
BenHenning Feb 5, 2022
09e2aad
Remove failing test.
BenHenning Feb 5, 2022
c7c2e4b
Merge branch 'add-support-for-math-expressions-pt5-polynomial-protos'…
BenHenning Feb 5, 2022
ecc836e
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Feb 18, 2022
b183d67
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Feb 18, 2022
005d9a0
Merge branch 'add-support-for-math-expressions-pt2-math-utility-refac…
BenHenning Feb 18, 2022
ba198fd
Merge branch 'add-support-for-math-expressions-pt3-math-expression-pr…
BenHenning Feb 18, 2022
1f2b90d
Merge branch 'add-support-for-math-expressions-pt4-commutative-compar…
BenHenning Feb 18, 2022
86e90f7
Merge branch 'add-support-for-math-expressions-pt5-polynomial-protos'…
BenHenning Feb 18, 2022
a6dc7d4
Address reviewer comment.
BenHenning Feb 18, 2022
fd9ec1f
Fix broken build.
BenHenning Feb 18, 2022
960287d
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Feb 18, 2022
b85567e
Merge branch 'add-support-for-math-expressions-pt2-math-utility-refac…
BenHenning Feb 18, 2022
2ed67c5
Merge branch 'add-support-for-math-expressions-pt3-math-expression-pr…
BenHenning Feb 18, 2022
3744cf2
Merge branch 'add-support-for-math-expressions-pt4-commutative-compar…
BenHenning Feb 18, 2022
c57e792
Merge branch 'add-support-for-math-expressions-pt5-polynomial-protos'…
BenHenning Feb 18, 2022
0fc8a1b
Fix broken build post-merge.
BenHenning Feb 18, 2022
e4b92e5
Merge branch 'add-support-for-math-expressions-pt2-math-utility-refac…
BenHenning Feb 18, 2022
9eb1c2d
Merge branch 'add-support-for-math-expressions-pt3-math-expression-pr…
BenHenning Feb 18, 2022
1f3fb48
Merge branch 'add-support-for-math-expressions-pt4-commutative-compar…
BenHenning Feb 18, 2022
24ac61c
Merge branch 'add-support-for-math-expressions-pt5-polynomial-protos'…
BenHenning Feb 18, 2022
c01f939
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Feb 24, 2022
14f7057
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Feb 24, 2022
b98e1ec
Merge branch 'add-support-for-math-expressions-pt2-math-utility-refac…
BenHenning Feb 24, 2022
b50c40f
Merge branch 'add-support-for-math-expressions-pt3-math-expression-pr…
BenHenning Feb 24, 2022
6d0cc9e
Merge branch 'add-support-for-math-expressions-pt4-commutative-compar…
BenHenning Feb 24, 2022
2217f7d
Merge branch 'add-support-for-math-expressions-pt5-polynomial-protos'…
BenHenning Feb 24, 2022
1d74aed
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Mar 7, 2022
2ae10ec
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Mar 7, 2022
60670a5
Merge branch 'add-support-for-math-expressions-pt2-math-utility-refac…
BenHenning Mar 7, 2022
473b562
Merge branch 'add-support-for-math-expressions-pt3-math-expression-pr…
BenHenning Mar 7, 2022
73a052f
Merge branch 'add-support-for-math-expressions-pt4-commutative-compar…
BenHenning Mar 7, 2022
e35b13f
Merge branch 'add-support-for-math-expressions-pt5-polynomial-protos'…
BenHenning Mar 7, 2022
8945c3a
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Mar 17, 2022
391cf22
Post-merge fix.
BenHenning Mar 17, 2022
7918001
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Mar 17, 2022
c29a47c
More post-merge fixes.
BenHenning Mar 17, 2022
19b3800
Merge branch 'add-support-for-math-expressions-pt2-math-utility-refac…
BenHenning Mar 17, 2022
aa4fd38
Merge branch 'add-support-for-math-expressions-pt3-math-expression-pr…
BenHenning Mar 17, 2022
eb2bcc3
Merge branch 'add-support-for-math-expressions-pt4-commutative-compar…
BenHenning Mar 17, 2022
8bd314f
Merge branch 'add-support-for-math-expressions-pt5-polynomial-protos'…
BenHenning Mar 17, 2022
52862d6
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Mar 25, 2022
cd31247
Merge branch 'develop' into add-support-for-math-expressions-pt1-fix-…
BenHenning Mar 25, 2022
4dbd838
Merge branch 'add-support-for-math-expressions-pt1-fix-proto-imports'…
BenHenning Mar 25, 2022
deabf3a
Merge branch 'develop' into add-support-for-math-expressions-pt2-math…
BenHenning Mar 26, 2022
8bd89e6
Merge branch 'add-support-for-math-expressions-pt2-math-utility-refac…
BenHenning Mar 26, 2022
06f9cfd
Merge branch 'develop' into add-support-for-math-expressions-pt3-math…
BenHenning Mar 26, 2022
a1284a1
Merge branch 'add-support-for-math-expressions-pt3-math-expression-pr…
BenHenning Mar 26, 2022
2c2328b
Merge branch 'develop' into add-support-for-math-expressions-pt4-comm…
BenHenning Mar 26, 2022
feb901b
Merge branch 'add-support-for-math-expressions-pt4-commutative-compar…
BenHenning Mar 26, 2022
783aaf0
Merge branch 'develop' into add-support-for-math-expressions-pt5-poly…
BenHenning Mar 26, 2022
7306faa
Merge branch 'add-support-for-math-expressions-pt5-polynomial-protos'…
BenHenning Mar 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions scripts/assets/file_content_validation_checks.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ file_content_checks {
exempted_file_name: "domain/src/main/java/org/oppia/android/domain/util/WorkDataExtensions.kt"
exempted_file_name: "domain/src/test/java/org/oppia/android/domain/onboarding/AppStartupStateControllerTest.kt"
exempted_file_name: "testing/src/main/java/org/oppia/android/testing/OppiaTestRunner.kt"
exempted_file_name: "testing/src/main/java/org/oppia/android/testing/junit/ParameterizedMethod.kt"
exempted_file_name: "testing/src/main/java/org/oppia/android/testing/time/FakeOppiaClock.kt"
exempted_file_name: "utility/src/main/java/org/oppia/android/util/extensions/BundleExtensions.kt"
exempted_file_name: "utility/src/main/java/org/oppia/android/util/locale/MachineLocaleImpl.kt"
Expand Down Expand Up @@ -260,6 +261,7 @@ file_content_checks {
exempted_file_name: "app/src/sharedTest/java/org/oppia/android/app/splash/SplashActivityTest.kt"
exempted_file_name: "app/src/test/java/org/oppia/android/app/player/state/StateFragmentLocalTest.kt"
exempted_file_name: "testing/src/main/java/org/oppia/android/testing/junit/InitializeDefaultLocaleRule.kt"
exempted_file_name: "testing/src/main/java/org/oppia/android/testing/junit/ParameterizedMethod.kt"
exempted_file_name: "testing/src/main/java/org/oppia/android/testing/robolectric/ShadowBidiFormatter.kt"
exempted_file_name: "testing/src/test/java/org/oppia/android/testing/robolectric/ShadowBidiFormatterTest.kt"
exempted_file_name: "utility/src/main/java/org/oppia/android/util/logging/firebase/FirebaseEventLogger.kt"
Expand All @@ -280,3 +282,11 @@ file_content_checks {
prohibited_content_regex: "^proto_library\\("
failure_message: "Don't use proto_library. Use oppia_proto_library instead."
}
file_content_checks {
file_path_regex: ".+?\\.kt"
prohibited_content_regex: "OppiaParameterizedTestRunner"
failure_message: "To use OppiaParameterizedTestRunner, please add an exemption to file_content_validation_checks.textproto and add an explanation for your use case in your PR description. Note that parameterized tests should only be used in special circumstances where a single behavior can be tested across multiple inputs, or for especially large test suites that can be trivially reduced."
exempted_file_name: "scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt"
exempted_file_name: "utility/src/test/java/org/oppia/android/util/math/MathTokenizerTest.kt"
exempted_file_patterns: "testing/src/main/java/org/oppia/android/testing/junit/.+?\\.kt"
}
10 changes: 10 additions & 0 deletions scripts/assets/test_file_exemptions.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -648,12 +648,22 @@ exempted_file_path: "testing/src/main/java/org/oppia/android/testing/espresso/Ge
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/espresso/ImageViewMatcher.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/espresso/KonfettiViewMatcher.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/junit/DefineAppLanguageLocaleContext.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/junit/OppiaParameterizedBaseRunner.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/junit/OppiaParameterizedTestRunner.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/junit/ParameterizedAndroidJunit4TestRunner.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/junit/ParameterizedJunitTestRunner.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/junit/ParameterizedMethod.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/junit/ParameterizedRobolectricTestRunner.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/junit/ParameterizedRunnerDelegate.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/junit/ParameterizedRunnerOverrideMethods.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/junit/ParameterValue.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/ComparableOperationSubject.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/FractionSubject.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/MathExpressionSubject.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/MathEquationSubject.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/PolynomialSubject.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/RealSubject.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/TokenSubject.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/mockito/MockitoKotlinHelper.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/network/ApiMockLoader.kt"
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/network/MockClassroomService.kt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ class RegexPatternValidationCheckTest {
" null, instead. Delegates uses reflection internally, have a non-trivial initialization" +
" cost, and can cause breakages on KitKat devices. See #3939 for more context."
private val doNotUseProtoLibrary = "Don't use proto_library. Use oppia_proto_library instead."
private val parameterizedTestRunnerRequiresException =
"To use OppiaParameterizedTestRunner, please add an exemption to" +
" file_content_validation_checks.textproto and add an explanation for your use case in your" +
" PR description. Note that parameterized tests should only be used in special" +
" circumstances where a single behavior can be tested across multiple inputs, or for" +
" especially large test suites that can be trivially reduced."
private val wikiReferenceNote =
"Refer to https://github.com/oppia/oppia-android/wiki/Static-Analysis-Checks" +
"#regexpatternvalidation-check for more details on how to fix this."
Expand Down Expand Up @@ -1569,6 +1575,32 @@ class RegexPatternValidationCheckTest {
)
}

@Test
fun testFileContent_kotlinTestUsesParameterizedTestRunner_fileContentIsNotCorrect() {
val prohibitedContent =
"""
import org.oppia.android.testing.junit.OppiaParameterizedTestRunner
@RunWith(OppiaParameterizedTestRunner::class)
""".trimIndent()
tempFolder.newFolder("testfiles", "domain", "src", "test")
val stringFilePath = "domain/src/test/SomeTest.kt"
tempFolder.newFile("testfiles/$stringFilePath").writeText(prohibitedContent)

val exception = assertThrows(Exception::class) {
runScript()
}

assertThat(exception).hasMessageThat().contains(REGEX_CHECK_FAILED_OUTPUT_INDICATOR)
assertThat(outContent.toString().trim())
.isEqualTo(
"""
$stringFilePath:1: $parameterizedTestRunnerRequiresException
$stringFilePath:2: $parameterizedTestRunnerRequiresException
$wikiReferenceNote
""".trimIndent()
)
}

@Test
fun testFileContent_java8OptionalImport_fileContentIsNotCorrect() {
val prohibitedContent = "import java.util.Optional"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,75 @@ kt_android_library(
"//third_party:junit_junit",
],
)

kt_android_library(
name = "oppia_parameterized_test_runner",
testonly = True,
srcs = [
"OppiaParameterizedTestRunner.kt",
],
visibility = ["//:oppia_testing_visibility"],
deps = [
":parameterized_runner_delegate_impl",
"//third_party:androidx_test_runner",
"//third_party:junit_junit",
"//third_party:org_robolectric_robolectric",
"//third_party:robolectric_android-all",
],
)

kt_android_library(
name = "parameterized_android_junit4_class_runner",
testonly = True,
srcs = [
"ParameterizedAndroidJunit4TestRunner.kt",
],
visibility = ["//:oppia_testing_visibility"],
deps = [
":parameterized_runner_delegate_impl",
"//third_party:androidx_test_runner",
"//third_party:junit_junit",
],
)

kt_android_library(
name = "parameterized_junit_test_runner",
testonly = True,
srcs = [
"ParameterizedJunitTestRunner.kt",
],
visibility = ["//:oppia_testing_visibility"],
deps = [
":parameterized_runner_delegate_impl",
"//third_party:junit_junit",
],
)

kt_android_library(
name = "parameterized_robolectric_test_runner",
testonly = True,
srcs = [
"ParameterizedRobolectricTestRunner.kt",
],
visibility = ["//:oppia_testing_visibility"],
deps = [
":parameterized_runner_delegate_impl",
"//third_party:junit_junit",
"//third_party:org_robolectric_robolectric",
],
)

kt_android_library(
name = "parameterized_runner_delegate_impl",
testonly = True,
srcs = [
"OppiaParameterizedBaseRunner.kt",
"ParameterValue.kt",
"ParameterizedMethod.kt",
"ParameterizedRunnerDelegate.kt",
"ParameterizedRunnerOverrideMethods.kt",
],
deps = [
"//third_party:junit_junit",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.oppia.android.testing.junit

/**
* This is a marker interface that's used to select a base runner to be used in conjunction with
* [OppiaParameterizedTestRunner].
*
* See the KDoc for the test runner for more details on how to use this.
*/
interface OppiaParameterizedBaseRunner
Loading