1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! Bug reproducer: `SmokeModuleTest::form()` must wrap code lacking `fn main()`.
//!
//! # Root Cause
//!
//! `SmokeModuleTest::form()` wrote user-provided code to `main.rs` without ensuring
//! a `fn main()` entry point existed. When the user code contained only `use` statements
//! or expressions (no `fn main()`), `cargo build` failed with E0601:
//! "main function not found in crate".
//!
//! The root cause was an implicit assumption in the `else` branch: the branch assumed
//! user-provided code always contained `fn main()`. In practice, code snippets — simple
//! `use` statements, standalone expressions, or import-only code — are valid test inputs
//! that lack a main entry point.
//!
//! # Why Not Caught
//!
//! Existing tests used code snippets that either:
//! 1. Included an explicit `fn main()` block, or
//! 2. Used the empty-code path (which auto-generates `fn main() { use ...; }`)
//!
//! The case of non-empty user code without `fn main()` was not tested. Edge case tests
//! existed in `smoke_test_edge_cases.rs` but did not verify that `form()` added a wrapper.
//!
//! # Fix Applied
//!
//! Added a third branch in `SmokeModuleTest::form()` (in `src/test/smoke_test.rs`):
//! when user code is non-empty AND does not contain `fn main()`, the code is wrapped in
//! `fn main() { ... }` to produce a valid binary entry point.
//!
//! ```text
//! if self.code.is_empty() → auto-generate with use statement
//! else if code.contains("fn main") → use as-is (no double-wrap)
//! else → wrap in `fn main() { ... }` ← FIX
//! ```
//!
//! # Prevention
//!
//! This test suite verifies all three branches of the code generation logic
//! in `form()`. Any future change to the code generation path must keep all
//! three variants passing.
//!
//! # Pitfall to Avoid
//!
//! Do not assume that user-provided test code always has an entry point.
//! Code snippets (use statements, expressions, struct declarations) are valid
//! smoke test inputs. The `form()` method is responsible for producing compilable
//! code regardless of user input — users should not need to add boilerplate.
// test_kind: bug_reproducer(issue-smoke-form-missing-main)
use SmokeModuleTest;
/// Verify: code without `fn main()` gets wrapped in `fn main()` by `form()`.
///
/// This is the primary bug reproducer. Before the fix, a `use` statement
/// without a wrapping `fn main()` caused E0601 at cargo build time.
/// Verify: code with `fn main()` is NOT double-wrapped.
///
/// Regression guard: wrapping code that already has `fn main()` would produce
/// E0201 (duplicate main) or `dead_code` warnings.
/// Verify: empty code path still generates auto `fn main()` with use statement.
///
/// Baseline: the original empty-code path must remain unaffected by the fix.