Skip to content

Commit

Permalink
Inline addSourceFile/addInput/addOutput in third_party ErrorProne.
Browse files Browse the repository at this point in the history
This is mostly fully automated (unknown commit; I suggest averting your eyes, it's awful code), but with some modifications and reversions to make stuff compile: mostly modifications to BUILD files, and escaping things properly.

There are some stragglers that I'll look at once some dust has settled.

PiperOrigin-RevId: 681909696
  • Loading branch information
graememorgan authored and Error Prone Team committed Oct 4, 2024
1 parent 74ae417 commit bab249c
Show file tree
Hide file tree
Showing 515 changed files with 27,583 additions and 30,574 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,257 @@ public class ArrayEqualsTest {

@Test
public void positiveCase() {
compilationHelper.addSourceFile("testdata/ArrayEqualsPositiveCases.java").doTest();
compilationHelper
.addSourceLines(
"ArrayEqualsPositiveCases.java",
"""
package com.google.errorprone.bugpatterns.testdata;
import com.google.common.base.Objects;
/**
* @author [email protected] (Eddie Aftandilian)
*/
public class ArrayEqualsPositiveCases {
public void intArray() {
int[] a = {1, 2, 3};
int[] b = {1, 2, 3};
// BUG: Diagnostic contains: Arrays.equals(a, b)
if (a.equals(b)) {
System.out.println("arrays are equal!");
} else {
System.out.println("arrays are not equal!");
}
// BUG: Diagnostic contains: Arrays.equals(a, b)
if (Objects.equal(a, b)) {
System.out.println("arrays are equal!");
} else {
System.out.println("arrays are not equal!");
}
}
public void objectArray() {
Object[] a = new Object[3];
Object[] b = new Object[3];
// BUG: Diagnostic contains: Arrays.equals(a, b)
if (a.equals(b)) {
System.out.println("arrays are equal!");
} else {
System.out.println("arrays are not equal!");
}
// BUG: Diagnostic contains: Arrays.equals(a, b)
if (Objects.equal(a, b)) {
System.out.println("arrays are equal!");
} else {
System.out.println("arrays are not equal!");
}
}
public void firstMethodCall() {
String s = "hello";
char[] b = new char[3];
// BUG: Diagnostic contains: Arrays.equals(s.toCharArray(), b)
if (s.toCharArray().equals(b)) {
System.out.println("arrays are equal!");
} else {
System.out.println("arrays are not equal!");
}
}
public void secondMethodCall() {
char[] a = new char[3];
String s = "hello";
// BUG: Diagnostic contains: Arrays.equals(a, s.toCharArray())
if (a.equals(s.toCharArray())) {
System.out.println("arrays are equal!");
} else {
System.out.println("arrays are not equal!");
}
}
public void bothMethodCalls() {
String s1 = "hello";
String s2 = "world";
// BUG: Diagnostic contains: Arrays.equals(s1.toCharArray(), s2.toCharArray())
if (s1.toCharArray().equals(s2.toCharArray())) {
System.out.println("arrays are equal!");
} else {
System.out.println("arrays are not equal!");
}
}
}""")
.doTest();
}

@Test
public void java7PositiveCase() {
compilationHelper.addSourceFile("testdata/ArrayEqualsPositiveCases2.java").doTest();
compilationHelper
.addSourceLines(
"ArrayEqualsPositiveCases2.java",
"""
package com.google.errorprone.bugpatterns.testdata;
import java.util.Objects;
/**
* Tests that only run with Java 7 and above.
*
* @author [email protected] (Eddie Aftandilian)
*/
public class ArrayEqualsPositiveCases2 {
public void intArray() {
int[] a = {1, 2, 3};
int[] b = {1, 2, 3};
// BUG: Diagnostic contains: Arrays.equals(a, b)
if (Objects.equals(a, b)) {
System.out.println("arrays are equal!");
} else {
System.out.println("arrays are not equal!");
}
}
public void objectArray() {
Object[] a = new Object[3];
Object[] b = new Object[3];
// BUG: Diagnostic contains: Arrays.equals(a, b)
if (Objects.equals(a, b)) {
System.out.println("arrays are equal!");
} else {
System.out.println("arrays are not equal!");
}
}
}""")
.doTest();
}

@Test
public void negativeCase() {
compilationHelper.addSourceFile("testdata/ArrayEqualsNegativeCases.java").doTest();
compilationHelper
.addSourceLines(
"ArrayEqualsNegativeCases.java",
"""
package com.google.errorprone.bugpatterns.testdata;
import com.google.common.base.Objects;
/**
* @author [email protected] (Eddie Aftandilian)
*/
public class ArrayEqualsNegativeCases {
public void neitherArray() {
Object a = new Object();
Object b = new Object();
if (a.equals(b)) {
System.out.println("Objects are equal!");
} else {
System.out.println("Objects are not equal!");
}
if (Objects.equal(a, b)) {
System.out.println("Objects are equal!");
} else {
System.out.println("Objects are not equal!");
}
}
public void firstArray() {
Object[] a = new Object[3];
Object b = new Object();
if (a.equals(b)) {
System.out.println("arrays are equal!");
} else {
System.out.println("arrays are not equal!");
}
if (Objects.equal(a, b)) {
System.out.println("Objects are equal!");
} else {
System.out.println("Objects are not equal!");
}
}
public void secondArray() {
Object a = new Object();
Object[] b = new Object[3];
if (a.equals(b)) {
System.out.println("arrays are equal!");
} else {
System.out.println("arrays are not equal!");
}
if (Objects.equal(a, b)) {
System.out.println("Objects are equal!");
} else {
System.out.println("Objects are not equal!");
}
}
}""")
.doTest();
}

@Test
public void java7NegativeCase() {
compilationHelper.addSourceFile("testdata/ArrayEqualsNegativeCases2.java").doTest();
compilationHelper
.addSourceLines(
"ArrayEqualsNegativeCases2.java",
"""
package com.google.errorprone.bugpatterns.testdata;
import java.util.Objects;
/**
* Tests that only run with Java 7 and above.
*
* @author [email protected] (Eddie Aftandilian)
*/
public class ArrayEqualsNegativeCases2 {
public void neitherArray() {
Object a = new Object();
Object b = new Object();
if (Objects.equals(a, b)) {
System.out.println("Objects are equal!");
} else {
System.out.println("Objects are not equal!");
}
}
public void firstArray() {
Object[] a = new Object[3];
Object b = new Object();
if (Objects.equals(a, b)) {
System.out.println("arrays are equal!");
} else {
System.out.println("arrays are not equal!");
}
}
public void secondArray() {
Object a = new Object();
Object[] b = new Object[3];
if (Objects.equals(a, b)) {
System.out.println("arrays are equal!");
} else {
System.out.println("arrays are not equal!");
}
}
}""")
.doTest();
}
}
Loading

0 comments on commit bab249c

Please sign in to comment.