
org.scalatest.AssertionsMacro.scala Maven / Gradle / Ivy
/*
* Copyright 2001-2012 Artima, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.scalatest
import org.scalactic.BooleanMacro
import reflect.macros.Context
/**
* Macro implementation that provides rich error message for boolean expression assertion.
*/
private[scalatest] object AssertionsMacro {
/**
* Provides assertion implementation for Assertions.assert(booleanExpr: Boolean)
, with rich error message.
*
* @param context macro context
* @param condition original condition expression
* @return transformed expression that performs the assertion check and throw TestFailedException
with rich error message if assertion failed
*/
def assert(context: Context)(condition: context.Expr[Boolean]): context.Expr[Assertion] =
new BooleanMacro[context.type](context, "assertionsHelper").genMacro[Assertion](condition, "macroAssert", context.literal(""))
/**
* Provides assertion implementation for Assertions.assert(booleanExpr: Boolean, clue: Any)
, with rich error message.
*
* @param context macro context
* @param condition original condition expression
* @param clue original clue expression
* @return transformed expression that performs the assertion check and throw TestFailedException
with rich error message (clue included) if assertion failed
*/
def assertWithClue(context: Context)(condition: context.Expr[Boolean], clue: context.Expr[Any]): context.Expr[Assertion] =
new BooleanMacro[context.type](context, "assertionsHelper").genMacro[Assertion](condition, "macroAssert", clue)
/**
* Provides implementation for Assertions.assume(booleanExpr: Boolean)
, with rich error message.
*
* @param context macro context
* @param condition original condition expression
* @return transformed expression that performs the assumption check and throw TestCanceledException
with rich error message if assumption failed
*/
def assume(context: Context)(condition: context.Expr[Boolean]): context.Expr[Assertion] =
new BooleanMacro[context.type](context, "assertionsHelper").genMacro[Assertion](condition, "macroAssume", context.literal(""))
/**
* Provides implementation for Assertions.assume(booleanExpr: Boolean, clue: Any)
, with rich error message.
*
* @param context macro context
* @param condition original condition expression
* @param clue original clue expression
* @return transformed expression that performs the assumption check and throw TestCanceledException
with rich error message (clue included) if assumption failed
*/
def assumeWithClue(context: Context)(condition: context.Expr[Boolean], clue: context.Expr[Any]): context.Expr[Assertion] =
new BooleanMacro[context.type](context, "assertionsHelper").genMacro[Assertion](condition, "macroAssume", clue)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy