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

Use text blocks for internal Error Prone test outputs #4573

Merged
merged 1 commit into from
Sep 12, 2024
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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
Loading