Skip to content

Commit

Permalink
Implement property matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
zishkaz committed Aug 7, 2024
1 parent 979e1e5 commit b5d68e5
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 10 deletions.
18 changes: 13 additions & 5 deletions usvm-ts/src/test/kotlin/org/usvm/samples/Arguments.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,39 @@ class Arguments : TSMethodTestRunner() {
className = "SimpleClass",
methodName = "noArguments",
argumentsNumber = 0
)
),
{ r -> r?.number == 42.0 }
)
}

@Test
fun testSingleArg() {
discoverProperties<TSObject.TSNumber>(
discoverProperties<TSObject.TSNumber, TSObject.TSNumber>(
methodIdentifier = MethodDescriptor(
fileName = "Arguments.ts",
className = "SimpleClass",
methodName = "singleArgument",
argumentsNumber = 1
)
),
{ a, r -> a == r }
)
}

@Test
fun testManyArgs() {
discoverProperties<TSObject.TSNumber>(
discoverProperties<TSObject.TSNumber, TSObject.TSNumber, TSObject.TSNumber, TSObject.TSNumber>(
methodIdentifier = MethodDescriptor(
fileName = "Arguments.ts",
className = "SimpleClass",
methodName = "manyArguments",
argumentsNumber = 3
)
),
{ a, _, _, r -> a.number == 1.0 && r == a },
{ _, b, _, r -> b.number == 2.0 && r == b },
{ _, _, c, r -> c.number == 3.0 && r == c },
{ a, b, c, r ->
a.number != 1.0 && b.number != 2.0 && c.number != 3.0 && r?.number == 100.0
},
)
}

Expand Down
20 changes: 15 additions & 5 deletions usvm-ts/src/test/kotlin/org/usvm/samples/StaticMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,41 @@ class StaticMethods : TSMethodTestRunner() {
className = "StaticMethods",
methodName = "noArguments",
argumentsNumber = 0
)
),
{ r -> r?.number == 42.0 }
)
}

@Test
fun testSingleArgStaticMethod() {
discoverProperties<TSObject.TSNumber>(
discoverProperties<TSObject.TSNumber, TSObject.TSNumber>(
methodIdentifier = MethodDescriptor(
fileName = "StaticMethods.ts",
className = "StaticMethods",
methodName = "singleArgument",
argumentsNumber = 1
)
),
{ a, r -> a.number == 1.0 && r?.number == 100.0 },
{ a, r -> a.number != 1.0 && r?.number == 0.0 },
)
}

@Test
fun testManyArgsStaticMethod() {
discoverProperties<TSObject.TSNumber>(
discoverProperties<TSObject.TSNumber, TSObject.TSNumber, TSObject.TSNumber, TSObject.TSNumber, TSObject.TSNumber>(
methodIdentifier = MethodDescriptor(
fileName = "StaticMethods.ts",
className = "StaticMethods",
methodName = "manyArguments",
argumentsNumber = 4
)
),
{ a, _, _, _, r -> a.number == 1.0 && r == a },
{ _, b, _, _, r -> b.number == 2.0 && r == b },
{ _, _, c, _, r -> c.number == 3.0 && r == c },
{ _, _, _, d, r -> d.number == 4.0 && r == d },
{ a, b, c, d, r ->
a.number != 1.0 && b.number != 2.0 && c.number != 3.0 && d.number != 4.0 && r?.number == 100.0
},
)
}
}
51 changes: 51 additions & 0 deletions usvm-ts/src/test/kotlin/org/usvm/util/TSMethodTestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,57 @@ open class TSMethodTestRunner : TestRunner<TSTest, MethodDescriptor, EtsType?, T
)
}

protected inline fun <reified T1 : TSObject, reified T2 : TSObject,

Check warning

Code scanning / detekt

Reports missing newlines (e.g. between parentheses of a multi-line function call Warning test

A newline was expected before 'reified T1 : TSObject'

Check warning

Code scanning / detekt

Reports missing newlines (e.g. between parentheses of a multi-line function call Warning test

A newline was expected before 'reified T2 : TSObject'
reified T3 : TSObject, reified R : TSObject>

Check warning

Code scanning / detekt

Reports mis-indented code Warning test

Unexpected indentation (26) (should be 8)

Check warning

Code scanning / detekt

Reports missing newlines (e.g. between parentheses of a multi-line function call Warning test

A newline was expected before 'reified R : TSObject'

Check warning

Code scanning / detekt

Rule to mandate/forbid trailing commas at declaration sites Warning test

Missing trailing comma before ">"

Check warning

Code scanning / detekt

Reports missing newlines (e.g. between parentheses of a multi-line function call Warning test

A newline was expected before '>'
discoverProperties(
methodIdentifier: MethodDescriptor,
vararg analysisResultMatchers: (T1, T2, T3, R?) -> Boolean,
invariants: Array<out Function<Boolean>> = emptyArray(),
noinline coverageChecker: CoverageChecker = doNotCheckCoverage,
) {
internalCheck(
target = methodIdentifier,
analysisResultsNumberMatcher = ignoreNumberOfAnalysisResults,
analysisResultsMatchers = analysisResultMatchers,
invariants = invariants,
extractValuesToCheck = { r -> r.parameters + r.resultValue },
expectedTypesForExtractedValues = arrayOf(
typeTransformer(T1::class),
typeTransformer(T2::class),
typeTransformer(T3::class),
typeTransformer(R::class)
),
checkMode = CheckMode.MATCH_PROPERTIES,
coverageChecker = coverageChecker
)
}

protected inline fun <reified T1 : TSObject, reified T2 : TSObject,

Check warning

Code scanning / detekt

Reports missing newlines (e.g. between parentheses of a multi-line function call Warning test

A newline was expected before 'reified T1 : TSObject'

Check warning

Code scanning / detekt

Reports missing newlines (e.g. between parentheses of a multi-line function call Warning test

A newline was expected before 'reified T2 : TSObject'
reified T3 : TSObject, reified T4 : TSObject, reified R : TSObject>

Check warning

Code scanning / detekt

Reports mis-indented code Warning test

Unexpected indentation (26) (should be 8)

Check warning

Code scanning / detekt

Reports missing newlines (e.g. between parentheses of a multi-line function call Warning test

A newline was expected before 'reified T4 : TSObject'

Check warning

Code scanning / detekt

Reports missing newlines (e.g. between parentheses of a multi-line function call Warning test

A newline was expected before 'reified R : TSObject'

Check warning

Code scanning / detekt

Rule to mandate/forbid trailing commas at declaration sites Warning test

Missing trailing comma before ">"

Check warning

Code scanning / detekt

Reports missing newlines (e.g. between parentheses of a multi-line function call Warning test

A newline was expected before '>'
discoverProperties(
methodIdentifier: MethodDescriptor,
vararg analysisResultMatchers: (T1, T2, T3, T4, R?) -> Boolean,
invariants: Array<out Function<Boolean>> = emptyArray(),
noinline coverageChecker: CoverageChecker = doNotCheckCoverage,
) {
internalCheck(
target = methodIdentifier,
analysisResultsNumberMatcher = ignoreNumberOfAnalysisResults,
analysisResultsMatchers = analysisResultMatchers,
invariants = invariants,
extractValuesToCheck = { r -> r.parameters + r.resultValue },
expectedTypesForExtractedValues = arrayOf(
typeTransformer(T1::class),
typeTransformer(T2::class),
typeTransformer(T3::class),
typeTransformer(T4::class),
typeTransformer(R::class)
),
checkMode = CheckMode.MATCH_PROPERTIES,
coverageChecker = coverageChecker
)
}

/*
For now type checks are disabled for development purposes
Expand Down

0 comments on commit b5d68e5

Please sign in to comment.