Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 20 additions & 2 deletions src/cli/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1681,10 +1681,28 @@ pub fn setupSharedMemoryWithModuleEnv(allocs: *Allocators, roc_file_path: []cons
app_env.module_name = app_module_name;
try app_env.common.calcLineStarts(shm_allocator);

var error_count: usize = 0;

var app_parse_ast = try parse.parse(&app_env.common, allocs.gpa);
defer app_parse_ast.deinit(allocs.gpa);
app_parse_ast.store.emptyScratch();
if (app_parse_ast.hasErrors()) {
const stderr = stderrWriter();
defer stderr.flush() catch {};
for (app_parse_ast.tokenize_diagnostics.items) |diagnostic| {
error_count += 1;
var report = app_parse_ast.tokenizeDiagnosticToReport(diagnostic, allocs.gpa, roc_file_path) catch continue;
defer report.deinit();
reporting.renderReportToTerminal(&report, stderr, ColorPalette.ANSI, reporting.ReportingConfig.initColorTerminal()) catch continue;
}
for (app_parse_ast.parse_diagnostics.items) |diagnostic| {
error_count += 1;
var report = app_parse_ast.parseDiagnosticToReport(&app_env.common, diagnostic, allocs.gpa, roc_file_path) catch continue;
defer report.deinit();
reporting.renderReportToTerminal(&report, stderr, ColorPalette.ANSI, reporting.ReportingConfig.initColorTerminal()) catch continue;
}
}

app_parse_ast.store.emptyScratch();
try app_env.initCIRFields(app_module_name);

var app_module_envs_map = std.AutoHashMap(base.Ident.Idx, Can.AutoImportedType).init(allocs.gpa);
Expand Down Expand Up @@ -1840,7 +1858,7 @@ pub fn setupSharedMemoryWithModuleEnv(allocs: *Allocators, roc_file_path: []cons
// Render all type problems (errors and warnings) exactly as roc check would
// Count errors so the caller can decide whether to proceed with execution
// Skip rendering in test mode to avoid polluting test output
const error_count = if (!builtin.is_test)
error_count += if (!builtin.is_test)
renderTypeProblems(allocs.gpa, &app_checker, &app_env, roc_file_path)
else
0;
Expand Down
27 changes: 25 additions & 2 deletions src/cli/test/fx_platform_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ test "fx platform issue8433" {
}
}

test "run aborts on errors by default" {
test "run aborts on type errors by default" {
// Tests that roc run aborts when there are type errors (without --allow-errors)
const allocator = testing.allocator;

Expand All @@ -1482,7 +1482,30 @@ test "run aborts on errors by default" {
try testing.expect(std.mem.indexOf(u8, run_result.stderr, "UNDEFINED VARIABLE") != null);
}

test "run with --allow-errors attempts execution despite errors" {
test "run aborts on parse errors by default" {
// Tests that roc run aborts when there are parse errors (without --allow-errors)
const allocator = testing.allocator;

try ensureRocBinary(allocator);

const run_result = try std.process.Child.run(.{
.allocator = allocator,
.argv = &[_][]const u8{
"./zig-out/bin/roc",
"test/fx/parse_error.roc",
},
});
defer allocator.free(run_result.stdout);
defer allocator.free(run_result.stderr);

// Should fail with type errors
try checkFailure(run_result);

// Should show the errors
try testing.expect(std.mem.indexOf(u8, run_result.stderr, "PARSE ERROR") != null);
}

test "run with --allow-errors attempts execution despite type errors" {
// Tests that roc run --allow-errors attempts to execute even with type errors
const allocator = testing.allocator;

Expand Down
8 changes: 8 additions & 0 deletions test/fx/parse_error.roc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
app [main!] {
pf: platform "./platform/main.roc",
}
import pf.Stdout
main! = |_args| {
Stdout.line!("Hello world")
Ok({})
}}