@@ -97,6 +97,10 @@ owned_link_dir: ?std.fs.Dir,
97
97
/// Don't use this for anything other than stage1 compatibility.
98
98
color : @import ("main.zig" ).Color = .Auto ,
99
99
100
+ test_filter : ? []const u8 ,
101
+ test_name_prefix : ? []const u8 ,
102
+ test_evented_io : bool ,
103
+
100
104
pub const InnerError = Module .InnerError ;
101
105
102
106
pub const CRTFile = struct {
@@ -327,6 +331,9 @@ pub const InitOptions = struct {
327
331
machine_code_model : std.builtin.CodeModel = .default ,
328
332
/// This is for stage1 and should be deleted upon completion of self-hosting.
329
333
color : @import ("main.zig" ).Color = .Auto ,
334
+ test_filter : ? []const u8 = null ,
335
+ test_name_prefix : ? []const u8 = null ,
336
+ test_evented_io : bool = false ,
330
337
};
331
338
332
339
pub fn create (gpa : * Allocator , options : InitOptions ) ! * Compilation {
@@ -554,6 +561,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
554
561
hash .add (single_threaded );
555
562
hash .add (options .target .os .getVersionRange ());
556
563
hash .add (dll_export_fns );
564
+ hash .add (options .is_test );
557
565
558
566
const digest = hash .final ();
559
567
const artifact_sub_dir = try std .fs .path .join (arena , &[_ ][]const u8 { "o" , & digest });
@@ -728,6 +736,9 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
728
736
.is_test = options .is_test ,
729
737
.color = options .color ,
730
738
.time_report = options .time_report ,
739
+ .test_filter = options .test_filter ,
740
+ .test_name_prefix = options .test_name_prefix ,
741
+ .test_evented_io = options .test_evented_io ,
731
742
};
732
743
break :comp comp ;
733
744
};
@@ -1996,6 +2007,25 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8
1996
2007
comp .bin_file .options .strip ,
1997
2008
@tagName (comp .bin_file .options .machine_code_model ),
1998
2009
});
2010
+
2011
+ if (comp .is_test ) {
2012
+ try buffer .appendSlice (
2013
+ \\pub var test_functions: []TestFn = undefined; // overwritten later
2014
+ \\
2015
+ );
2016
+ if (comp .test_evented_io ) {
2017
+ try buffer .appendSlice (
2018
+ \\pub const test_io_mode = .evented;
2019
+ \\
2020
+ );
2021
+ } else {
2022
+ try buffer .appendSlice (
2023
+ \\pub const test_io_mode = .blocking;
2024
+ \\
2025
+ );
2026
+ }
2027
+ }
2028
+
1999
2029
return buffer .toOwnedSlice ();
2000
2030
}
2001
2031
@@ -2129,6 +2159,7 @@ fn updateStage1Module(comp: *Compilation) !void {
2129
2159
ch .hash .add (target .os .getVersionRange ());
2130
2160
ch .hash .add (comp .bin_file .options .dll_export_fns );
2131
2161
ch .hash .add (comp .bin_file .options .function_sections );
2162
+ ch .hash .add (comp .is_test );
2132
2163
2133
2164
if (try ch .hit ()) {
2134
2165
const digest = ch .final ();
@@ -2155,7 +2186,7 @@ fn updateStage1Module(comp: *Compilation) !void {
2155
2186
.llvm_cpu_features = comp .bin_file .options .llvm_cpu_features .? ,
2156
2187
};
2157
2188
var progress : std.Progress = .{};
2158
- var main_progress_node = try progress .start ("" , 100 );
2189
+ var main_progress_node = try progress .start ("" , null );
2159
2190
defer main_progress_node .end ();
2160
2191
if (comp .color == .Off ) progress .terminal = null ;
2161
2192
@@ -2184,17 +2215,19 @@ fn updateStage1Module(comp: *Compilation) !void {
2184
2215
.parent = null ,
2185
2216
};
2186
2217
const output_dir = comp .bin_file .options .directory .path orelse "." ;
2218
+ const test_filter = comp .test_filter orelse "" [0.. 0];
2219
+ const test_name_prefix = comp .test_name_prefix orelse "" [0.. 0];
2187
2220
stage1_module .* = .{
2188
2221
.root_name_ptr = comp .bin_file .options .root_name .ptr ,
2189
2222
.root_name_len = comp .bin_file .options .root_name .len ,
2190
2223
.output_dir_ptr = output_dir .ptr ,
2191
2224
.output_dir_len = output_dir .len ,
2192
2225
.builtin_zig_path_ptr = builtin_zig_path .ptr ,
2193
2226
.builtin_zig_path_len = builtin_zig_path .len ,
2194
- .test_filter_ptr = "" ,
2195
- .test_filter_len = 0 ,
2196
- .test_name_prefix_ptr = "" ,
2197
- .test_name_prefix_len = 0 ,
2227
+ .test_filter_ptr = test_filter . ptr ,
2228
+ .test_filter_len = test_filter . len ,
2229
+ .test_name_prefix_ptr = test_name_prefix . ptr ,
2230
+ .test_name_prefix_len = test_name_prefix . len ,
2198
2231
.userdata = @ptrToInt (comp ),
2199
2232
.root_pkg = stage1_pkg ,
2200
2233
.code_model = @enumToInt (comp .bin_file .options .machine_code_model ),
@@ -2217,7 +2250,7 @@ fn updateStage1Module(comp: *Compilation) !void {
2217
2250
.emit_bin = true ,
2218
2251
.emit_asm = false ,
2219
2252
.emit_llvm_ir = false ,
2220
- .test_is_evented = false ,
2253
+ .test_is_evented = comp . test_evented_io ,
2221
2254
.verbose_tokenize = comp .verbose_tokenize ,
2222
2255
.verbose_ast = comp .verbose_ast ,
2223
2256
.verbose_ir = comp .verbose_ir ,
0 commit comments