1423 try { 1424 Set<String> env1 = new HashSet<String> 1425 (Arrays.asList(nativeEnv((String[])null).split("\n"))); 1426 1427 ProcessBuilder pb = new ProcessBuilder(); 1428 pb.environment().put("QwErTyUiOp","AsDfGhJk"); 1429 1430 Set<String> env2 = new HashSet<String> 1431 (Arrays.asList(nativeEnv(pb).split("\n"))); 1432 1433 check(env2.size() == env1.size() + 1); 1434 env1.add("QwErTyUiOp=AsDfGhJk"); 1435 check(env1.equals(env2)); 1436 } catch (Throwable t) { unexpected(t); } 1437 1438 //---------------------------------------------------------------- 1439 // Test Runtime.exec(...envp...) 1440 // Check for sort order of environment variables on Windows. 1441 //---------------------------------------------------------------- 1442 try { 1443 // '+' < 'A' < 'Z' < '_' < 'a' < 'z' < '~' 1444 String[]envp = {"FOO=BAR","BAZ=GORP","QUUX=", 1445 "+=+", "_=_", "~=~"}; 1446 String output = nativeEnv(envp); 1447 String expected = "+=+\nBAZ=GORP\nFOO=BAR\nQUUX=\n_=_\n~=~\n"; 1448 // On Windows, Java must keep the environment sorted. 1449 // Order is random on Unix, so this test does the sort. 1450 if (! Windows.is()) 1451 output = sortByLinesWindowsly(output); 1452 equal(output, expected); 1453 } catch (Throwable t) { unexpected(t); } 1454 1455 //---------------------------------------------------------------- 1456 // System.getenv() must be consistent with System.getenv(String) 1457 //---------------------------------------------------------------- 1458 try { 1459 for (Map.Entry<String,String> e : getenv().entrySet()) 1460 equal(getenv(e.getKey()), e.getValue()); 1461 } catch (Throwable t) { unexpected(t); } 1462 1463 //---------------------------------------------------------------- 1464 // Fiddle with working directory in child 1465 //---------------------------------------------------------------- 1466 try { 1467 String canonicalUserDir = | 1423 try { 1424 Set<String> env1 = new HashSet<String> 1425 (Arrays.asList(nativeEnv((String[])null).split("\n"))); 1426 1427 ProcessBuilder pb = new ProcessBuilder(); 1428 pb.environment().put("QwErTyUiOp","AsDfGhJk"); 1429 1430 Set<String> env2 = new HashSet<String> 1431 (Arrays.asList(nativeEnv(pb).split("\n"))); 1432 1433 check(env2.size() == env1.size() + 1); 1434 env1.add("QwErTyUiOp=AsDfGhJk"); 1435 check(env1.equals(env2)); 1436 } catch (Throwable t) { unexpected(t); } 1437 1438 //---------------------------------------------------------------- 1439 // Test Runtime.exec(...envp...) 1440 // Check for sort order of environment variables on Windows. 1441 //---------------------------------------------------------------- 1442 try { 1443 String systemRoot = "SystemRoot=" + System.getenv("SystemRoot"); 1444 // '+' < 'A' < 'Z' < '_' < 'a' < 'z' < '~' 1445 String[]envp = {"FOO=BAR","BAZ=GORP","QUUX=", 1446 "+=+", "_=_", "~=~", systemRoot}; 1447 String output = nativeEnv(envp); 1448 String expected = "+=+\nBAZ=GORP\nFOO=BAR\nQUUX=\n"+systemRoot+"\n_=_\n~=~\n"; 1449 // On Windows, Java must keep the environment sorted. 1450 // Order is random on Unix, so this test does the sort. 1451 if (! Windows.is()) 1452 output = sortByLinesWindowsly(output); 1453 equal(output, expected); 1454 } catch (Throwable t) { unexpected(t); } 1455 1456 //---------------------------------------------------------------- 1457 // System.getenv() must be consistent with System.getenv(String) 1458 //---------------------------------------------------------------- 1459 try { 1460 for (Map.Entry<String,String> e : getenv().entrySet()) 1461 equal(getenv(e.getKey()), e.getValue()); 1462 } catch (Throwable t) { unexpected(t); } 1463 1464 //---------------------------------------------------------------- 1465 // Fiddle with working directory in child 1466 //---------------------------------------------------------------- 1467 try { 1468 String canonicalUserDir = |