uber / mockolo

Efficient Mock Generator for Swift
Apache License 2.0
805 stars 85 forks source link

Report error when fails to write mock file #193

Closed maiyama18 closed 2 years ago

maiyama18 commented 2 years ago

Close #189

This PR makes mockolo command report error in log message and finish with non-zero exit code when it fails to create mock file. Change of the log message for that situation is shown below.

before

❯ mockolo --sourcedirs Path/To/SourceDir --destination /NonexistentDirectory/Mocks.swift
Start...
["Process input mock files..."]
["Took", 4.1961669921875e-05]
["Process source files and generate an annotated/protocol map..."]
["Took", 0.023231029510498047]
["Resolve inheritance and generate unique entity models..."]
["Took", 0.0008450746536254883]
["Render models with templates..."]
["Took", 0.0002319812774658203]
["Write the mock results and import lines to", "/NonexistentDirectory/Mocks.swift"]
["Took", 0.0001609325408935547]
["TOTAL", 0.024510979652404785]
["#Protocols = 3, #Annotated protocols = 3, #Parent mock classes = 0, #Final mock classes = 3, File LoC = 77"]
["Done. Exiting program."]
Done.

after

❯ mockolo --sourcedirs Path/To/SourceDir --destination /NonexistentDirectory/Mocks.swift
Start...
["Process input mock files..."]
["Took", 6.496906280517578e-05]
["Process source files and generate an annotated/protocol map..."]
["Took", 0.07189595699310303]
["Resolve inheritance and generate unique entity models..."]
["Took", 7.808208465576172e-05]
["Render models with templates..."]
["Took", 9.894371032714844e-06]
["Write the mock results and import lines to", "/NonexistentDirectory/Mocks.swift"]
Mockolo/Executor.swift:213: Fatal error: Generation error: Error Domain=NSCocoaErrorDomain Code=4 "The folder “Mocks.swift” doesn’t exist." UserInfo={NSFilePath=/NonexistentDirectory/Mocks.swift, NSUserStringVariant=Folder, NSUnderlyingError=0x600003ce90e0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
zsh: trace trap  .build/arm64-apple-macosx/debug/mockolo --sourcedirs Sources --destination
CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.