Skip to content

Commit

Permalink
Fixes GH-242 and replaces some Locale.ENGLISH with Locale.ROOT.
Browse files Browse the repository at this point in the history
  • Loading branch information
dweiss committed Jan 18, 2017
1 parent 6ddd8fc commit b658d85
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ New Features

* GH-240: Add RandomPicks.randomFrom on primitive arrays. (Dawid Weiss)

Bug Fixes

* GH-242: RandomizedTest.nextTempName uses locale-sensitive String.format.
(Dawid Weiss)

======================= randomizedtesting 2.4.0 ====================

Changes in Backwards Compatibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static CharSequence toHumanDuration(long duration) {
if (longTime) {
duration = emitOrSkip(duration, str, MILLIS_IN_A_SECOND, " second", true);
} else {
str.append(String.format(Locale.ENGLISH, "%.2f sec.", (duration / 1000.0f)));
str.append(String.format(Locale.ROOT, "%.2f sec.", (duration / 1000.0f)));
}
return str;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static String formatDurationInSeconds(long timeMillis) {
} else {
precision = 2;
}
return String.format(Locale.ENGLISH, "%4." + precision + "fs", timeMillis / 1000.0);
return String.format(Locale.ROOT, "%4." + precision + "fs", timeMillis / 1000.0);
}

public static String formatDescription(Description description) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ public void execute() throws BuildException {


if (jvmCount > 1 && uniqueSuiteNames && testCollection.hasReplicatedSuites()) {
throw new BuildException(String.format(Locale.ENGLISH,
throw new BuildException(String.format(Locale.ROOT,
"There are test suites that request JVM replication and the number of forked JVMs %d is larger than 1. Run on a single JVM.",
jvmCount));
}
Expand Down Expand Up @@ -1147,7 +1147,7 @@ private List<String> loadBalanceSuites(List<ForkedJvmInfo> jvmInfo,
throw new RuntimeException("Balancer must return suite name as a key: " + e.suiteName);
}

log(String.format(Locale.ENGLISH,
log(String.format(Locale.ROOT,
"Assignment hint: J%-2d (cost %5d) %s (by %s)",
e.slaveId,
e.estimatedCost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public List<Assignment> assign(Collection<String> suiteNames, int slaves, long s
}
for (Integer id : ordered.keySet()) {
final SlaveLoad slave = ordered.get(id);
owner.log(String.format(Locale.ENGLISH,
owner.log(String.format(Locale.ROOT,
"Expected execution time on JVM J%d: %8.2fs",
slave.id,
slave.estimatedFinish / 1000.0f),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void execute() throws BuildException {
Collections.sort(entries, byDescHint);
final int j = Math.min(max, entries.size());
for (int i = 0; i < j; i++) {
log(String.format(Locale.ENGLISH, "%6.2fs | %s",
log(String.format(Locale.ROOT, "%6.2fs | %s",
entries.get(i).averageHint / 1000.0,
entries.get(i).suiteName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.Flushable;
import java.io.IOException;
import java.io.Writer;
import java.util.Locale;

/**
* Writes a JSON (<a href="http://www.ietf.org/rfc/rfc4627.txt">RFC 4627</a>)
Expand Down Expand Up @@ -139,7 +140,7 @@ public class JsonWriter extends IOContext implements Closeable, Flushable {
static {
REPLACEMENT_CHARS = new String[128];
for (int i = 0; i <= 0x1f; i++) {
REPLACEMENT_CHARS[i] = String.format("\\u%04x", (int) i);
REPLACEMENT_CHARS[i] = String.format(Locale.ROOT, "\\u%04x", (int) i);
}
REPLACEMENT_CHARS['"'] = "\\\"";
REPLACEMENT_CHARS['\\'] = "\\\\";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ private void emitSuiteEnd(AggregatedSuiteResultEvent e, int suitesCompleted) thr

final StringBuilder b = new StringBuilder();
final int totalErrors = this.totalErrors.addAndGet(e.isSuccessful() ? 0 : 1);
b.append(String.format(Locale.ENGLISH, "%sCompleted [%d/%d%s]%s in %.2fs, ",
b.append(String.format(Locale.ROOT, "%sCompleted [%d/%d%s]%s in %.2fs, ",
shortTimestamp(e.getStartTimestamp() + e.getExecutionTime()),
suitesCompleted,
totalSuites,
Expand Down Expand Up @@ -610,7 +610,7 @@ private void emitStatusLine(AggregatedResultEvent result, TestStatus status, lon
line.append(Strings.padEnd(statusNames.get(status), 8, ' '));
line.append(formatDurationInSeconds(timeMillis));
if (forkedJvmCount > 1) {
line.append(String.format(Locale.ENGLISH, jvmIdFormat, result.getSlave().id));
line.append(String.format(Locale.ROOT, jvmIdFormat, result.getSlave().id));
}
line.append(" | ");

Expand Down Expand Up @@ -639,11 +639,11 @@ private void emitStatusLine(AggregatedResultEvent result, TestStatus status, lon
for (FailureMirror fm : failures) {
count++;
if (fm.isAssumptionViolation()) {
pos.write(String.format(Locale.ENGLISH,
pos.write(String.format(Locale.ROOT,
"Assumption #%d: %s",
count, MoreObjects.firstNonNull(fm.getMessage(), "(no message)")));
} else {
pos.write(String.format(Locale.ENGLISH,
pos.write(String.format(Locale.ROOT,
"Throwable #%d: %s",
count,
showStackTraces ? filterStackTrace(fm.getTrace()) : fm.getThrowableString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public void pseudoLoadBalancing() {
jvms = Integer.parseInt(System.getProperty("junit4.childvm.count"));

assumeTrue(
String.format(Locale.ENGLISH, "Test %d ignored on VM %d.", id, jvmId),
String.format(Locale.ROOT, "Test %d ignored on VM %d.", id, jvmId),
(id % jvms) == jvmId);
}

@Test
public void replicatedTest() {
System.out.println(String.format(Locale.ENGLISH, "Test %d executed on VM %d.", id, jvmId));
System.out.println(String.format(Locale.ROOT, "Test %d executed on VM %d.", id, jvmId));
}

@ParametersFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private Iterator<Node> tokenize(String rule) {
} else if (value.startsWith("@")) {
t = new TestGroupNode();
} else {
throw new SyntaxException(null, String.format(Locale.ENGLISH,
throw new SyntaxException(null, String.format(Locale.ROOT,
"Unrecognized token '%s'. At: \"%s\"",
value == null ? "<null>" : value,
new InputRange(rule, s, len)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ private List<TestCandidate> collectCandidatesForMethod(
}

Description description = Description.createSuiteDescription(
String.format("%s%s(%s)", method.getName(), formattedArguments, suiteClass.getName()),
String.format(Locale.ROOT, "%s%s(%s)", method.getName(), formattedArguments, suiteClass.getName()),
method.getAnnotations());

// Create an instance and delay instantiation exception if possible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Locale;
import java.util.Random;
import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.Assume;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -333,11 +334,8 @@ public static int scaledRandomIntBetween(int min, int max) {
*/
private static Path globalTempDir;

/**
* Subfolders under {@link #globalTempDir} are created synchronously, so we don't need
* to mangle filenames.
*/
private static int tempSubFileNameCount;
/** */
private static AtomicInteger tempSubFileNameCount = new AtomicInteger(0);

/**
* Global temporary directory created for the duration of this class's lifespan. If
Expand Down Expand Up @@ -370,8 +368,8 @@ public void run() {
rmDir(globalTempDir);
} catch (IOException e) {
// Not much else to do but to log and quit.
System.err.println("Could not completely delete temporary folder: " +
globalTempDir.toAbsolutePath() + ". Cause: ");
System.err.println("Could not delete temporary folder: "
+ globalTempDir.toAbsolutePath() + ". Cause: ");
e.printStackTrace(System.err);
}
}
Expand Down Expand Up @@ -446,8 +444,8 @@ public static Path newTempFile(LifecycleScope scope) throws IOException {
}

/** Next temporary filename. */
private static String nextTempName() {
return String.format("%04d has-space", tempSubFileNameCount++);
protected static String nextTempName() {
return String.format(Locale.ROOT, "%04d has-space", tempSubFileNameCount.getAndIncrement());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ public Void run() {
Collections.sort(fieldsAndValues);

StringBuilder b = new StringBuilder();
b.append(String.format(Locale.ENGLISH, "Clean up static fields (in @AfterClass?), "
b.append(String.format(Locale.ROOT, "Clean up static fields (in @AfterClass?), "
+ "your test seems to hang on to approximately %,d bytes (threshold is %,d). " +
"Field reference sizes (counted individually):",
ramUsage, leakThreshold));

for (Entry e : fieldsAndValues) {
b.append(String.format(Locale.ENGLISH, "\n - %,d bytes, %s", e.ramUsed,
b.append(String.format(Locale.ROOT, "\n - %,d bytes, %s", e.ramUsed,
e.field.toString()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ public void checkOrder() throws Exception {
final int i = junitOrder.size();
final int j = callOrder.size();

System.out.println(String.format(Locale.ENGLISH,
System.out.println(String.format(Locale.ROOT,
"%-30s | %-30s", "JUnit4", "RR"));
for (int k = 0; k < Math.max(i, j); k++) {
System.out.println(String.format(Locale.ENGLISH,
System.out.println(String.format(Locale.ROOT,
"%-30s | %-30s",
k < i ? junitOrder.get(k) : "--",
k < j ? callOrder.get(k) : "--"));
Expand Down

0 comments on commit b658d85

Please sign in to comment.