Skip to content

Commit 01c8600

Browse files
authored
Merge pull request #58 from fglock/fix-chdir-test
Fix t/op/chdir.t - All 51 tests passing (100%)
2 parents a3d4f5e + 95539cd commit 01c8600

File tree

3 files changed

+74
-9
lines changed

3 files changed

+74
-9
lines changed

dev/tools/perl_test_runner.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ sub run_single_test {
278278
$local_test_dir =~ s{/[^/]+$}{};
279279
}
280280
}
281+
# For tests in t/ directory (t/op/, t/base/, etc.), change to t/
282+
# so they can find ./test.pl via require
283+
elsif ($test_file =~ m{^t/}) {
284+
$local_test_dir = 't';
285+
}
281286

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

src/main/java/org/perlonjava/operators/Directory.java

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,66 @@ public static RuntimeScalar chdir(RuntimeScalar runtimeScalar) {
3636
// directory handle as the argument. On systems that don't support
3737
// fchdir(2), passing handles raises an exception.
3838

39-
String dirName = runtimeScalar.toString();
39+
String dirName;
40+
41+
// Check if argument is a filehandle or dirhandle
42+
if (runtimeScalar.value instanceof RuntimeIO || runtimeScalar.value instanceof RuntimeGlob) {
43+
// Try to get RuntimeIO from the scalar
44+
RuntimeIO io = RuntimeIO.getRuntimeIO(runtimeScalar);
45+
if (io != null) {
46+
// This is a filehandle or dirhandle - fchdir is not supported
47+
throw new PerlCompilerException("The fchdir function is unimplemented");
48+
}
49+
}
50+
51+
// Handle chdir() with no arguments - check environment variables
52+
if (!runtimeScalar.defined().getBoolean()) {
53+
// Try HOME, then LOGDIR, then SYS$LOGIN (for VMS only)
54+
RuntimeHash envHash = GlobalVariable.getGlobalHash("main::ENV");
55+
RuntimeScalar homeDir = envHash.get("HOME");
56+
if (homeDir != null && homeDir.defined().getBoolean() && !homeDir.toString().isEmpty()) {
57+
dirName = homeDir.toString();
58+
} else {
59+
RuntimeScalar logDir = envHash.get("LOGDIR");
60+
if (logDir != null && logDir.defined().getBoolean() && !logDir.toString().isEmpty()) {
61+
dirName = logDir.toString();
62+
} else {
63+
// Check SYS$LOGIN only on VMS
64+
String osName = GlobalVariable.getGlobalVariable("main::^O").toString();
65+
if ("VMS".equalsIgnoreCase(osName)) {
66+
RuntimeScalar sysLogin = envHash.get("SYS$LOGIN");
67+
if (sysLogin != null && sysLogin.defined().getBoolean() && !sysLogin.toString().isEmpty()) {
68+
dirName = sysLogin.toString();
69+
} else {
70+
// No environment variable set - fail with EINVAL
71+
getGlobalVariable("main::!").set(22); // EINVAL
72+
return scalarFalse;
73+
}
74+
} else {
75+
// Not VMS and no HOME/LOGDIR - fail with EINVAL
76+
getGlobalVariable("main::!").set(22); // EINVAL
77+
return scalarFalse;
78+
}
79+
}
80+
}
81+
} else {
82+
dirName = runtimeScalar.toString();
83+
}
84+
85+
// Check for empty string - should fail with ENOENT
86+
if (dirName.isEmpty()) {
87+
getGlobalVariable("main::!").set(2); // ENOENT
88+
return scalarFalse;
89+
}
90+
4091
File absoluteDir = RuntimeIO.resolveFile(dirName);
4192

4293
if (absoluteDir.exists() && absoluteDir.isDirectory()) {
4394
System.setProperty("user.dir", absoluteDir.getAbsolutePath());
4495
return scalarTrue;
4596
} else {
46-
getGlobalVariable("main::!").set("chdir failed: No such directory '" + dirName + "'");
97+
// Set errno to ENOENT (No such file or directory)
98+
getGlobalVariable("main::!").set(2); // ENOENT
4799
return scalarFalse;
48100
}
49101
}

src/main/java/org/perlonjava/perlmodule/Exporter.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,21 @@ public static RuntimeList exportToLevel(RuntimeArray args, int ctx) {
174174

175175
if (symbolString.startsWith(":")) {
176176
String tagName = symbolString.substring(1);
177-
RuntimeScalar tagValue = exportTags.get(tagName);
178-
if (tagValue == null || tagValue.type != RuntimeScalarType.ARRAYREFERENCE) {
179-
throw new PerlCompilerException("Invalid or unknown export tag: " + tagName);
180-
}
181-
RuntimeArray tagSymbols = tagValue.arrayDeref();
182-
if (tagSymbols != null) {
183-
tagArray.elements.addAll(tagSymbols.elements);
177+
178+
// Handle special :DEFAULT tag - it means "use @EXPORT"
179+
if ("DEFAULT".equals(tagName)) {
180+
if (export != null && !export.elements.isEmpty()) {
181+
tagArray.elements.addAll(export.elements);
182+
}
183+
} else {
184+
RuntimeScalar tagValue = exportTags.get(tagName);
185+
if (tagValue == null || tagValue.type != RuntimeScalarType.ARRAYREFERENCE) {
186+
throw new PerlCompilerException("Invalid or unknown export tag: " + tagName);
187+
}
188+
RuntimeArray tagSymbols = tagValue.arrayDeref();
189+
if (tagSymbols != null) {
190+
tagArray.elements.addAll(tagSymbols.elements);
191+
}
184192
}
185193
} else {
186194
tagArray.elements.add(symbolObj);

0 commit comments

Comments
 (0)