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

#4549 kotlin ijar test cases #4632

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions third_party/ijar/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ sh_test(
# Intentionally bad test JAR: file count in central directory
# wrong.
"libwrongcentraldir.jar",
"kotlin/inline-cases.jar",
"//tools/defaults:jdk",
"//tools/jdk:langtools",
],
Expand Down
40 changes: 39 additions & 1 deletion third_party/ijar/test/ijar_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ SOURCEDEBUGEXT_IJAR=$TEST_TMPDIR/source_debug_extension.jar
CENTRAL_DIR_LARGEST_REGULAR=$IJAR_SRCDIR/test/largest_regular.jar
CENTRAL_DIR_SMALLEST_ZIP64=$IJAR_SRCDIR/test/smallest_zip64.jar
CENTRAL_DIR_ZIP64=$IJAR_SRCDIR/test/definitely_zip64.jar

KOTLIN_INLINE_JAR=$IJAR_SRCDIR/test/kotlin/inline-cases.jar
KOTLIN_INLINE_INTERFACE_JAR=$TEST_TMPDIR/kotlin/inline-cases.jar
KOTLIN_INLINE_OUTPUT_DIR=$TEST_TMPDIR/kotlin/inline
#### Setup

# set_file_length FILE SIZE
Expand Down Expand Up @@ -114,13 +116,49 @@ function check_consistent_file_contents() {

function set_up() {
mkdir -p $TEST_TMPDIR/classes
mkdir -p $TEST_TMPDIR/kotlin
}

function tear_down() {
rm -fr $TEST_TMPDIR/classes
rm -fr $TEST_TMPDIR/kotlin
}

function run_ijar_and_extract_to() {
mkdir -p $3 || fail "could not ensure output dir"
${IJAR} $1 $2 || fail "ijar failed"
pushd $3
${JAR} xf $2 || fail "could not extract jar contents"
Copy link
Member

Choose a reason for hiding this comment

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

Please just indent with 4 spaces here, too.

Copy link
Author

Choose a reason for hiding this comment

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

It's showing up as 4 spaces on my side (not a tab).

popd
}

function javap_decompile_and_assert_contains() {
local output=$(${JAVAP} -c $1)
[[ "${output}" =~ "${2}" ]] || fail "javap output missing expected substring: ${2}"
}

#### Tests
function test_kotlin_metadata_retention() {
run_ijar_and_extract_to $KOTLIN_INLINE_JAR $KOTLIN_INLINE_INTERFACE_JAR $KOTLIN_INLINE_OUTPUT_DIR
[[ -f "${KOTLIN_INLINE_OUTPUT_DIR}/META-INF/inline-cases.kotlin_module" ]] || fail "kotlin metadata not retained"
}

function test_kotlin_inline_retention() {
run_ijar_and_extract_to $KOTLIN_INLINE_JAR $KOTLIN_INLINE_INTERFACE_JAR $KOTLIN_INLINE_OUTPUT_DIR
javap_decompile_and_assert_contains "${KOTLIN_INLINE_OUTPUT_DIR}/ClassWithInline.class" \
" public final void classInlineFun(kotlin.jvm.functions.Function0<kotlin.Unit>);
Code:"
javap_decompile_and_assert_contains "${KOTLIN_INLINE_OUTPUT_DIR}/InlineCasesKt.class" \
" public static final void freeInlineFun(kotlin.jvm.functions.Function0<kotlin.Unit>);
Code:"
javap_decompile_and_assert_contains "${KOTLIN_INLINE_OUTPUT_DIR}/ObjectWithInline.class" \
" public final void objectInlineFun(kotlin.jvm.functions.Function0<kotlin.Unit>);
Code:"
javap_decompile_and_assert_contains "${KOTLIN_INLINE_OUTPUT_DIR}/AbstractClassWithInline.class" \
" public final void inheritedInlineFun(kotlin.jvm.functions.Function0<kotlin.Unit>);
Code:"
}

function test_output_bigger_than_input() {
# Tests that ijar does not crash when output ijar is bigger than the input jar
$JAVAC -g -d $TEST_TMPDIR/classes \
Expand Down
15 changes: 15 additions & 0 deletions third_party/ijar/test/kotlin/InlineCases.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
inline fun freeInlineFun(op: () -> Unit) { op() }

class ClassWithInline {
inline fun classInlineFun(op: () -> Unit) { op() }
}

object ObjectWithInline {
inline fun objectInlineFun(op: () -> Unit) { op() }
}

abstract class AbstractClassWithInline {
inline fun inheritedInlineFun(op: () -> Unit) { op() }
}

object ObjectInheritingInline: AbstractClassWithInline()
Binary file added third_party/ijar/test/kotlin/inline-cases.jar
Binary file not shown.
3 changes: 3 additions & 0 deletions third_party/ijar/test/kotlin/regen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -eu

kotlinc -module-name inline-cases -d inline-cases.jar InlineCases.kt