Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dev/tools/perl_test_runner.pl
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ sub run_single_test {
$local_test_dir =~ s{/[^/]+$}{};
}
}
# For tests in t/ directory (t/op/, t/base/, etc.), change to t/
# so they can find ./test.pl via require
elsif ($test_file =~ m{^t/}) {
$local_test_dir = 't';
}

chdir($local_test_dir) if $local_test_dir && -d $local_test_dir;

Expand Down
56 changes: 54 additions & 2 deletions src/main/java/org/perlonjava/operators/Directory.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,66 @@ public static RuntimeScalar chdir(RuntimeScalar runtimeScalar) {
// directory handle as the argument. On systems that don't support
// fchdir(2), passing handles raises an exception.

String dirName = runtimeScalar.toString();
String dirName;

// Check if argument is a filehandle or dirhandle
if (runtimeScalar.value instanceof RuntimeIO || runtimeScalar.value instanceof RuntimeGlob) {
// Try to get RuntimeIO from the scalar
RuntimeIO io = RuntimeIO.getRuntimeIO(runtimeScalar);
if (io != null) {
// This is a filehandle or dirhandle - fchdir is not supported
throw new PerlCompilerException("The fchdir function is unimplemented");
}
}

// Handle chdir() with no arguments - check environment variables
if (!runtimeScalar.defined().getBoolean()) {
// Try HOME, then LOGDIR, then SYS$LOGIN (for VMS only)
RuntimeHash envHash = GlobalVariable.getGlobalHash("main::ENV");
RuntimeScalar homeDir = envHash.get("HOME");
if (homeDir != null && homeDir.defined().getBoolean() && !homeDir.toString().isEmpty()) {
dirName = homeDir.toString();
} else {
RuntimeScalar logDir = envHash.get("LOGDIR");
if (logDir != null && logDir.defined().getBoolean() && !logDir.toString().isEmpty()) {
dirName = logDir.toString();
} else {
// Check SYS$LOGIN only on VMS
String osName = GlobalVariable.getGlobalVariable("main::^O").toString();
if ("VMS".equalsIgnoreCase(osName)) {
RuntimeScalar sysLogin = envHash.get("SYS$LOGIN");
if (sysLogin != null && sysLogin.defined().getBoolean() && !sysLogin.toString().isEmpty()) {
dirName = sysLogin.toString();
} else {
// No environment variable set - fail with EINVAL
getGlobalVariable("main::!").set(22); // EINVAL
return scalarFalse;
}
} else {
// Not VMS and no HOME/LOGDIR - fail with EINVAL
getGlobalVariable("main::!").set(22); // EINVAL
return scalarFalse;
}
}
}
} else {
dirName = runtimeScalar.toString();
}

// Check for empty string - should fail with ENOENT
if (dirName.isEmpty()) {
getGlobalVariable("main::!").set(2); // ENOENT
return scalarFalse;
}

File absoluteDir = RuntimeIO.resolveFile(dirName);

if (absoluteDir.exists() && absoluteDir.isDirectory()) {
System.setProperty("user.dir", absoluteDir.getAbsolutePath());
return scalarTrue;
} else {
getGlobalVariable("main::!").set("chdir failed: No such directory '" + dirName + "'");
// Set errno to ENOENT (No such file or directory)
getGlobalVariable("main::!").set(2); // ENOENT
return scalarFalse;
}
}
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/org/perlonjava/perlmodule/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,21 @@ public static RuntimeList exportToLevel(RuntimeArray args, int ctx) {

if (symbolString.startsWith(":")) {
String tagName = symbolString.substring(1);
RuntimeScalar tagValue = exportTags.get(tagName);
if (tagValue == null || tagValue.type != RuntimeScalarType.ARRAYREFERENCE) {
throw new PerlCompilerException("Invalid or unknown export tag: " + tagName);
}
RuntimeArray tagSymbols = tagValue.arrayDeref();
if (tagSymbols != null) {
tagArray.elements.addAll(tagSymbols.elements);

// Handle special :DEFAULT tag - it means "use @EXPORT"
if ("DEFAULT".equals(tagName)) {
if (export != null && !export.elements.isEmpty()) {
tagArray.elements.addAll(export.elements);
}
} else {
RuntimeScalar tagValue = exportTags.get(tagName);
if (tagValue == null || tagValue.type != RuntimeScalarType.ARRAYREFERENCE) {
throw new PerlCompilerException("Invalid or unknown export tag: " + tagName);
}
RuntimeArray tagSymbols = tagValue.arrayDeref();
if (tagSymbols != null) {
tagArray.elements.addAll(tagSymbols.elements);
}
}
} else {
tagArray.elements.add(symbolObj);
Expand Down