Skip to content

Commit

Permalink
[annot] Add some basic Kotlin tests
Browse files Browse the repository at this point in the history
Summary: Add some simple tests for annotation reachability checker in Kotlin.

Reviewed By: rgrig

Differential Revision:
D59587456

Privacy Context Container: L1208441

fbshipit-source-id: a8cfa7a4f0a4030cc8738472dbaf0f15a754151a
  • Loading branch information
hajduakos authored and facebook-github-bot committed Jul 10, 2024
1 parent d5be102 commit d84062a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ DIRECT_TESTS += \

ifneq ($(KOTLINC), no)
DIRECT_TESTS += \
kotlin_annotreach \
kotlin_pulse \
kotlin_racerd \
kotlin_resources \
Expand Down
14 changes: 14 additions & 0 deletions infer/tests/codetoanalyze/kotlin/annotreach/.inferconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"force-delete-results-dir": true,
"annotation-reachability-expensive": false,
"annotation-reachability-no-allocation": false,
"annotation-reachability-custom-pairs": [
{
"sources": ["UserDefinedSource"],
"sinks": ["UserDefinedSink"],
"sanitizers": ["UserDefinedSanitizer"]
}
],
"annotation-reachability-apply-superclass-annotations": false,
"annotation-reachability-report-source-and-sink": true
}
51 changes: 51 additions & 0 deletions infer/tests/codetoanalyze/kotlin/annotreach/CustomAnnotations.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package codetoanalyze.kotlin.annotreach

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class UserDefinedSource

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class UserDefinedSink

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class UserDefinedSanitizer

class CustomAnnotations {
@UserDefinedSink fun sink(): Unit {}

fun notSink(): Unit {}

@UserDefinedSource
fun sourceBad(): Unit {
sink()
}

@UserDefinedSource
fun sourceOk(): Unit {
notSink()
}

@UserDefinedSanitizer
fun canCallSink(): Unit {
sink()
}

@UserDefinedSource
fun sourceWithSanitizerOk(): Unit {
canCallSink()
}

fun notSourceOk(): Unit {
sink()
}

@UserDefinedSource @UserDefinedSink fun sourceAndSinkAtTheSameTimeBad(): Unit {}
}
15 changes: 15 additions & 0 deletions infer/tests/codetoanalyze/kotlin/annotreach/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

TESTS_DIR = ../../..

INFER_OPTIONS = --debug-exceptions --annotation-reachability-only
INFERPRINT_OPTIONS = --issues-tests

SOURCES = $(wildcard *.kt)

CLEAN_EXTRA = *.class META-INF

include $(TESTS_DIR)/kotlinc.make
2 changes: 2 additions & 0 deletions infer/tests/codetoanalyze/kotlin/annotreach/issues.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CustomAnnotations.kt, codetoanalyze.kotlin.annotreach.CustomAnnotations.sourceBad():void, 1, CHECKERS_ANNOTATION_REACHABILITY_ERROR, no_bucket, ERROR, []
CustomAnnotations.kt, codetoanalyze.kotlin.annotreach.CustomAnnotations.sourceAndSinkAtTheSameTimeBad():void, 0, CHECKERS_ANNOTATION_REACHABILITY_ERROR, no_bucket, ERROR, []

0 comments on commit d84062a

Please sign in to comment.