Skip to content

Commit

Permalink
Fix for #157
Browse files Browse the repository at this point in the history
  • Loading branch information
marcgurevitx committed Jul 10, 2024
1 parent 58ff9c1 commit ce50a35
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 @@ -337,8 +337,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 ce50a35

Please sign in to comment.