Søren Gjesse | d7aca32 | 2019-02-13 13:10:12 +0100 | [diff] [blame] | 1 | // Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | package com.android.tools.r8.naming.retrace; |
| 6 | |
| 7 | import static org.junit.Assert.assertEquals; |
| 8 | |
Søren Gjesse | d7aca32 | 2019-02-13 13:10:12 +0100 | [diff] [blame] | 9 | import com.android.tools.r8.TestBase; |
Christoffer Quist Adamsen | d94d850 | 2021-09-22 11:18:33 +0200 | [diff] [blame] | 10 | import com.android.tools.r8.TestParameters; |
| 11 | import com.android.tools.r8.TestParametersCollection; |
Søren Gjesse | d7aca32 | 2019-02-13 13:10:12 +0100 | [diff] [blame] | 12 | import com.android.tools.r8.utils.StringUtils; |
| 13 | import org.junit.Test; |
Christoffer Quist Adamsen | d94d850 | 2021-09-22 11:18:33 +0200 | [diff] [blame] | 14 | import org.junit.runner.RunWith; |
| 15 | import org.junit.runners.Parameterized; |
| 16 | import org.junit.runners.Parameterized.Parameter; |
| 17 | import org.junit.runners.Parameterized.Parameters; |
Søren Gjesse | d7aca32 | 2019-02-13 13:10:12 +0100 | [diff] [blame] | 18 | |
Christoffer Quist Adamsen | d94d850 | 2021-09-22 11:18:33 +0200 | [diff] [blame] | 19 | @RunWith(Parameterized.class) |
Søren Gjesse | d7aca32 | 2019-02-13 13:10:12 +0100 | [diff] [blame] | 20 | public class LineDeltaTest extends TestBase { |
Christoffer Quist Adamsen | d94d850 | 2021-09-22 11:18:33 +0200 | [diff] [blame] | 21 | |
| 22 | @Parameter(0) |
| 23 | public TestParameters parameters; |
| 24 | |
| 25 | @Parameters(name = "{0}") |
| 26 | public static TestParametersCollection parameters() { |
| 27 | return getTestParameters().withAllRuntimesAndApiLevels().build(); |
| 28 | } |
| 29 | |
| 30 | @Test |
| 31 | public void test() throws Exception { |
| 32 | String proguardMap = |
| 33 | testForR8(parameters.getBackend()) |
| 34 | .addProgramClasses(LineDeltaTestClass.class) |
| 35 | .addKeepMainRule(LineDeltaTestClass.class) |
| 36 | .addKeepRules("-keepattributes LineNumberTable") |
| 37 | .setMinApi(parameters.getApiLevel()) |
| 38 | .compile() |
| 39 | .inspect( |
| 40 | inspector -> |
| 41 | assertEquals(1, inspector.clazz(LineDeltaTestClass.class).allMethods().size())) |
| 42 | .run(parameters.getRuntime(), LineDeltaTestClass.class) |
| 43 | .assertSuccessWithOutput( |
| 44 | StringUtils.lines( |
| 45 | "In test1() - 1", |
| 46 | "In test1() - 2", |
| 47 | "In test1() - 3", |
| 48 | "In test1() - 4", |
| 49 | "In test2() - 1", |
| 50 | "In test2() - 2", |
| 51 | "In test2() - 3", |
| 52 | "In test2() - 4")) |
| 53 | .proguardMap(); |
| 54 | assertEquals(parameters.isCfRuntime() ? 5 : 17, mapLines(proguardMap)); |
Søren Gjesse | d7aca32 | 2019-02-13 13:10:12 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | private long mapLines(String map) { |
| 58 | return StringUtils.splitLines(map).stream().filter(line -> !line.startsWith("#")).count(); |
| 59 | } |
Søren Gjesse | d7aca32 | 2019-02-13 13:10:12 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | class LineDeltaTestClass { |
Søren Gjesse | d7aca32 | 2019-02-13 13:10:12 +0100 | [diff] [blame] | 63 | static void test1() { |
| 64 | System.out.println("In test1() - 1"); |
| 65 | // One line comment. |
| 66 | System.out.println("In test1() - 2"); |
| 67 | // Two line comments. |
| 68 | // |
| 69 | System.out.println("In test1() - 3"); |
| 70 | // Four line comments. |
| 71 | // |
| 72 | // |
| 73 | // |
| 74 | System.out.println("In test1() - 4"); |
| 75 | } |
| 76 | |
Søren Gjesse | d7aca32 | 2019-02-13 13:10:12 +0100 | [diff] [blame] | 77 | static void test2() { |
| 78 | System.out.println("In test2() - 1"); |
| 79 | // Seven line comments. |
| 80 | // |
| 81 | // |
| 82 | // |
| 83 | // |
| 84 | // |
| 85 | // |
| 86 | System.out.println("In test2() - 2"); |
| 87 | // Eight line comments. |
| 88 | // |
| 89 | // |
| 90 | // |
| 91 | // |
| 92 | // |
| 93 | // |
| 94 | // |
| 95 | System.out.println("In test2() - 3"); |
| 96 | // Nine line comments. |
| 97 | // |
| 98 | // |
| 99 | // |
| 100 | // |
| 101 | // |
| 102 | // |
| 103 | // |
| 104 | // |
| 105 | System.out.println("In test2() - 4"); |
| 106 | } |
| 107 | |
| 108 | public static void main(String[] args) { |
| 109 | test1(); |
| 110 | test2(); |
| 111 | } |
| 112 | } |