All Projects → google → Resumable Assert

google / Resumable Assert

Licence: apache-2.0
Assert replacement to continue execution in debugger

Programming Languages

c
50402 projects - #5 most used programming language
swift
15916 projects

Labels

Projects that are alternatives of or similar to Resumable Assert

assert-true
A lot of ways to you set your assert as true
Stars: ✭ 19 (-87.9%)
Mutual labels:  assert
Static Assertions Rs
Ensure correct assumptions about constants, types, and more in Rust
Stars: ✭ 363 (+131.21%)
Mutual labels:  assert
Testify
A unit testing framework written in bash for bash scripts
Stars: ✭ 45 (-71.34%)
Mutual labels:  assert
openapi-assert
Asserting data against OpenAPI docs.
Stars: ✭ 17 (-89.17%)
Mutual labels:  assert
Strikt
An assertion library for Kotlin
Stars: ✭ 310 (+97.45%)
Mutual labels:  assert
Validator.js
⁉️轻量级的 JavaScript 表单验证,字符串验证。没有依赖,支持 UMD ,~3kb。
Stars: ✭ 486 (+209.55%)
Mutual labels:  assert
got
An enjoyable golang test framework.
Stars: ✭ 234 (+49.04%)
Mutual labels:  assert
Gopwt
PowerAssert library for golang
Stars: ✭ 137 (-12.74%)
Mutual labels:  assert
Atrium
A multiplatform assertion library for Kotlin
Stars: ✭ 359 (+128.66%)
Mutual labels:  assert
Regex Assert Symfony
Common Regex to use with Assert in Symfony's entity
Stars: ✭ 5 (-96.82%)
Mutual labels:  assert
underscore.haz
🔍 _.haz() is like _.has() but this underscore and/or lodash mixin lets you do deep object key existence checking with a dot denoted string, for example 'a.b.c'
Stars: ✭ 13 (-91.72%)
Mutual labels:  assert
Commonjs Assert
Node.js's require('assert') for all engines
Stars: ✭ 255 (+62.42%)
Mutual labels:  assert
Node Deep Equal
node's assert.deepEqual algorithm
Stars: ✭ 577 (+267.52%)
Mutual labels:  assert
php-assert
Fast flexible php assert
Stars: ✭ 18 (-88.54%)
Mutual labels:  assert
Assert
A collection of convenient assertions for Swift testing
Stars: ✭ 69 (-56.05%)
Mutual labels:  assert
earl
☕ Ergonomic, modern and type-safe assertion library for TypeScript
Stars: ✭ 217 (+38.22%)
Mutual labels:  assert
Ava
Node.js test runner that lets you develop with confidence 🚀
Stars: ✭ 19,458 (+12293.63%)
Mutual labels:  assert
Earl
☕ Ergonomic, modern and type-safe assertion library for TypeScript
Stars: ✭ 153 (-2.55%)
Mutual labels:  assert
Expect More
Curried Type Testing library, and Test Matchers for Jest
Stars: ✭ 124 (-21.02%)
Mutual labels:  assert
Baloo
Expressive end-to-end HTTP API testing made easy in Go
Stars: ✭ 702 (+347.13%)
Mutual labels:  assert

Apache License

Resumable Assert

Assert replacement to continue execution in debugger

In any large app, it sometimes happens that some asserts are failing in code you don't currently care about, and blocking the entire team from being able to run the app until the issue is fixed is not the best workflow. So we usually end up moving the execution marker past the assert line in IDE or debugger, or even comment the assert out, recompile and relaunch. With Resumable Assert, you can simply continue execution when an assertion fails in debugger, or even disable asserts that you are not interested in, so that those never bother you again.

Disclaimer: be careful with that power though, since execution of potentially broken code may lead to unrecoverable errors in future.

C/C++/Objective-C

First, include or import the header:

#import "ResumableAssert.h"

Then, use the RESUMABLE_ASSERT() or RESUMABLE_ASSERT_WITH_FORMAT() macros instead of the standard ones: assert(), NSAssert(), etc.

Once RESUMABLE_ASSERT() variant is hit in debug mode, you can ignore it and continue execution, or disable it permanently, or even disable all asserts permanently with corresponding lldb commands when prompted.

For example, the following assert somewhere in ViewController.viewDidLoad method:

RESUMABLE_ASSERT(2 + 2 == 5);

Or:

RESUMABLE_ASSERT_WITH_FORMAT(2 + 2 == 5, "Calculation error");

Leads to the following debugger console output:

ViewController.m:-[ViewController viewDidLoad]:42
Assertion failed: 2 + 2 == 5
Calculation error
Continue execution or issue one of the following lldb commands:
e disable = 1  # disable this assert permanently
e unleash = 1  # disable all asserts permanently

Where you can just continue execution, or additionally disable the assert:

(lldb) e disable = 1
(volatile int) $1 = 1
(lldb) c
Process 11193 resuming

Custom logging

RESUMABLE_ASSERT() macro in C uses stdout to print the failure message by default. To change this behavior and use something else for logging, (e.g. NSLog()) redefine the RESUMABLE_ASSERT_LOG() macro in C like so:

#import <Foundation/Foundation.h>

#include "ResumableAssert.h"

#undef RESUMABLE_ASSERT_LOG
#define RESUMABLE_ASSERT_LOG(condition, format, ...)                 \
  do {                                                               \
    NSLog(@"%s:%u\nAssertion failed: %s\n" format,                   \
          __PRETTY_FUNCTION__, __LINE__, condition, ##__VA_ARGS__);  \
  } while (0)

Similarly, you can define your own assert macro with a custom name:

#define ASSERT_WITH_FORMAT(condition, format, ...) \
  RESUMABLE_ASSERT_WITH_FORMAT(condition, format, ##__VA_ARGS__)
#define ASSERT(condition) ASSERT_WITH_FORMAT(condition, "")

Swift

For Swift and other languages, we provide ResumableAssertDebugTrap() function that implements the core logic of resumable assert. You can then implement a custom assert() function somewhere in a custom Diagnostics module which would use ResumableAssertDebugTrap() internally:

import ResumableAssert // Import the module or use a bridging header and import ResumableAssert.h.

public func assert(
  _ condition: @autoclosure () -> Bool,
  _ message: @autoclosure () -> String = "",
  file: StaticString = #file,
  function: StaticString = #function,
  line: UInt = #line
) {
#ifdef DEBUG
  if !condition() {
    NSLog("Assertion failed:" + " \(message()):" +
          " file \(file.description), function \(function.description), line \(line)")
    ResumableAssertDebugTrap()
  }
#endif
}

Then, you can use the new function as:

Diagnostics.assert(2 + 2 == 5, "Calculation error")

Setup

Bazel

In your BUILD file, add ResumableAssert deps to corresponding targets:

objc_library(
  # ...
  deps = [
    "//path/to/ResumableAssert",
  ],
  # ...
)

Include or import the header:

#import "path/to/ResumableAssert/ResumableAssert.h"

CocoaPods

To use ResumableAssert for Objective-C, add the following to your Podfile:

pod 'ResumableAssert', '~> 1.0'

Then, run pod install and import the umbrella header in generated project:

#import <ResumableAssert/ResumableAssert.h>

Or, the module:

@import ResumableAssert;
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].