Skip to content

Commit

Permalink
Fix for JoeStrout#157
Browse files Browse the repository at this point in the history
  • Loading branch information
marcgurevitx authored and borgi committed Nov 21, 2024
1 parent f0b65c6 commit 8b5dfea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion MiniScript-cpp/src/ShellIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,12 @@ static IntrinsicResult intrinsic_basename(Context *context, IntrinsicResult part
char extBuf[256];
_splitpath_s(pathStr.c_str(), driveBuf, sizeof(driveBuf), nullptr, 0, nameBuf, sizeof(nameBuf), extBuf, sizeof(extBuf));
String result = String(nameBuf) + String(extBuf);
#else
#elif defined(__APPLE__) || defined(__FreeBSD__)
String result(basename((char*)pathStr.c_str()));
#else
char *duplicate = strdup((char*)pathStr.c_str());
String result(basename(duplicate));
free(duplicate);
#endif
return IntrinsicResult(result);
}
Expand Down
12 changes: 12 additions & 0 deletions MiniScript-cpp/tests/testFileName.ms
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "qa"

testDir = "tests/"

testFileName = function
p = "a/b/"
n = file.name(p)
qa.assertEqual n, "b"
qa.assertEqual p, "a/b/"
end function

if refEquals(locals, globals) then testFileName

0 comments on commit 8b5dfea

Please sign in to comment.