Skip to content

Commit

Permalink
Use text blocks for internal Error Prone test outputs
Browse files Browse the repository at this point in the history
The min JDK version for OSS is being updated to 17 as part of: #3803

PiperOrigin-RevId: 673443508
  • Loading branch information
cushon authored and Error Prone Team committed Sep 12, 2024
1 parent 1e6d3a5 commit 0c5b38b
Show file tree
Hide file tree
Showing 481 changed files with 63,264 additions and 44,819 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,33 @@ public void positive() {
testHelper
.addInputLines(
"Test.java",
"import com.sun.tools.javac.code.Symbol;",
"class Test {",
" void f(Symbol s) {",
" s.isStatic();",
" s.packge();",
" s.members().anyMatch(x -> x.isStatic());",
" }",
"}")
"""
import com.sun.tools.javac.code.Symbol;
class Test {
void f(Symbol s) {
s.isStatic();
s.packge();
s.members().anyMatch(x -> x.isStatic());
}
}
""")
.addOutputLines(
"Test.java",
"import static com.google.errorprone.util.ASTHelpers.enclosingPackage;",
"import static com.google.errorprone.util.ASTHelpers.isStatic;",
"import static com.google.errorprone.util.ASTHelpers.scope;",
"import com.sun.tools.javac.code.Symbol;",
"class Test {",
" void f(Symbol s) {",
" isStatic(s);",
" enclosingPackage(s);",
" scope(s.members()).anyMatch(x -> isStatic(x));",
" }",
"}")
"""
import static com.google.errorprone.util.ASTHelpers.enclosingPackage;
import static com.google.errorprone.util.ASTHelpers.isStatic;
import static com.google.errorprone.util.ASTHelpers.scope;
import com.sun.tools.javac.code.Symbol;
class Test {
void f(Symbol s) {
isStatic(s);
enclosingPackage(s);
scope(s.members()).anyMatch(x -> isStatic(x));
}
}
""")
.addModules(
"jdk.compiler/com.sun.tools.javac.code", "jdk.compiler/com.sun.tools.javac.util")
.doTest();
Expand All @@ -62,27 +68,33 @@ public void onSymbolSubtype() {
testHelper
.addInputLines(
"Test.java",
"import com.sun.tools.javac.code.Symbol.VarSymbol;",
"class Test {",
" void f(VarSymbol s) {",
" s.isStatic();",
" s.packge();",
" s.members().anyMatch(x -> x.isStatic());",
" }",
"}")
"""
import com.sun.tools.javac.code.Symbol.VarSymbol;
class Test {
void f(VarSymbol s) {
s.isStatic();
s.packge();
s.members().anyMatch(x -> x.isStatic());
}
}
""")
.addOutputLines(
"Test.java",
"import static com.google.errorprone.util.ASTHelpers.enclosingPackage;",
"import static com.google.errorprone.util.ASTHelpers.isStatic;",
"import static com.google.errorprone.util.ASTHelpers.scope;",
"import com.sun.tools.javac.code.Symbol.VarSymbol;",
"class Test {",
" void f(VarSymbol s) {",
" s.isStatic();",
" enclosingPackage(s);",
" scope(s.members()).anyMatch(x -> isStatic(x));",
" }",
"}")
"""
import static com.google.errorprone.util.ASTHelpers.enclosingPackage;
import static com.google.errorprone.util.ASTHelpers.isStatic;
import static com.google.errorprone.util.ASTHelpers.scope;
import com.sun.tools.javac.code.Symbol.VarSymbol;
class Test {
void f(VarSymbol s) {
s.isStatic();
enclosingPackage(s);
scope(s.members()).anyMatch(x -> isStatic(x));
}
}
""")
.addModules(
"jdk.compiler/com.sun.tools.javac.code", "jdk.compiler/com.sun.tools.javac.util")
.doTest();
Expand All @@ -93,21 +105,27 @@ public void symbolGetEnclosedElements() {
testHelper
.addInputLines(
"Test.java",
"import com.sun.tools.javac.code.Symbol.ClassSymbol;",
"class Test {",
" void f(ClassSymbol s) {",
" s.getEnclosedElements();",
" }",
"}")
"""
import com.sun.tools.javac.code.Symbol.ClassSymbol;
class Test {
void f(ClassSymbol s) {
s.getEnclosedElements();
}
}
""")
.addOutputLines(
"Test.java",
"import static com.google.errorprone.util.ASTHelpers.getEnclosedElements;",
"import com.sun.tools.javac.code.Symbol.ClassSymbol;",
"class Test {",
" void f(ClassSymbol s) {",
" getEnclosedElements(s);",
" }",
"}")
"""
import static com.google.errorprone.util.ASTHelpers.getEnclosedElements;
import com.sun.tools.javac.code.Symbol.ClassSymbol;
class Test {
void f(ClassSymbol s) {
getEnclosedElements(s);
}
}
""")
.addModules(
"jdk.compiler/com.sun.tools.javac.code", "jdk.compiler/com.sun.tools.javac.util")
.doTest();
Expand All @@ -118,13 +136,17 @@ public void selfMatch() {
testHelper
.addInputLines(
"ASTHelpers.java",
"package com.google.errorprone.util;",
"import com.sun.tools.javac.code.Symbol;",
"public final class ASTHelpers {",
" public static boolean isStatic(Symbol symbol) {",
" return symbol.isStatic();",
" }",
"}")
"""
package com.google.errorprone.util;
import com.sun.tools.javac.code.Symbol;
public final class ASTHelpers {
public static boolean isStatic(Symbol symbol) {
return symbol.isStatic();
}
}
""")
.expectUnchanged()
.addModules(
"jdk.compiler/com.sun.tools.javac.code", "jdk.compiler/com.sun.tools.javac.util")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,22 @@ public void positive() {
compilationHelper
.addSourceLines(
"Test.java",
"import java.net.InetAddress;",
"import java.net.InetSocketAddress;",
"import java.net.Socket;",
"class Test {",
" void f() throws Exception{",
" // BUG: Diagnostic contains:",
" InetAddress.getByName(\"example.com\");",
" // BUG: Diagnostic contains:",
" new Socket(\"example.com\", 80);",
" // BUG: Diagnostic contains:",
" new InetSocketAddress(\"example.com\", 80);",
" }",
"}")
"""
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
class Test {
void f() throws Exception {
// BUG: Diagnostic contains:
InetAddress.getByName("example.com");
// BUG: Diagnostic contains:
new Socket("example.com", 80);
// BUG: Diagnostic contains:
new InetSocketAddress("example.com", 80);
}
}
""")
.doTest();
}

Expand All @@ -57,16 +60,19 @@ public void negative() throws Exception {
compilationHelper
.addSourceLines(
"Test.java",
"import java.net.InetAddress;",
"import java.net.InetSocketAddress;",
"import java.net.Socket;",
"class Test {",
" void f() throws Exception{",
" new Socket(InetAddress.getLoopbackAddress(), 80);",
" InetAddress.getAllByName(\"example.com\");",
" new InetSocketAddress(InetAddress.getLoopbackAddress(), 80);",
" }",
"}")
"""
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
class Test {
void f() throws Exception {
new Socket(InetAddress.getLoopbackAddress(), 80);
InetAddress.getAllByName("example.com");
new InetSocketAddress(InetAddress.getLoopbackAddress(), 80);
}
}
""")
.doTest();
}

Expand All @@ -75,16 +81,19 @@ public void negativeLocalhost() throws Exception {
compilationHelper
.addSourceLines(
"Test.java",
"import java.net.InetAddress;",
"import java.net.InetSocketAddress;",
"import java.net.Socket;",
"class Test {",
" void f() throws Exception{",
" new Socket(\"localhost\", 80);",
" InetAddress.getByName(\"localhost\");",
" new InetSocketAddress(\"localhost\", 80);",
" }",
"}")
"""
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
class Test {
void f() throws Exception {
new Socket("localhost", 80);
InetAddress.getByName("localhost");
new InetSocketAddress("localhost", 80);
}
}
""")
.doTest();
}

Expand All @@ -93,16 +102,19 @@ public void negativeNumeric() throws Exception {
compilationHelper
.addSourceLines(
"Test.java",
"import java.net.InetAddress;",
"import java.net.InetSocketAddress;",
"import java.net.Socket;",
"class Test {",
" void f() throws Exception {",
" new Socket(\"1.2.3.4\", 80);",
" InetAddress.getByName(\"2001:db8:85a3:8d3:1319:8a2e:370:7348\");",
" new InetSocketAddress(\"::ffff:192.0.2.128\", 80);",
" }",
"}")
"""
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
class Test {
void f() throws Exception {
new Socket("1.2.3.4", 80);
InetAddress.getByName("2001:db8:85a3:8d3:1319:8a2e:370:7348");
new InetSocketAddress("::ffff:192.0.2.128", 80);
}
}
""")
.doTest();
}

Expand All @@ -111,34 +123,40 @@ public void refactor() throws Exception {
refactoringTestHelper
.addInputLines(
"Test.java",
"import java.net.InetAddress;",
"import java.net.InetSocketAddress;",
"import java.net.Socket;",
"class Test {",
" void f() throws Exception{",
" new Socket(\"127.0.0.1\", 80);",
" InetAddress.getByName(\"127.0.0.1\");",
" new InetSocketAddress(\"127.0.0.1\", 80);",
" new Socket(\"::1\", 80);",
" InetAddress.getByName(\"::1\");",
" new InetSocketAddress(\"::1\", 80);",
" }",
"}")
"""
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
class Test {
void f() throws Exception {
new Socket("127.0.0.1", 80);
InetAddress.getByName("127.0.0.1");
new InetSocketAddress("127.0.0.1", 80);
new Socket("::1", 80);
InetAddress.getByName("::1");
new InetSocketAddress("::1", 80);
}
}
""")
.addOutputLines(
"Test.java",
"import java.net.InetAddress;",
"import java.net.InetSocketAddress;",
"import java.net.Socket;",
"class Test {",
" void f() throws Exception{",
" new Socket(InetAddress.getLoopbackAddress(), 80);",
" InetAddress.getLoopbackAddress();",
" new InetSocketAddress(InetAddress.getLoopbackAddress(), 80);",
" new Socket(InetAddress.getLoopbackAddress(), 80);",
" InetAddress.getLoopbackAddress();",
" new InetSocketAddress(InetAddress.getLoopbackAddress(), 80);",
" }",
"}")
"""
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
class Test {
void f() throws Exception {
new Socket(InetAddress.getLoopbackAddress(), 80);
InetAddress.getLoopbackAddress();
new InetSocketAddress(InetAddress.getLoopbackAddress(), 80);
new Socket(InetAddress.getLoopbackAddress(), 80);
InetAddress.getLoopbackAddress();
new InetSocketAddress(InetAddress.getLoopbackAddress(), 80);
}
}
""")
.doTest();
}
}
Loading

0 comments on commit 0c5b38b

Please sign in to comment.