Skip to content

Instantly share code, notes, and snippets.

@erica
Created March 20, 2018 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erica/27fe5d738d9f1698b1773f18ff99141e to your computer and use it in GitHub Desktop.
Save erica/27fe5d738d9f1698b1773f18ff99141e to your computer and use it in GitHub Desktop.
% cat testAssertConfigurations.swift
// Test compilation with -O, -Onone, and -Ounchecked
print("Starting tests")
#if optimization(enabled)
print("asserts will not fire. optimized")
#else
print("asserts will fire. unoptimized/debug")
#endif
#if !optimization(enabled)
print("asserts will fire. unoptimized/debug")
#else
print("asserts will not fire. optimized")
#endif
print("Ending tests")
% ./swift testAssertConfigurations.swift
Starting tests
asserts will fire. unoptimized/debug
asserts will fire. unoptimized/debug
Ending tests
% ./swift -O testAssertConfigurations.swift
Starting tests
asserts will not fire. optimized
asserts will not fire. optimized
Ending tests
% ./swift -Onone testAssertConfigurations.swift
Starting tests
asserts will fire. unoptimized/debug
asserts will fire. unoptimized/debug
Ending tests
% ./swift -Ounchecked testAssertConfigurations.swift
Starting tests
asserts will not fire. optimized
asserts will not fire. optimized
Ending tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment