Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: support zig build test #15915

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,20 @@ pub fn build(b: *Build) !void {
// const run = b.addRunArtifact(exe);
// step.dependOn(&run.step);
}

// zig build test
{
const unit_tests = b.addTest(.{
.name = "zig-unit-tests",
.root_source_file = b.path("src/unit_test.zig"),
.optimize = build_options.optimize,
.target = build_options.target,
.use_llvm = if (build_options.no_llvm) false else null,
.use_lld = if (build_options.os == .mac) false else !build_options.no_llvm,
});
const test_step = b.step("test", "Run Zig-only unit tests");
test_step.dependOn(&unit_tests.step);
}
}

pub fn addMultiCheck(
Expand Down
5 changes: 2 additions & 3 deletions src/bun.js/api/glob.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const Glob = @This();
const globImpl = @import("../../glob.zig");
const globImplAscii = @import("../../glob_ascii.zig");
const GlobWalker = globImpl.BunGlobWalker;
const PathLike = @import("../node/types.zig").PathLike;
const ArgumentsSlice = @import("../node/types.zig").ArgumentsSlice;
Expand Down Expand Up @@ -407,7 +406,7 @@ pub fn match(this: *Glob, globalThis: *JSGlobalObject, callframe: *JSC.CallFrame
var str = str_arg.toSlice(globalThis, arena.allocator());
defer str.deinit();

if (this.is_ascii and isAllAscii(str.slice())) return JSC.JSValue.jsBoolean(globImplAscii.match(this.pattern, str.slice()));
if (this.is_ascii and isAllAscii(str.slice())) return JSC.JSValue.jsBoolean(globImpl.Ascii.match(this.pattern, str.slice()));

const codepoints = codepoints: {
if (this.pattern_codepoints) |cp| break :codepoints cp.items[0..];
Expand All @@ -422,7 +421,7 @@ pub fn match(this: *Glob, globalThis: *JSGlobalObject, callframe: *JSC.CallFrame
break :codepoints codepoints.items[0..codepoints.items.len];
};

return if (globImpl.matchImpl(codepoints, str.slice()).matches()) .true else .false;
return if (globImpl.walk.matchImpl(codepoints, str.slice()).matches()) .true else .false;
}

pub fn convertUtf8(codepoints: *std.ArrayList(u32), pattern: []const u8) !void {
Expand Down
6 changes: 3 additions & 3 deletions src/cli/filter_arg.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn globIgnoreFn(val: []const u8) bool {
return false;
}

const GlobWalker = Glob.GlobWalker_(globIgnoreFn, Glob.DirEntryAccessor, false);
const GlobWalker = Glob.GlobWalker(globIgnoreFn, Glob.walk.DirEntryAccessor, false);

pub fn getCandidatePackagePatterns(allocator: std.mem.Allocator, log: *bun.logger.Log, out_patterns: *std.ArrayList([]u8), workdir_: []const u8, root_buf: *bun.PathBuffer) ![]const u8 {
bun.JSAst.Expr.Data.Store.create();
Expand Down Expand Up @@ -187,7 +187,7 @@ pub const FilterSet = struct {

pub fn matchesPath(self: *const FilterSet, path: []const u8) bool {
for (self.filters) |filter| {
if (Glob.matchImpl(filter.codepoints, path).matches()) {
if (Glob.walk.matchImpl(filter.codepoints, path).matches()) {
return true;
}
}
Expand All @@ -200,7 +200,7 @@ pub const FilterSet = struct {
.name => name,
.path => path,
};
if (Glob.matchImpl(filter.codepoints, target).matches()) {
if (Glob.walk.matchImpl(filter.codepoints, target).matches()) {
return true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/cli/outdated_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ pub const OutdatedCommand = struct {

const abs_res_path = path.joinAbsString(FileSystem.instance.top_level_dir, &[_]string{res_path}, .posix);

if (!glob.matchImpl(pattern, strings.withoutTrailingSlash(abs_res_path)).matches()) {
if (!glob.walk.matchImpl(pattern, strings.withoutTrailingSlash(abs_res_path)).matches()) {
break :matched false;
}
},
.name => |pattern| {
const name = pkg_names[workspace_pkg_id].slice(string_buf);

if (!glob.matchImpl(pattern, name).matches()) {
if (!glob.walk.matchImpl(pattern, name).matches()) {
break :matched false;
}
},
Expand Down Expand Up @@ -331,7 +331,7 @@ pub const OutdatedCommand = struct {
.path => unreachable,
.name => |name_pattern| {
if (name_pattern.len == 0) continue;
if (!glob.matchImpl(name_pattern, dep.name.slice(string_buf)).matches()) {
if (!glob.walk.matchImpl(name_pattern, dep.name.slice(string_buf)).matches()) {
break :match false;
}
},
Expand Down
8 changes: 4 additions & 4 deletions src/cli/pack_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ pub const PackCommand = struct {
// normally the behavior of `index.js` and `**/index.js` are the same,
// but includes require `**/`
const match_path = if (include.@"leading **/") entry_name else entry_subpath;
switch (glob.matchImpl(include.glob, match_path)) {
switch (glob.walk.matchImpl(include.glob, match_path)) {
.match => included = true,
.negate_no_match => included = false,

Expand Down Expand Up @@ -976,7 +976,7 @@ pub const PackCommand = struct {

// check default ignores that only apply to the root project directory
for (root_default_ignore_patterns) |pattern| {
switch (glob.matchImpl(pattern, entry_name)) {
switch (glob.walk.matchImpl(pattern, entry_name)) {
.match => {
// cannot be reversed
return .{
Expand All @@ -1003,7 +1003,7 @@ pub const PackCommand = struct {

for (default_ignore_patterns) |pattern_info| {
const pattern, const can_override = pattern_info;
switch (glob.matchImpl(pattern, entry_name)) {
switch (glob.walk.matchImpl(pattern, entry_name)) {
.match => {
if (can_override) {
ignored = true;
Expand Down Expand Up @@ -1045,7 +1045,7 @@ pub const PackCommand = struct {
if (pattern.dirs_only and entry.kind != .directory) continue;

const match_path = if (pattern.rel_path) rel else entry_name;
switch (glob.matchImpl(pattern.glob, match_path)) {
switch (glob.walk.matchImpl(pattern.glob, match_path)) {
.match => {
ignored = true;
ignore_pattern = pattern.glob;
Expand Down
Loading