blob: d91a506f27af19e9714b634bdf4aafd94b36c1bb [file] [log] [blame]
Søren Gjessed7aca322019-02-13 13:10:12 +01001// 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
5package com.android.tools.r8.naming.retrace;
6
7import static org.junit.Assert.assertEquals;
8
Søren Gjessed7aca322019-02-13 13:10:12 +01009import com.android.tools.r8.TestBase;
Christoffer Quist Adamsend94d8502021-09-22 11:18:33 +020010import com.android.tools.r8.TestParameters;
11import com.android.tools.r8.TestParametersCollection;
Søren Gjessed7aca322019-02-13 13:10:12 +010012import com.android.tools.r8.utils.StringUtils;
13import org.junit.Test;
Christoffer Quist Adamsend94d8502021-09-22 11:18:33 +020014import org.junit.runner.RunWith;
15import org.junit.runners.Parameterized;
16import org.junit.runners.Parameterized.Parameter;
17import org.junit.runners.Parameterized.Parameters;
Søren Gjessed7aca322019-02-13 13:10:12 +010018
Christoffer Quist Adamsend94d8502021-09-22 11:18:33 +020019@RunWith(Parameterized.class)
Søren Gjessed7aca322019-02-13 13:10:12 +010020public class LineDeltaTest extends TestBase {
Christoffer Quist Adamsend94d8502021-09-22 11:18:33 +020021
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 Gjessed7aca322019-02-13 13:10:12 +010055 }
56
57 private long mapLines(String map) {
58 return StringUtils.splitLines(map).stream().filter(line -> !line.startsWith("#")).count();
59 }
Søren Gjessed7aca322019-02-13 13:10:12 +010060}
61
62class LineDeltaTestClass {
Søren Gjessed7aca322019-02-13 13:10:12 +010063 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 Gjessed7aca322019-02-13 13:10:12 +010077 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}