Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceres6 committed Oct 23, 2023
1 parent 282946b commit 2370642
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions test/cctest/test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
#include "gtest/gtest.h"
#include "simdutf.h"
#include "util-inl.h"
#include "node_test_fixture.h"

using node::Calloc;
using node::Malloc;
using node::MaybeStackBuffer;
using node::PathResolve;
using node::SPrintF;
using node::StringEqualNoCase;
using node::StringEqualNoCaseN;
using node::ToLower;
using node::UncheckedCalloc;
using node::UncheckedMalloc;

class UtilTest : public EnvironmentTestFixture {};

TEST(UtilTest, ListHead) {
struct Item { node::ListNode<Item> node_; };
typedef node::ListHead<Item, &Item::node_> List;
Expand Down Expand Up @@ -299,3 +303,44 @@ TEST(UtilTest, SPrintF) {
const std::string with_zero = std::string("a") + '\0' + 'b';
EXPECT_EQ(SPrintF("%s", with_zero), with_zero);
}

TEST(UtilTest, PathResolve) {
#ifdef _WIN32
// TODO: figure out how to get env
EXPECT_EQ(PathResolve(nullptr, {"c:/blah\\blah", "d:/games", "c:../a"}),
"c:\\blah\\a");
EXPECT_EQ(PathResolve(nullptr, {"c:/ignore", "d:\\a/b\\c/d", "\\e.exe"}),
"d:\\e.exe");
EXPECT_EQ(PathResolve(nullptr, {"c:/ignore", "c:/some/file"}),
"c:\\some\\file");
EXPECT_EQ(PathResolve(nullptr, {"d:/ignore", "d:some/dir//"}),
"d:\\ignore\\some\\dir");
// EXPECT_EQ(PathResolve(nullptr, {"."}), process.cwd()); // TODO: figure
// out how to get cwd
EXPECT_EQ(PathResolve(nullptr, {"//server/share", "..", "relative\\"}),
"\\\\server\\share\\relative");
EXPECT_EQ(PathResolve(nullptr, {"c:/", "//"}), "c:\\");
EXPECT_EQ(PathResolve(nullptr, {"c:/", "//dir"}), "c:\\dir");
EXPECT_EQ(PathResolve(nullptr, {"c:/", "//server/share"}),
"\\\\server\\share\\");
EXPECT_EQ(PathResolve(nullptr, {"c:/", "//server//share"}),
"\\\\server\\share\\");
EXPECT_EQ(PathResolve(nullptr, {"c:/", "///some//dir"}), "c:\\some\\dir");
EXPECT_EQ(
PathResolve(nullptr, {"C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js"}),
"C:\\foo\\tmp.3\\cycles\\root.js");
#else
const v8::HandleScope handle_scope(isolate_);
Argv argv;
Env env{handle_scope, argv, node::EnvironmentFlags::kNoBrowserGlobals};
// TODO: change nullptr to actual environment when working
EXPECT_EQ(PathResolve(env, {"/var/lib", "../", "file/"}), "/var/file");
EXPECT_EQ(PathResolve(nullptr, {"/var/lib", "/../", "file/"}), "/file");
// EXPECT_EQ(PathResolve(nullptr, {"a/b/c/", "../../.."}), posixyCwd); //
// TODO: figure out how to get posixyCwd EXPECT_EQ(PathResolve(nullptr,
// {"."}), posixyCwd);
EXPECT_EQ(PathResolve(nullptr, {"/some/dir", ".", "/absolute/"}), "/absolute");
EXPECT_EQ(PathResolve(nullptr, {"/foo/tmp.3/", "../tmp.3/cycles/root.js"}),
"/foo/tmp.3/cycles/root.js");
#endif
}
2 changes: 1 addition & 1 deletion test/parallel/test-permission-fs-relative-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const assert = require('assert');
const { spawnSync } = require('child_process');

{
// Relative path as CLI args are NOT supported yet
// Relative path as CLI args are supported
const { status, stdout } = spawnSync(
process.execPath,
[
Expand Down

0 comments on commit 2370642

Please sign in to comment.