Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimeon Andreev2018-12-06 08:32:57 +0000
committerSimeon Andreev2018-12-06 15:44:40 +0000
commitbe463b257a9ef835177ce02bc0b5d07c11cdec60 (patch)
tree177a84e87e2d3ee3a864c2b617eb45ee76a1ebe1
parent178dc273b0765dcfaf9cca6a214c89ecf4c18d31 (diff)
downloadeclipse.jdt.core-be463b257a9ef835177ce02bc0b5d07c11cdec60.tar.gz
eclipse.jdt.core-be463b257a9ef835177ce02bc0b5d07c11cdec60.tar.xz
eclipse.jdt.core-be463b257a9ef835177ce02bc0b5d07c11cdec60.zip
Bug 413114 - added encoding assertions in test testBug376673e
If JavaSearchBugsTests2.testBug376673e fails in Linux environments if the environment variable LANG is not set to UTF-8. This is e.g. the case in official builds. This change adds further assertions in the test, to validate that correct encoding is set. If the encoding is not as expected, the test fails with a more comprehensible message. Change-Id: I21fe15947262137f48195026add56525fe35a748 Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java
index a4fe9ca797..770f241fc2 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java
@@ -22,12 +22,16 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -61,6 +65,7 @@ import org.eclipse.jdt.core.search.TypeNameMatchRequestor;
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
import org.eclipse.jdt.internal.core.search.matching.MethodPattern;
+import org.eclipse.osgi.service.environment.Constants;
import junit.framework.Test;
@@ -801,6 +806,7 @@ public class JavaSearchBugsTests2 extends AbstractJavaSearchTests {
if ("macosx".equals(System.getProperty("osgi.os"))) {
return;
}
+ assertUTF8Encoding();
IJavaProject p = createJavaProject("P", new String[] {}, new String[] { "/P/lib376673.jar", "JCL17_LIB" }, "", "1.7");
IPath jarPath = p.getProject().getLocation().append("lib376673.jar");
@@ -2873,4 +2879,29 @@ public class JavaSearchBugsTests2 extends AbstractJavaSearchTests {
return buffer.toByteArray();
}
+
+ private void assertUTF8Encoding() {
+ String fileEncodingVMProperty = System.getProperty("file.encoding");
+ Charset defaultCharset = Charset.defaultCharset();
+ String langEnvVariable = System.getenv("LANG");
+ StringBuilder errorMessage = new StringBuilder();
+ errorMessage.append(System.lineSeparator());
+ errorMessage.append("Unexpected encoding during test, encoding parameters are:");
+ errorMessage.append(System.lineSeparator());
+ errorMessage.append("-Dfile.encoding=" + fileEncodingVMProperty);
+ errorMessage.append(System.lineSeparator());
+ errorMessage.append("Charset.defaultCharset()=" + defaultCharset);
+ errorMessage.append(System.lineSeparator());
+ errorMessage.append("LANG=" + langEnvVariable);
+
+ assertEquals("unexpected default charset " + errorMessage, StandardCharsets.UTF_8, defaultCharset);
+ if (Constants.OS_LINUX.equals(System.getProperty("osgi.os"))) {
+ assertNotNull("expected LANG environment variable to be set" + errorMessage, langEnvVariable);
+ String utf8LANGRegexp = ".*\\.(UTF-8|UTF8|utf-8|utf8)";
+ Pattern utf8LANGPattern = Pattern.compile(utf8LANGRegexp);
+ Matcher LANGMatcher = utf8LANGPattern.matcher(langEnvVariable);
+ assertTrue("expected encoding set with LANG environment variable to match regexp: " + utf8LANGRegexp + ", LANG=" + langEnvVariable + errorMessage,
+ LANGMatcher.matches());
+ }
+ }
} \ No newline at end of file

Back to the top