{"id":151646,"date":"2025-03-23T12:34:45","date_gmt":"2025-03-23T12:34:45","guid":{"rendered":"https:\/\/peraltafinancing.com\/apple-2\/michael-tsai-blog-swift-testing-proposal-exit-tests\/"},"modified":"2025-03-23T12:34:45","modified_gmt":"2025-03-23T12:34:45","slug":"michael-tsai-blog-swift-testing-proposal-exit-tests","status":"publish","type":"post","link":"https:\/\/fivemor.com\/?p=151646","title":{"rendered":"Michael Tsai &#8211; Blog &#8211; Swift Testing Proposal: Exit Tests"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<p><a href=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/testing\/0008-exit-tests.md\">ST-0008<\/a>:<\/p>\n<blockquote cite=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/testing\/0008-exit-tests.md\">\n<p>One of the first enhancement requests we received for Swift Testing was the ability to test for precondition failures and other critical failures that terminate the current process when they occur.<\/p>\n<p>[\u2026]<\/p>\n<p>This proposal introduces new overloads of the <code>#expect()<\/code> and <code>#require()<\/code><br \/>\nmacros that take, as an argument, a closure to be executed in a child process.<br \/>\nWhen called, these macros spawn a new process using the relevant<br \/>\nplatform-specific interface (<code>posix_spawn()<\/code>, <code>CreateProcessW()<\/code>, etc.), call<br \/>\nthe closure from within that process, and suspend the caller until that process<br \/>\nterminates. The exit status of the process is then compared against a known<br \/>\nvalue passed to the macro, allowing the test to pass or fail as appropriate.<\/p>\n<\/blockquote>\n<p>I had heard talk about changing the behavior of preconditions and assertions during tests so that they would signal back to the testing system instead of actually terminating the process. This is a much more ambitious solution and should be more widely useful. For example, I\u2019ve written tests to reproduce crashes that are triggered by a bug, but I can\u2019t leave these enabled with XCTest because they\u2019ll crash the whole testing system.<\/p>\n<blockquote cite=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/testing\/0008-exit-tests.md\">\n<p>Exit tests cannot capture any state originating in the parent process or from the enclosing lexical context.<\/p>\n<\/blockquote>\n<p>This is an unsurprising limitation. I\u2019m guessing that it won\u2019t be much of a problem, but I\u2019m not sure without trying it.<\/p>\n<blockquote cite=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/testing\/0008-exit-tests.md\">\n<p>It is often interesting to examine what is written to the standard output and<br \/>\nstandard error streams by code running in an exit test. Callers can request that<br \/>\neither or both stream be captured and included in the result of the call to<br \/>\n<code>#expect(exitsWith:)<\/code> or <code>#require(exitsWith:)<\/code>.<\/p>\n<p>[\u2026]<\/p>\n<p>The technical constraints preventing recursive exit test invocation can be resolved if there is a need to do so. However, we don&#8217;t anticipate that this constraint will be a serious issue for developers.<\/p>\n<\/blockquote>\n<p>Previously:<\/p>\n<p class=\"tags\"><a rel=\"tag\" href=\"https:\/\/mjtsai.com\/blog\/tag\/languagedesign\/\">Language Design<\/a> <a rel=\"tag\" href=\"https:\/\/mjtsai.com\/blog\/tag\/programming\/\">Programming<\/a> <a rel=\"tag\" href=\"https:\/\/mjtsai.com\/blog\/tag\/swift-programming-language\/\">Swift Programming Language<\/a> <a rel=\"tag\" href=\"https:\/\/mjtsai.com\/blog\/tag\/testing\/\">Testing<\/a><\/p>\n<h2><a id=\"respond\"><\/a><br \/>\nComments<br \/>\n <\/h2>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>ST-0008: One of the first enhancement requests we received for Swift Testing was the ability to test for precondition failures and other critical failures that terminate the current process when they occur. [\u2026] This proposal introduces new overloads of the #expect() and #require() macros that take, as an argument, a closure to be executed in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11768],"tags":[3767,13646,1823,2596,11592,12632,11326,17088],"dealstore":[],"offerexpiration":[],"class_list":["post-151646","post","type-post","status-publish","format-standard","hentry","category-apple-2","tag-blog","tag-exit","tag-michael","tag-proposal","tag-swift","tag-testing","tag-tests","tag-tsai"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Michael Tsai - Blog - Swift Testing Proposal: Exit Tests - Som2ny Network<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fivemor.com\/?p=151646\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Michael Tsai - Blog - Swift Testing Proposal: Exit Tests - Som2ny Network\" \/>\n<meta property=\"og:description\" content=\"ST-0008: One of the first enhancement requests we received for Swift Testing was the ability to test for precondition failures and other critical failures that terminate the current process when they occur. [\u2026] This proposal introduces new overloads of the #expect() and #require() macros that take, as an argument, a closure to be executed in [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fivemor.com\/?p=151646\" \/>\n<meta property=\"og:site_name\" content=\"Som2ny Network\" \/>\n<meta property=\"article:published_time\" content=\"2025-03-23T12:34:45+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/fivemor.com\/?p=151646#article\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/?p=151646\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\"},\"headline\":\"Michael Tsai &#8211; Blog &#8211; Swift Testing Proposal: Exit Tests\",\"datePublished\":\"2025-03-23T12:34:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=151646\"},\"wordCount\":326,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"keywords\":[\"Blog\",\"Exit\",\"Michael\",\"Proposal\",\"Swift\",\"Testing\",\"tests\",\"Tsai\"],\"articleSection\":[\"Apple\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fivemor.com\/?p=151646#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fivemor.com\/?p=151646\",\"url\":\"https:\/\/fivemor.com\/?p=151646\",\"name\":\"Michael Tsai - Blog - Swift Testing Proposal: Exit Tests - Som2ny Network\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/#website\"},\"datePublished\":\"2025-03-23T12:34:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fivemor.com\/?p=151646#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fivemor.com\/?p=151646\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fivemor.com\/?p=151646#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fivemor.com\/?bp_activities=1\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Michael Tsai &#8211; Blog &#8211; Swift Testing Proposal: Exit Tests\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/fivemor.com\/#website\",\"url\":\"https:\/\/fivemor.com\/\",\"name\":\"Som2ny Network\",\"description\":\"Daily Deals\",\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/fivemor.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/fivemor.com\/#organization\",\"name\":\"Som2ny Network\",\"url\":\"https:\/\/fivemor.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"width\":300,\"height\":86,\"caption\":\"Som2ny Network\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/fivemor.com\"],\"url\":\"https:\/\/fivemor.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Michael Tsai - Blog - Swift Testing Proposal: Exit Tests - Som2ny Network","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fivemor.com\/?p=151646","og_locale":"en_US","og_type":"article","og_title":"Michael Tsai - Blog - Swift Testing Proposal: Exit Tests - Som2ny Network","og_description":"ST-0008: One of the first enhancement requests we received for Swift Testing was the ability to test for precondition failures and other critical failures that terminate the current process when they occur. [\u2026] This proposal introduces new overloads of the #expect() and #require() macros that take, as an argument, a closure to be executed in [&hellip;]","og_url":"https:\/\/fivemor.com\/?p=151646","og_site_name":"Som2ny Network","article_published_time":"2025-03-23T12:34:45+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fivemor.com\/?p=151646#article","isPartOf":{"@id":"https:\/\/fivemor.com\/?p=151646"},"author":{"name":"admin","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371"},"headline":"Michael Tsai &#8211; Blog &#8211; Swift Testing Proposal: Exit Tests","datePublished":"2025-03-23T12:34:45+00:00","mainEntityOfPage":{"@id":"https:\/\/fivemor.com\/?p=151646"},"wordCount":326,"commentCount":0,"publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"keywords":["Blog","Exit","Michael","Proposal","Swift","Testing","tests","Tsai"],"articleSection":["Apple"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fivemor.com\/?p=151646#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fivemor.com\/?p=151646","url":"https:\/\/fivemor.com\/?p=151646","name":"Michael Tsai - Blog - Swift Testing Proposal: Exit Tests - Som2ny Network","isPartOf":{"@id":"https:\/\/fivemor.com\/#website"},"datePublished":"2025-03-23T12:34:45+00:00","breadcrumb":{"@id":"https:\/\/fivemor.com\/?p=151646#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fivemor.com\/?p=151646"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/fivemor.com\/?p=151646#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fivemor.com\/?bp_activities=1"},{"@type":"ListItem","position":2,"name":"Michael Tsai &#8211; Blog &#8211; Swift Testing Proposal: Exit Tests"}]},{"@type":"WebSite","@id":"https:\/\/fivemor.com\/#website","url":"https:\/\/fivemor.com\/","name":"Som2ny Network","description":"Daily Deals","publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fivemor.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fivemor.com\/#organization","name":"Som2ny Network","url":"https:\/\/fivemor.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","width":300,"height":86,"caption":"Som2ny Network"},"image":{"@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","caption":"admin"},"sameAs":["https:\/\/fivemor.com"],"url":"https:\/\/fivemor.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/151646","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=151646"}],"version-history":[{"count":0,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/151646\/revisions"}],"wp:attachment":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=151646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=151646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=151646"},{"taxonomy":"dealstore","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdealstore&post=151646"},{"taxonomy":"offerexpiration","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fofferexpiration&post=151646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}