|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.daffodil.lib.exceptions |
| 19 | + |
| 20 | +trait AssertsUsingMacrosMixin { |
| 21 | + |
| 22 | + /** |
| 23 | + * Verbose name helps you get the sense of the predicate right. |
| 24 | + */ |
| 25 | + def usageErrorUnless(testAbortsIfFalse: Boolean, message: String): Unit = |
| 26 | + macro AssertMacros.usageMacro2 |
| 27 | + |
| 28 | + def usageErrorUnless(testAbortsIfFalse: Boolean, cause: Throwable): Unit = |
| 29 | + macro AssertMacros.usageMacro2Cause |
| 30 | + |
| 31 | + def usageErrorUnless(testAbortsIfFalse: Boolean): Unit = macro AssertMacros.usageMacro1 |
| 32 | + |
| 33 | + /** |
| 34 | + * Brief form |
| 35 | + */ |
| 36 | + def usage(testAbortsIfFalse: Boolean, message: String): Unit = macro AssertMacros.usageMacro2 |
| 37 | + |
| 38 | + def usageWithCause(testAbortsIfFalse: Boolean, cause: Throwable): Unit = |
| 39 | + macro AssertMacros.usageMacro2Cause |
| 40 | + |
| 41 | + def usage(testAbortsIfFalse: Boolean): Unit = |
| 42 | + macro AssertMacros.usageMacro1 |
| 43 | + |
| 44 | + /** |
| 45 | + * test for something that the program is supposed to be ensuring. |
| 46 | + * |
| 47 | + * This is for more complex invariants than the simple 'impossible' case. |
| 48 | + */ |
| 49 | + def invariant(testAbortsIfFalse: Boolean): Unit = macro AssertMacros.invariantMacro1 |
| 50 | + |
| 51 | + /** |
| 52 | + * test for something that the program is supposed to be ensuring, with a custom error message. |
| 53 | + * |
| 54 | + * This is for more complex invariants than the simple 'impossible' case. |
| 55 | + * |
| 56 | + * The msg parameter is only evaluated if the test fails |
| 57 | + */ |
| 58 | + def invariant(testAbortsIfFalse: Boolean, msg: String): Unit = |
| 59 | + macro AssertMacros.invariantMacro2 |
| 60 | + |
| 61 | + /** |
| 62 | + * Conditional behavior for NYIs |
| 63 | + */ |
| 64 | + def notYetImplemented(testThatWillThrowIfTrue: Boolean): Unit = |
| 65 | + macro AssertMacros.notYetImplementedMacro1 |
| 66 | + |
| 67 | + def notYetImplemented(testThatWillThrowIfTrue: Boolean, msg: String): Unit = |
| 68 | + macro AssertMacros.notYetImplementedMacro2 |
| 69 | +} |
0 commit comments