Skip to content

Commit b7e9813

Browse files
cameroncookecodex
andcommitted
test(snapshot): Avoid mutating example app sources
Trigger compiler-error snapshot cases with a guarded Swift compile flag instead of patching example project files during test execution. This keeps snapshot tests deterministic and avoids leaving tracked source files corrupted if a run is interrupted. Refs GH-387 Co-Authored-By: Codex <codex@openai.com>
1 parent 9c162ac commit b7e9813

33 files changed

Lines changed: 98 additions & 136 deletions

example_projects/iOS_Calculator/CalculatorApp/CalculatorApp.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ struct CalculatorApp: App {
2828
#Preview {
2929
ContentView()
3030
}
31+
32+
#if SNAPSHOT_COMPILER_ERROR
33+
private let snapshotCompilerError: Int = "not an int"
34+
#endif

example_projects/macOS/MCPTest/MCPTestApp.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ struct MCPTestApp: App {
1515
}
1616
}
1717
}
18+
19+
#if SNAPSHOT_COMPILER_ERROR
20+
private let snapshotCompilerError: Int = "not an int"
21+
#endif

src/snapshot-tests/__fixtures__/cli/device/build--error-compiler.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Compiler Errors (1):
1111

1212
✗ cannot convert value of type 'String' to specified type 'Int'
13-
example_projects/iOS_Calculator/CalculatorApp/CalculatorApp.swift:32:42
13+
example_projects/iOS_Calculator/CalculatorApp/CalculatorApp.swift:33:42
1414

1515
❌ Build failed. (⏱️ <DURATION>)
1616
└ Build Logs: <HOME>/Library/Developer/XcodeBuildMCP/logs/build_device_<TIMESTAMP>_pid<PID>.log

src/snapshot-tests/__fixtures__/cli/device/build-and-run--error-compiler.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Compiler Errors (1):
1212

1313
✗ cannot convert value of type 'String' to specified type 'Int'
14-
example_projects/iOS_Calculator/CalculatorApp/CalculatorApp.swift:32:42
14+
example_projects/iOS_Calculator/CalculatorApp/CalculatorApp.swift:33:42
1515

1616
❌ Build failed. (⏱️ <DURATION>)
1717
└ Build Logs: <HOME>/Library/Developer/XcodeBuildMCP/logs/build_run_device_<TIMESTAMP>_pid<PID>.log

src/snapshot-tests/__fixtures__/cli/device/test--error-compiler.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Discovered 1 test(s):
1616
Compiler Errors (1):
1717

1818
✗ cannot convert value of type 'String' to specified type 'Int'
19-
example_projects/iOS_Calculator/CalculatorApp/CalculatorApp.swift:32:42
19+
example_projects/iOS_Calculator/CalculatorApp/CalculatorApp.swift:33:42
2020

2121
❌ Test failed. (⏱️ <DURATION>)
2222
└ Build Logs: <HOME>/Library/Developer/XcodeBuildMCP/logs/test_device_<TIMESTAMP>_pid<PID>.log

src/snapshot-tests/__fixtures__/cli/macos/build--error-compiler.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Compiler Errors (1):
1111

1212
✗ cannot convert value of type 'String' to specified type 'Int'
13-
example_projects/macOS/MCPTest/MCPTestApp.swift:19:42
13+
example_projects/macOS/MCPTest/MCPTestApp.swift:20:42
1414

1515
❌ Build failed. (⏱️ <DURATION>)
1616
└ Build Logs: <HOME>/Library/Developer/XcodeBuildMCP/logs/build_macos_<TIMESTAMP>_pid<PID>.log

src/snapshot-tests/__fixtures__/cli/macos/build-and-run--error-compiler.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Compiler Errors (1):
1111

1212
✗ cannot convert value of type 'String' to specified type 'Int'
13-
example_projects/macOS/MCPTest/MCPTestApp.swift:19:42
13+
example_projects/macOS/MCPTest/MCPTestApp.swift:20:42
1414

1515
❌ Build failed. (⏱️ <DURATION>)
1616
└ Build Logs: <HOME>/Library/Developer/XcodeBuildMCP/logs/build_run_macos_<TIMESTAMP>_pid<PID>.log

src/snapshot-tests/__fixtures__/cli/macos/test--error-compiler.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Discovered 2 test(s):
1717
Compiler Errors (1):
1818

1919
✗ cannot convert value of type 'String' to specified type 'Int'
20-
example_projects/macOS/MCPTest/MCPTestApp.swift:19:42
20+
example_projects/macOS/MCPTest/MCPTestApp.swift:20:42
2121

2222
❌ Test failed. (⏱️ <DURATION>)
2323
└ Build Logs: <HOME>/Library/Developer/XcodeBuildMCP/logs/test_macos_<TIMESTAMP>_pid<PID>.log

src/snapshot-tests/__fixtures__/cli/simulator/build--error-compiler.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Compiler Errors (1):
1212

1313
✗ cannot convert value of type 'String' to specified type 'Int'
14-
example_projects/iOS_Calculator/CalculatorApp/CalculatorApp.swift:32:42
14+
example_projects/iOS_Calculator/CalculatorApp/CalculatorApp.swift:33:42
1515

1616
❌ Build failed. (⏱️ <DURATION>)
1717
└ Build Logs: <HOME>/Library/Developer/XcodeBuildMCP/logs/build_sim_<TIMESTAMP>_pid<PID>.log

src/snapshot-tests/__fixtures__/cli/simulator/build-and-run--error-compiler.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Compiler Errors (1):
1212

1313
✗ cannot convert value of type 'String' to specified type 'Int'
14-
example_projects/iOS_Calculator/CalculatorApp/CalculatorApp.swift:32:42
14+
example_projects/iOS_Calculator/CalculatorApp/CalculatorApp.swift:33:42
1515

1616
❌ Build failed. (⏱️ <DURATION>)
1717
└ Build Logs: <HOME>/Library/Developer/XcodeBuildMCP/logs/build_run_sim_<TIMESTAMP>_pid<PID>.log

0 commit comments

Comments
 (0)