Prepare kotlin-power-assert files for git merge with Kotlin
This commit is contained in:
@@ -1,18 +0,0 @@
|
|||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
charset = utf-8
|
|
||||||
end_of_line = lf
|
|
||||||
insert_final_newline = true
|
|
||||||
|
|
||||||
[*.{kt,kts}]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
|
||||||
|
|
||||||
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
|
|
||||||
ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^
|
|
||||||
ij_kotlin_name_count_to_use_star_import = 2147483647
|
|
||||||
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
|
|
||||||
ij_kotlin_packages_to_use_import_on_demand = unset
|
|
||||||
ij_kotlin_allow_trailing_comma_on_call_site = true
|
|
||||||
ij_kotlin_allow_trailing_comma = true
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
name: build
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
pull_request:
|
|
||||||
types: [opened, labeled, unlabeled, synchronize]
|
|
||||||
|
|
||||||
env:
|
|
||||||
GRADLE_OPTS: "-Dorg.gradle.jvmargs=-Xmx4g -Dorg.gradle.daemon=false -Dkotlin.incremental=false"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
tryK2: [false, true]
|
|
||||||
|
|
||||||
name: "Build"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- uses: gradle/wrapper-validation-action@v1
|
|
||||||
|
|
||||||
- name: Configure JDK
|
|
||||||
uses: actions/setup-java@v3
|
|
||||||
with:
|
|
||||||
distribution: 'zulu'
|
|
||||||
java-version: 11
|
|
||||||
|
|
||||||
- name: Build Project
|
|
||||||
uses: gradle/gradle-build-action@v2
|
|
||||||
with:
|
|
||||||
arguments: build
|
|
||||||
|
|
||||||
- name: Build Sample
|
|
||||||
uses: gradle/gradle-build-action@v2
|
|
||||||
with:
|
|
||||||
arguments: build -Pkotlin.experimental.tryK2=${{ matrix.tryK2 }}
|
|
||||||
build-root-directory: sample
|
|
||||||
|
|
||||||
- name: Publish Test Report
|
|
||||||
if: success() || failure()
|
|
||||||
uses: mikepenz/action-junit-report@v3
|
|
||||||
with:
|
|
||||||
report_paths: '**/build/test-results/test/TEST-*.xml'
|
|
||||||
|
|
||||||
lint:
|
|
||||||
name: "Lint"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Run ktlint
|
|
||||||
uses: ScaCap/action-ktlint@1.5.1
|
|
||||||
with:
|
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
reporter: github-pr-check
|
|
||||||
|
|
||||||
qodana:
|
|
||||||
name: "Qodana"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- name: 'Qodana Scan'
|
|
||||||
uses: JetBrains/qodana-action@v2022.2.1
|
|
||||||
- uses: github/codeql-action/upload-sarif@v2
|
|
||||||
with:
|
|
||||||
sarif_file: ${{ runner.temp }}/qodana/results/qodana.sarif.json
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
# Gradle
|
|
||||||
build/
|
|
||||||
.gradle/
|
|
||||||
|
|
||||||
# IDEA
|
|
||||||
out/
|
|
||||||
.idea/
|
|
||||||
*.iml
|
|
||||||
-180
@@ -1,180 +0,0 @@
|
|||||||
Change Log
|
|
||||||
==========
|
|
||||||
|
|
||||||
## Version 0.13.0
|
|
||||||
|
|
||||||
_2023-05-06_
|
|
||||||
|
|
||||||
**New**
|
|
||||||
* Support Kotlin 1.8.20 (#89).
|
|
||||||
|
|
||||||
**Fixes**
|
|
||||||
* Correctly align `in` operator. (#96).
|
|
||||||
|
|
||||||
## Version 0.12.2
|
|
||||||
|
|
||||||
_2023-04-09_
|
|
||||||
|
|
||||||
**Fixes**
|
|
||||||
* Correctly align `in` operator. (#95).
|
|
||||||
|
|
||||||
## Version 0.12.1
|
|
||||||
|
|
||||||
_2023-04-08_
|
|
||||||
|
|
||||||
**New**
|
|
||||||
* Support receivers of infix functions (#69).
|
|
||||||
|
|
||||||
**Fixes**
|
|
||||||
* Ignore implicit varargs array (#84).
|
|
||||||
* Ignore body of object literals (#85).
|
|
||||||
|
|
||||||
**Other**
|
|
||||||
* Run tests in parallel (#73) - @christophsturm.
|
|
||||||
* Upgrade to Gradle 8 (#87) - @TWiStErRob.
|
|
||||||
* Add Kotlinter for code styling (#86) - @christophsturm.
|
|
||||||
|
|
||||||
## Version 0.12.0
|
|
||||||
|
|
||||||
_2022-07-10_
|
|
||||||
|
|
||||||
**New**
|
|
||||||
* Support Kotlin 1.7.0 (#67).
|
|
||||||
* Allow excluding Gradle source sets from transformation (#55).
|
|
||||||
|
|
||||||
**Fixes**
|
|
||||||
* Ignore smart casting from diagram (#60).
|
|
||||||
* Properly align `is` operator result (#59).
|
|
||||||
* Support JVM static functions for transformation (#52).
|
|
||||||
|
|
||||||
## Version 0.11.0
|
|
||||||
|
|
||||||
_2021-11-18_
|
|
||||||
|
|
||||||
**New**
|
|
||||||
* Support Kotlin 1.6.0 (#50).
|
|
||||||
|
|
||||||
## Version 0.10.0
|
|
||||||
|
|
||||||
_2021-06-29_
|
|
||||||
|
|
||||||
**New**
|
|
||||||
* Support Kotlin 1.5.20.
|
|
||||||
|
|
||||||
## Version 0.9.0
|
|
||||||
|
|
||||||
_2021-06-02_
|
|
||||||
|
|
||||||
**New**
|
|
||||||
* Support Kotlin 1.5.10.
|
|
||||||
|
|
||||||
## Version 0.8.1
|
|
||||||
|
|
||||||
_2021-05-12_
|
|
||||||
|
|
||||||
**Fixes**
|
|
||||||
* Fix diagramming of expressions which contain lambdas (#44)
|
|
||||||
|
|
||||||
## Version 0.8.0
|
|
||||||
|
|
||||||
_2021-05-06_
|
|
||||||
|
|
||||||
**New**
|
|
||||||
* Compile against Kotlin 1.5.0 (#40).
|
|
||||||
* Support generic parameter diagramming (#39).
|
|
||||||
* Added support for `assertFalse` style functions.
|
|
||||||
* Added support for non-boolean functions.
|
|
||||||
* Support multiple parameter functions (#41).
|
|
||||||
* Added support for `assertEquals` style functions.
|
|
||||||
* Function signature must still end with a `String` or `() -> String` accepting parameter.
|
|
||||||
|
|
||||||
## Version 0.7.0
|
|
||||||
|
|
||||||
_2021-02-04_
|
|
||||||
|
|
||||||
**New**
|
|
||||||
* Support Kotlin 1.4.30.
|
|
||||||
|
|
||||||
**Fixes**
|
|
||||||
* Regex `matches` function formats poorly and exception (#31).
|
|
||||||
|
|
||||||
## Version 0.6.1
|
|
||||||
|
|
||||||
_2020-11-29_
|
|
||||||
|
|
||||||
Fixes:
|
|
||||||
* Better support for arithmetic in assertion condition (#27).
|
|
||||||
|
|
||||||
## Version 0.6.0
|
|
||||||
|
|
||||||
_2020-11-21_
|
|
||||||
|
|
||||||
Changes:
|
|
||||||
* Support Kotlin 1.4.20.
|
|
||||||
|
|
||||||
## Version 0.5.3
|
|
||||||
|
|
||||||
_2020-09-28_
|
|
||||||
|
|
||||||
Bug Fixes:
|
|
||||||
* Fix member and extension function transformation.
|
|
||||||
* Fix generation of message lambda for non-inline functions.
|
|
||||||
|
|
||||||
## Version 0.5.2
|
|
||||||
|
|
||||||
_2020-09-25_
|
|
||||||
|
|
||||||
Bug Fixes:
|
|
||||||
* Skip transformation if entire expression is constant (`true` or `false`)
|
|
||||||
(#23).
|
|
||||||
* Fix inlining of lambda parameter to transformed function call on Kotlin/JS
|
|
||||||
and Kotlin/Native (#22).
|
|
||||||
|
|
||||||
## Version 0.5.1
|
|
||||||
|
|
||||||
_2020-09-14_
|
|
||||||
|
|
||||||
Bug Fixes:
|
|
||||||
* Support Windows-style line-separators in compiled files (#20).
|
|
||||||
|
|
||||||
## Version 0.5.0
|
|
||||||
|
|
||||||
_2020-08-29_
|
|
||||||
|
|
||||||
* Support for Kotlin/Native (#18).
|
|
||||||
|
|
||||||
## Version 0.4.0
|
|
||||||
|
|
||||||
_2020-08-21_
|
|
||||||
|
|
||||||
* Support Kotlin 1.4.0.
|
|
||||||
|
|
||||||
## Version 0.3.1
|
|
||||||
|
|
||||||
_2020-05-25_
|
|
||||||
|
|
||||||
* Fix: Do not include wrapper class for top-level function in Gradle plugin
|
|
||||||
default function (#13).
|
|
||||||
|
|
||||||
## Version 0.3.0
|
|
||||||
|
|
||||||
_2020-03-07_
|
|
||||||
|
|
||||||
* Support Kotlin 1.3.70.
|
|
||||||
* Fix: Including Kotlin wrapper class for top-level functions in Gradle
|
|
||||||
configuration is no longer required.
|
|
||||||
|
|
||||||
## Version 0.2.0
|
|
||||||
|
|
||||||
_2020-02-12_
|
|
||||||
|
|
||||||
* Support configuring of which functions are transformed (eg, assert, require,
|
|
||||||
check, assertTrue). This works for any function which takes a Boolean and a
|
|
||||||
String.
|
|
||||||
* Support Boolean expressions which are split onto multiple lines.
|
|
||||||
|
|
||||||
## Version 0.1.0
|
|
||||||
|
|
||||||
_2020-02-10_
|
|
||||||
|
|
||||||
* Initial release
|
|
||||||
-202
@@ -1,202 +0,0 @@
|
|||||||
|
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
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.
|
|
||||||
@@ -1,244 +0,0 @@
|
|||||||
# kotlin-power-assert
|
|
||||||
|
|
||||||
[](https://maven-badges.herokuapp.com/maven-central/com.bnorm.power/kotlin-power-assert-plugin)
|
|
||||||
|
|
||||||
Kotlin Compiler Plugin which high-jacks Kotlin assert function calls and
|
|
||||||
transforms them similar to [Groovy's Power Assert feature][groovy-power-assert].
|
|
||||||
This plugin uses the IR backend for the Kotlin compiler and supports all
|
|
||||||
platforms: JVM, JS, and Native!
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
Given following code:
|
|
||||||
|
|
||||||
```kotlin
|
|
||||||
val hello = "Hello"
|
|
||||||
assert(hello.length == "World".substring(1, 4).length)
|
|
||||||
```
|
|
||||||
|
|
||||||
Normally the assertion message would look like:
|
|
||||||
|
|
||||||
```text
|
|
||||||
java.lang.AssertionError: Assertion failed
|
|
||||||
at <stacktrace>
|
|
||||||
```
|
|
||||||
|
|
||||||
A custom assertion message can be provided:
|
|
||||||
|
|
||||||
```kotlin
|
|
||||||
val hello = "Hello"
|
|
||||||
assert(hello.length == "World".substring(1, 4).length) { "Incorrect length" }
|
|
||||||
```
|
|
||||||
|
|
||||||
But this just replaces the message:
|
|
||||||
|
|
||||||
```text
|
|
||||||
java.lang.AssertionError: Incorrect length
|
|
||||||
at <stacktrace>
|
|
||||||
```
|
|
||||||
|
|
||||||
With `kotlin-power-assert` included, the error message for the previous example
|
|
||||||
will be transformed:
|
|
||||||
|
|
||||||
```text
|
|
||||||
java.lang.AssertionError: Incorrect length
|
|
||||||
assert(hello.length == "World".substring(1, 4).length)
|
|
||||||
| | | | |
|
|
||||||
| | | | 3
|
|
||||||
| | | orl
|
|
||||||
| | false
|
|
||||||
| 5
|
|
||||||
Hello
|
|
||||||
at <stacktrace>
|
|
||||||
```
|
|
||||||
|
|
||||||
Complex, multi-line, boolean expression are also supported:
|
|
||||||
|
|
||||||
```text
|
|
||||||
Assertion failed
|
|
||||||
assert(
|
|
||||||
(text != null && text.toLowerCase() == text) ||
|
|
||||||
| |
|
|
||||||
| false
|
|
||||||
null
|
|
||||||
text == "Hello"
|
|
||||||
| |
|
|
||||||
| false
|
|
||||||
null
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Beyond Assert
|
|
||||||
|
|
||||||
The plugin by default will transform `assert` function calls but can also
|
|
||||||
transform other functions like `require`, `check`, `assertTrue`, and many, many
|
|
||||||
more.
|
|
||||||
|
|
||||||
Functions which can be transformed have specific requirements. A function must
|
|
||||||
have a form which allows taking a `String` or `() -> String` value as the last
|
|
||||||
parameter. This can either be as an overload or the original function.
|
|
||||||
|
|
||||||
For example, the `assert` function has 2 definitions:
|
|
||||||
* `fun assert(value: Boolean)`
|
|
||||||
* `fun assert(value: Boolean, lazyMessage: () -> Any)`
|
|
||||||
|
|
||||||
If the first function definition is called, it will be transformed into calling
|
|
||||||
the second definition with the diagram message supplied as the last parameter.
|
|
||||||
If the second definition is called, it will be transformed into calling the same
|
|
||||||
function but with the diagram message appended to the last parameter.
|
|
||||||
|
|
||||||
This transformed function call doesn't need to throw an exception either. See
|
|
||||||
[Advanced Usage](#advanced-usage) for some examples.
|
|
||||||
|
|
||||||
## Gradle Plugin
|
|
||||||
|
|
||||||
Builds of the Gradle plugin are available through the
|
|
||||||
[Gradle Plugin Portal][kotlin-power-assert-gradle].
|
|
||||||
|
|
||||||
```kotlin
|
|
||||||
plugins {
|
|
||||||
kotlin("multiplatform") version "1.8.20"
|
|
||||||
id("com.bnorm.power.kotlin-power-assert") version "0.13.0"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The Gradle plugin allows configuring the functions which should be transformed
|
|
||||||
with a list of fully-qualified function names.
|
|
||||||
|
|
||||||
```kotlin
|
|
||||||
// Kotlin DSL
|
|
||||||
configure<com.bnorm.power.PowerAssertGradleExtension> {
|
|
||||||
functions = listOf("kotlin.assert", "kotlin.test.assertTrue")
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
```groovy
|
|
||||||
// Groovy
|
|
||||||
kotlinPowerAssert {
|
|
||||||
functions = ["kotlin.assert", "kotlin.test.assertTrue"]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also exclude Gradle source sets from being transformed by the plugin,
|
|
||||||
where those source sets can be specified by name.
|
|
||||||
|
|
||||||
```kotlin
|
|
||||||
// Kotlin DSL
|
|
||||||
configure<com.bnorm.power.PowerAssertGradleExtension> {
|
|
||||||
excludedSourceSets = listOf(
|
|
||||||
"commonMain",
|
|
||||||
"jvmMain",
|
|
||||||
"jsMain",
|
|
||||||
"nativeMain"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
```groovy
|
|
||||||
// Groovy
|
|
||||||
kotlinPowerAssert {
|
|
||||||
excludedSourceSets = [
|
|
||||||
"commonMain",
|
|
||||||
"jvmMain",
|
|
||||||
"jsMain",
|
|
||||||
"nativeMain"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Compatibility
|
|
||||||
|
|
||||||
The Kotlin compiler plugin API is unstable and each new version of Kotlin can
|
|
||||||
bring breaking changes to the APIs used by this compiler plugin. Make sure you
|
|
||||||
are using the correct version of this plugin for whatever version of Kotlin
|
|
||||||
used. Check the table below to find when support for a particular version of
|
|
||||||
Kotlin was first introduced. If a version of Kotlin or this plugin is not listed
|
|
||||||
it can be assumed to maintain compatibility with the next oldest version listed.
|
|
||||||
|
|
||||||
| Kotlin Version | Plugin Version |
|
|
||||||
|----------------|----------------|
|
|
||||||
| 1.3.60 | 0.1.0 |
|
|
||||||
| 1.3.70 | 0.3.0 |
|
|
||||||
| 1.4.0 | 0.4.0 |
|
|
||||||
| 1.4.20 | 0.6.0 |
|
|
||||||
| 1.4.30 | 0.7.0 |
|
|
||||||
| 1.5.0 | 0.8.0 |
|
|
||||||
| 1.5.10 | 0.9.0 |
|
|
||||||
| 1.5.20 | 0.10.0 |
|
|
||||||
| 1.6.0 | 0.11.0 |
|
|
||||||
| 1.7.0 | 0.12.0 |
|
|
||||||
| 1.8.20 | 0.13.0 |
|
|
||||||
|
|
||||||
## Kotlin IR
|
|
||||||
|
|
||||||
This plugin supports all IR based compiler backends: JVM, JS, and Native! Only
|
|
||||||
Kotlin/JS still uses the legacy compiler backend by default, use the following
|
|
||||||
to make sure IR is enabled.
|
|
||||||
|
|
||||||
```kotlin
|
|
||||||
target {
|
|
||||||
js(IR) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Advanced Usage
|
|
||||||
|
|
||||||
### Function Call Tracing
|
|
||||||
|
|
||||||
Similar to Rust's `dbg!` macro, functions which take arbitrary parameters can
|
|
||||||
be transformed. For example:
|
|
||||||
|
|
||||||
```kotlin
|
|
||||||
fun <T> dbg(value: T): T = value
|
|
||||||
|
|
||||||
fun <T> dbg(value: T, msg: String): T {
|
|
||||||
println(msg)
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
println(dbg(1 + 2 + 3))
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Prints the following:
|
|
||||||
|
|
||||||
```text
|
|
||||||
dbg(1 + 2 + 3)
|
|
||||||
| |
|
|
||||||
| 6
|
|
||||||
3
|
|
||||||
6
|
|
||||||
```
|
|
||||||
|
|
||||||
### Soft Assertion
|
|
||||||
|
|
||||||
To achieve soft assertion, the following template can be implemented:
|
|
||||||
|
|
||||||
```kotlin
|
|
||||||
typealias LazyMessage = () -> Any
|
|
||||||
|
|
||||||
interface AssertScope {
|
|
||||||
fun assert(assertion: Boolean, lazyMessage: LazyMessage? = null)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <R> assertSoftly(block: AssertScope.() -> R): R = TODO("implement")
|
|
||||||
```
|
|
||||||
|
|
||||||
You can then use the template as follows:
|
|
||||||
|
|
||||||
```kotlin
|
|
||||||
val jane: Person = TODO()
|
|
||||||
assertSoftly {
|
|
||||||
assert(jane.firstName == "Jane")
|
|
||||||
assert(jane.lastName == "Doe")
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
A working example is [available][soft-assert-example] in this repository in the
|
|
||||||
sample directory.
|
|
||||||
|
|
||||||
[groovy-power-assert]: https://groovy-lang.org/testing.html#_power_assertions
|
|
||||||
[kotlin-power-assert-gradle]: https://plugins.gradle.org/plugin/com.bnorm.power.kotlin-power-assert
|
|
||||||
[soft-assert-example]: https://github.com/bnorm/kotlin-power-assert/blob/master/sample/src/commonMain/kotlin/com/bnorm/power/AssertScope.kt
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|
||||||
import org.jmailen.gradle.kotlinter.KotlinterPlugin
|
|
||||||
import org.jmailen.gradle.kotlinter.tasks.FormatTask
|
|
||||||
import org.jmailen.gradle.kotlinter.tasks.LintTask
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
kotlin("jvm") version "1.8.20" apply false
|
|
||||||
id("org.jetbrains.dokka") version "1.8.10" apply false
|
|
||||||
id("com.gradle.plugin-publish") version "1.1.0" apply false
|
|
||||||
id("com.github.gmazzo.buildconfig") version "3.1.0" apply false
|
|
||||||
id("org.jmailen.kotlinter") version "3.14.0" apply false
|
|
||||||
}
|
|
||||||
|
|
||||||
allprojects {
|
|
||||||
group = "com.bnorm.power"
|
|
||||||
version = "0.14.0-SNAPSHOT"
|
|
||||||
}
|
|
||||||
|
|
||||||
allprojects {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType<JavaCompile> {
|
|
||||||
sourceCompatibility = "1.8"
|
|
||||||
targetCompatibility = "1.8"
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType<KotlinCompile> {
|
|
||||||
kotlinOptions.jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins.withType<KotlinterPlugin> {
|
|
||||||
val formatBuildscripts = tasks.register<FormatTask>("formatBuildscripts") {
|
|
||||||
group = "verification"
|
|
||||||
source(layout.projectDirectory.asFileTree.matching { include("**.kts") })
|
|
||||||
}
|
|
||||||
tasks.named("formatKotlin") { dependsOn(formatBuildscripts) }
|
|
||||||
|
|
||||||
val lintBuildscripts = tasks.register<LintTask>("lintBuildscripts") {
|
|
||||||
group = "verification"
|
|
||||||
source(layout.projectDirectory.asFileTree.matching { include("**.kts") })
|
|
||||||
}
|
|
||||||
tasks.named("lintKotlin") { dependsOn(lintBuildscripts) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
kapt.include.compile.classpath=false
|
|
||||||
Vendored
BIN
Binary file not shown.
-7
@@ -1,7 +0,0 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
|
||||||
distributionPath=wrapper/dists
|
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
|
||||||
networkTimeout=10000
|
|
||||||
validateDistributionUrl=true
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
|
||||||
zipStorePath=wrapper/dists
|
|
||||||
@@ -1,249 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
#
|
|
||||||
# Copyright © 2015-2021 the original authors.
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
#
|
|
||||||
# https://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.
|
|
||||||
#
|
|
||||||
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# Gradle start up script for POSIX generated by Gradle.
|
|
||||||
#
|
|
||||||
# Important for running:
|
|
||||||
#
|
|
||||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
|
||||||
# noncompliant, but you have some other compliant shell such as ksh or
|
|
||||||
# bash, then to run this script, type that shell name before the whole
|
|
||||||
# command line, like:
|
|
||||||
#
|
|
||||||
# ksh Gradle
|
|
||||||
#
|
|
||||||
# Busybox and similar reduced shells will NOT work, because this script
|
|
||||||
# requires all of these POSIX shell features:
|
|
||||||
# * functions;
|
|
||||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
|
||||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
|
||||||
# * compound commands having a testable exit status, especially «case»;
|
|
||||||
# * various built-in commands including «command», «set», and «ulimit».
|
|
||||||
#
|
|
||||||
# Important for patching:
|
|
||||||
#
|
|
||||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
|
||||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
|
||||||
#
|
|
||||||
# The "traditional" practice of packing multiple parameters into a
|
|
||||||
# space-separated string is a well documented source of bugs and security
|
|
||||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
|
||||||
# options in "$@", and eventually passing that to Java.
|
|
||||||
#
|
|
||||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
|
||||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
|
||||||
# see the in-line comments for details.
|
|
||||||
#
|
|
||||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
|
||||||
# Darwin, MinGW, and NonStop.
|
|
||||||
#
|
|
||||||
# (3) This script is generated from the Groovy template
|
|
||||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
|
||||||
# within the Gradle project.
|
|
||||||
#
|
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
|
||||||
|
|
||||||
# Resolve links: $0 may be a link
|
|
||||||
app_path=$0
|
|
||||||
|
|
||||||
# Need this for daisy-chained symlinks.
|
|
||||||
while
|
|
||||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
|
||||||
[ -h "$app_path" ]
|
|
||||||
do
|
|
||||||
ls=$( ls -ld "$app_path" )
|
|
||||||
link=${ls#*' -> '}
|
|
||||||
case $link in #(
|
|
||||||
/*) app_path=$link ;; #(
|
|
||||||
*) app_path=$APP_HOME$link ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# This is normally unused
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
APP_BASE_NAME=${0##*/}
|
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
||||||
MAX_FD=maximum
|
|
||||||
|
|
||||||
warn () {
|
|
||||||
echo "$*"
|
|
||||||
} >&2
|
|
||||||
|
|
||||||
die () {
|
|
||||||
echo
|
|
||||||
echo "$*"
|
|
||||||
echo
|
|
||||||
exit 1
|
|
||||||
} >&2
|
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
|
||||||
cygwin=false
|
|
||||||
msys=false
|
|
||||||
darwin=false
|
|
||||||
nonstop=false
|
|
||||||
case "$( uname )" in #(
|
|
||||||
CYGWIN* ) cygwin=true ;; #(
|
|
||||||
Darwin* ) darwin=true ;; #(
|
|
||||||
MSYS* | MINGW* ) msys=true ;; #(
|
|
||||||
NONSTOP* ) nonstop=true ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
|
||||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
|
||||||
else
|
|
||||||
JAVACMD=$JAVA_HOME/bin/java
|
|
||||||
fi
|
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
JAVACMD=java
|
|
||||||
if ! command -v java >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
|
||||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|
||||||
case $MAX_FD in #(
|
|
||||||
max*)
|
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
|
||||||
# shellcheck disable=SC2039,SC3045
|
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
|
||||||
warn "Could not query maximum file descriptor limit"
|
|
||||||
esac
|
|
||||||
case $MAX_FD in #(
|
|
||||||
'' | soft) :;; #(
|
|
||||||
*)
|
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
|
||||||
# shellcheck disable=SC2039,SC3045
|
|
||||||
ulimit -n "$MAX_FD" ||
|
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Collect all arguments for the java command, stacking in reverse order:
|
|
||||||
# * args from the command line
|
|
||||||
# * the main class name
|
|
||||||
# * -classpath
|
|
||||||
# * -D...appname settings
|
|
||||||
# * --module-path (only if needed)
|
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
|
||||||
|
|
||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
||||||
if "$cygwin" || "$msys" ; then
|
|
||||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
|
||||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
|
||||||
|
|
||||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
|
||||||
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
for arg do
|
|
||||||
if
|
|
||||||
case $arg in #(
|
|
||||||
-*) false ;; # don't mess with options #(
|
|
||||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
|
||||||
[ -e "$t" ] ;; #(
|
|
||||||
*) false ;;
|
|
||||||
esac
|
|
||||||
then
|
|
||||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
|
||||||
fi
|
|
||||||
# Roll the args list around exactly as many times as the number of
|
|
||||||
# args, so each arg winds up back in the position where it started, but
|
|
||||||
# possibly modified.
|
|
||||||
#
|
|
||||||
# NB: a `for` loop captures its iteration list before it begins, so
|
|
||||||
# changing the positional parameters here affects neither the number of
|
|
||||||
# iterations, nor the values presented in `arg`.
|
|
||||||
shift # remove old arg
|
|
||||||
set -- "$@" "$arg" # push replacement arg
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Collect all arguments for the java command:
|
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
|
||||||
# and any embedded shellness will be escaped.
|
|
||||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
|
||||||
# treated as '${Hostname}' itself on the command line.
|
|
||||||
|
|
||||||
set -- \
|
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
|
||||||
-classpath "$CLASSPATH" \
|
|
||||||
org.gradle.wrapper.GradleWrapperMain \
|
|
||||||
"$@"
|
|
||||||
|
|
||||||
# Stop when "xargs" is not available.
|
|
||||||
if ! command -v xargs >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
die "xargs is not available"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Use "xargs" to parse quoted args.
|
|
||||||
#
|
|
||||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
|
||||||
#
|
|
||||||
# In Bash we could simply go:
|
|
||||||
#
|
|
||||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
|
||||||
# set -- "${ARGS[@]}" "$@"
|
|
||||||
#
|
|
||||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
|
||||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
|
||||||
# character that might be a shell metacharacter, then use eval to reverse
|
|
||||||
# that process (while maintaining the separation between arguments), and wrap
|
|
||||||
# the whole thing up as a single "set" statement.
|
|
||||||
#
|
|
||||||
# This will of course break if any of these variables contains a newline or
|
|
||||||
# an unmatched quote.
|
|
||||||
#
|
|
||||||
|
|
||||||
eval "set -- $(
|
|
||||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
|
||||||
xargs -n1 |
|
|
||||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
|
||||||
tr '\n' ' '
|
|
||||||
)" '"$@"'
|
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
|
||||||
Vendored
-92
@@ -1,92 +0,0 @@
|
|||||||
@rem
|
|
||||||
@rem Copyright 2015 the original author or authors.
|
|
||||||
@rem
|
|
||||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
@rem you may not use this file except in compliance with the License.
|
|
||||||
@rem You may obtain a copy of the License at
|
|
||||||
@rem
|
|
||||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
@rem
|
|
||||||
@rem Unless required by applicable law or agreed to in writing, software
|
|
||||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
@rem See the License for the specific language governing permissions and
|
|
||||||
@rem limitations under the License.
|
|
||||||
@rem
|
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
|
||||||
@rem ##########################################################################
|
|
||||||
@rem
|
|
||||||
@rem Gradle startup script for Windows
|
|
||||||
@rem
|
|
||||||
@rem ##########################################################################
|
|
||||||
|
|
||||||
@rem Set local scope for the variables with windows NT shell
|
|
||||||
if "%OS%"=="Windows_NT" setlocal
|
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
|
||||||
if "%DIRNAME%"=="" set DIRNAME=.
|
|
||||||
@rem This is normally unused
|
|
||||||
set APP_BASE_NAME=%~n0
|
|
||||||
set APP_HOME=%DIRNAME%
|
|
||||||
|
|
||||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
|
||||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
|
||||||
|
|
||||||
@rem Find java.exe
|
|
||||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
|
||||||
if %ERRORLEVEL% equ 0 goto execute
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
echo.
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
echo location of your Java installation.
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:findJavaFromJavaHome
|
|
||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
|
||||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
|
||||||
echo.
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
echo location of your Java installation.
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:execute
|
|
||||||
@rem Setup the command line
|
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
|
||||||
|
|
||||||
:end
|
|
||||||
@rem End local scope for the variables with windows NT shell
|
|
||||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
|
||||||
|
|
||||||
:fail
|
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
|
||||||
rem the _cmd.exe /c_ return code!
|
|
||||||
set EXIT_CODE=%ERRORLEVEL%
|
|
||||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
|
||||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
|
||||||
exit /b %EXIT_CODE%
|
|
||||||
|
|
||||||
:mainEnd
|
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
|
||||||
|
|
||||||
:omega
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id("java-gradle-plugin")
|
|
||||||
kotlin("jvm")
|
|
||||||
id("com.gradle.plugin-publish")
|
|
||||||
id("com.github.gmazzo.buildconfig")
|
|
||||||
id("org.jmailen.kotlinter")
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation(kotlin("stdlib"))
|
|
||||||
implementation(kotlin("gradle-plugin-api"))
|
|
||||||
}
|
|
||||||
|
|
||||||
buildConfig {
|
|
||||||
val project = project(":kotlin-power-assert-plugin")
|
|
||||||
packageName(project.group.toString())
|
|
||||||
buildConfigField("String", "PLUGIN_GROUP_ID", "\"${project.group}\"")
|
|
||||||
buildConfigField("String", "PLUGIN_ARTIFACT_ID", "\"${project.name}\"")
|
|
||||||
buildConfigField("String", "PLUGIN_VERSION", "\"${project.version}\"")
|
|
||||||
}
|
|
||||||
|
|
||||||
gradlePlugin {
|
|
||||||
website.set("https://github.com/bnorm/kotlin-power-assert")
|
|
||||||
vcsUrl.set("https://github.com/bnorm/kotlin-power-assert.git")
|
|
||||||
plugins {
|
|
||||||
create("kotlinPowerAssert") {
|
|
||||||
id = "com.bnorm.power.kotlin-power-assert"
|
|
||||||
displayName = "Kotlin Power Assertion Plugin"
|
|
||||||
description = "Kotlin Compiler Plugin to add power to your assertions"
|
|
||||||
implementationClass = "com.bnorm.power.PowerAssertGradlePlugin"
|
|
||||||
tags.set(listOf("kotlin", "power-assert"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.named("publish") {
|
|
||||||
dependsOn("publishPlugins")
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
repositories {
|
|
||||||
maven {
|
|
||||||
name = "test"
|
|
||||||
url = uri(rootProject.layout.buildDirectory.dir("localMaven"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
kotlin("jvm")
|
|
||||||
kotlin("kapt")
|
|
||||||
id("org.jetbrains.dokka")
|
|
||||||
|
|
||||||
signing
|
|
||||||
`maven-publish`
|
|
||||||
id("org.jmailen.kotlinter")
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compileOnly("org.jetbrains.kotlin:kotlin-compiler-embeddable")
|
|
||||||
|
|
||||||
kapt("com.google.auto.service:auto-service:1.0.1")
|
|
||||||
compileOnly("com.google.auto.service:auto-service-annotations:1.0.1")
|
|
||||||
|
|
||||||
testImplementation(kotlin("test-junit5"))
|
|
||||||
testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable")
|
|
||||||
testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.5.0")
|
|
||||||
testImplementation(enforcedPlatform("org.junit:junit-bom:5.9.1"))
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType<KotlinCompile> {
|
|
||||||
kotlinOptions.freeCompilerArgs += listOf(
|
|
||||||
"-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType<Test> {
|
|
||||||
useJUnitPlatform()
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.register("sourcesJar", Jar::class) {
|
|
||||||
group = "build"
|
|
||||||
description = "Assembles Kotlin sources"
|
|
||||||
|
|
||||||
archiveClassifier.set("sources")
|
|
||||||
from(sourceSets.main.get().allSource)
|
|
||||||
dependsOn(tasks.classes)
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.register("dokkaJar", Jar::class) {
|
|
||||||
group = "documentation"
|
|
||||||
description = "Assembles Kotlin docs with Dokka"
|
|
||||||
|
|
||||||
archiveClassifier.set("javadoc")
|
|
||||||
from(tasks.dokkaHtml)
|
|
||||||
dependsOn(tasks.dokkaHtml)
|
|
||||||
}
|
|
||||||
|
|
||||||
signing {
|
|
||||||
setRequired(provider { gradle.taskGraph.hasTask("publish") })
|
|
||||||
sign(publishing.publications)
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
publications {
|
|
||||||
create<MavenPublication>("default") {
|
|
||||||
from(components["java"])
|
|
||||||
artifact(tasks["sourcesJar"])
|
|
||||||
artifact(tasks["dokkaJar"])
|
|
||||||
|
|
||||||
pom {
|
|
||||||
name.set(project.name)
|
|
||||||
description.set("Kotlin compiler plugin to enable power assertions in the Kotlin programming language")
|
|
||||||
url.set("https://github.com/bnorm/kotlin-power-assert")
|
|
||||||
|
|
||||||
licenses {
|
|
||||||
license {
|
|
||||||
name.set("Apache License 2.0")
|
|
||||||
url.set("https://github.com/bnorm/kotlin-power-assert/blob/master/LICENSE.txt")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
scm {
|
|
||||||
url.set("https://github.com/bnorm/kotlin-power-assert")
|
|
||||||
connection.set("scm:git:git://github.com/bnorm/kotlin-power-assert.git")
|
|
||||||
}
|
|
||||||
developers {
|
|
||||||
developer {
|
|
||||||
name.set("Brian Norman")
|
|
||||||
url.set("https://github.com/bnorm")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
if (
|
|
||||||
hasProperty("sonatypeUsername") &&
|
|
||||||
hasProperty("sonatypePassword") &&
|
|
||||||
hasProperty("sonatypeSnapshotUrl") &&
|
|
||||||
hasProperty("sonatypeReleaseUrl")
|
|
||||||
) {
|
|
||||||
maven {
|
|
||||||
val sonatypeUrlProperty = when {
|
|
||||||
version.toString().endsWith("-SNAPSHOT") -> "sonatypeSnapshotUrl"
|
|
||||||
else -> "sonatypeReleaseUrl"
|
|
||||||
}
|
|
||||||
setUrl(property(sonatypeUrlProperty) as String)
|
|
||||||
credentials {
|
|
||||||
username = property("sonatypeUsername") as String
|
|
||||||
password = property("sonatypePassword") as String
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
maven {
|
|
||||||
name = "test"
|
|
||||||
url = uri(rootProject.layout.buildDirectory.dir("localMaven"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,441 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 Brian Norman
|
|
||||||
*
|
|
||||||
* 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 com.bnorm.power
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import kotlin.test.Test
|
|
||||||
|
|
||||||
class AssertTest {
|
|
||||||
@Test
|
|
||||||
fun memberFunctions() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
val hello = "Hello"
|
|
||||||
assert(hello.length == "World".substring(1, 4).length)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert(hello.length == "World".substring(1, 4).length)
|
|
||||||
| | | | |
|
|
||||||
| | | | 3
|
|
||||||
| | | orl
|
|
||||||
| | false
|
|
||||||
| 5
|
|
||||||
Hello
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun transformations() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
val hello = listOf("Hello", "World")
|
|
||||||
assert(hello.reversed() == emptyList<String>())
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert(hello.reversed() == emptyList<String>())
|
|
||||||
| | | |
|
|
||||||
| | | []
|
|
||||||
| | false
|
|
||||||
| [World, Hello]
|
|
||||||
[Hello, World]
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun customMessage() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
assert(1 == 2) { "Not equal" }
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Not equal
|
|
||||||
assert(1 == 2) { "Not equal" }
|
|
||||||
|
|
|
||||||
false
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun customLocalVariableMessage() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
val lambda = { "Not equal" }
|
|
||||||
assert(1 == 2, lambda)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Not equal
|
|
||||||
assert(1 == 2, lambda)
|
|
||||||
|
|
|
||||||
false
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun booleanExpressionsShortCircuit() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
val text: String? = null
|
|
||||||
assert(text != null && text.length == 1)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert(text != null && text.length == 1)
|
|
||||||
| |
|
|
||||||
| false
|
|
||||||
null
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun booleanAnd() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
val text: String? = "Hello"
|
|
||||||
assert(text != null && text.length == 5 && text.toLowerCase() == text)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert(text != null && text.length == 5 && text.toLowerCase() == text)
|
|
||||||
| | | | | | | | |
|
|
||||||
| | | | | | | | Hello
|
|
||||||
| | | | | | | false
|
|
||||||
| | | | | | hello
|
|
||||||
| | | | | Hello
|
|
||||||
| | | | true
|
|
||||||
| | | 5
|
|
||||||
| | Hello
|
|
||||||
| true
|
|
||||||
Hello
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun booleanOr() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
val text: String? = "Hello"
|
|
||||||
assert(text == null || text.length == 1 || text.toLowerCase() == text)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert(text == null || text.length == 1 || text.toLowerCase() == text)
|
|
||||||
| | | | | | | | |
|
|
||||||
| | | | | | | | Hello
|
|
||||||
| | | | | | | false
|
|
||||||
| | | | | | hello
|
|
||||||
| | | | | Hello
|
|
||||||
| | | | false
|
|
||||||
| | | 5
|
|
||||||
| | Hello
|
|
||||||
| false
|
|
||||||
Hello
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun booleanMixAndFirst() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
val text: String? = "Hello"
|
|
||||||
assert(text != null && (text.length == 1 || text.toLowerCase() == text))
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert(text != null && (text.length == 1 || text.toLowerCase() == text))
|
|
||||||
| | | | | | | | |
|
|
||||||
| | | | | | | | Hello
|
|
||||||
| | | | | | | false
|
|
||||||
| | | | | | hello
|
|
||||||
| | | | | Hello
|
|
||||||
| | | | false
|
|
||||||
| | | 5
|
|
||||||
| | Hello
|
|
||||||
| true
|
|
||||||
Hello
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun booleanMixAndLast() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
val text = "Hello"
|
|
||||||
assert((text.length == 1 || text.toLowerCase() == text) && text.length == 1)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert((text.length == 1 || text.toLowerCase() == text) && text.length == 1)
|
|
||||||
| | | | | | |
|
|
||||||
| | | | | | Hello
|
|
||||||
| | | | | false
|
|
||||||
| | | | hello
|
|
||||||
| | | Hello
|
|
||||||
| | false
|
|
||||||
| 5
|
|
||||||
Hello
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun booleanMixOrFirst() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
val text: String? = "Hello"
|
|
||||||
assert(text == null || (text.length == 5 && text.toLowerCase() == text))
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert(text == null || (text.length == 5 && text.toLowerCase() == text))
|
|
||||||
| | | | | | | | |
|
|
||||||
| | | | | | | | Hello
|
|
||||||
| | | | | | | false
|
|
||||||
| | | | | | hello
|
|
||||||
| | | | | Hello
|
|
||||||
| | | | true
|
|
||||||
| | | 5
|
|
||||||
| | Hello
|
|
||||||
| false
|
|
||||||
Hello
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun booleanMixOrLast() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
val text = "Hello"
|
|
||||||
assert((text.length == 5 && text.toLowerCase() == text) || text.length == 1)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert((text.length == 5 && text.toLowerCase() == text) || text.length == 1)
|
|
||||||
| | | | | | | | | |
|
|
||||||
| | | | | | | | | false
|
|
||||||
| | | | | | | | 5
|
|
||||||
| | | | | | | Hello
|
|
||||||
| | | | | | Hello
|
|
||||||
| | | | | false
|
|
||||||
| | | | hello
|
|
||||||
| | | Hello
|
|
||||||
| | true
|
|
||||||
| 5
|
|
||||||
Hello
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun conditionalAccess() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
val text: String? = "Hello"
|
|
||||||
assert(text?.length?.minus(2) == 1)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert(text?.length?.minus(2) == 1)
|
|
||||||
| | | |
|
|
||||||
| | | false
|
|
||||||
| | 3
|
|
||||||
| 5
|
|
||||||
Hello
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun infixFunctions() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
assert(1.shl(1) == 4)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert(1.shl(1) == 4)
|
|
||||||
| |
|
|
||||||
| false
|
|
||||||
2
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
assert(1 shl 1 == 4)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert(1 shl 1 == 4)
|
|
||||||
| |
|
|
||||||
| false
|
|
||||||
2
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun multiline() {
|
|
||||||
assertMessage(
|
|
||||||
"""fun main() {
|
|
||||||
val text: String? = "Hello"
|
|
||||||
assert(
|
|
||||||
text
|
|
||||||
== null ||
|
|
||||||
(
|
|
||||||
text.length == 5 &&
|
|
||||||
text.toLowerCase() == text
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert(
|
|
||||||
text
|
|
||||||
|
|
|
||||||
Hello
|
|
||||||
== null ||
|
|
||||||
|
|
|
||||||
false
|
|
||||||
(
|
|
||||||
text.length == 5 &&
|
|
||||||
| | |
|
|
||||||
| | true
|
|
||||||
| 5
|
|
||||||
Hello
|
|
||||||
text.toLowerCase() == text
|
|
||||||
| | | |
|
|
||||||
| | | Hello
|
|
||||||
| | false
|
|
||||||
| hello
|
|
||||||
Hello
|
|
||||||
)
|
|
||||||
)
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun assertTrueCustomMessage() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import kotlin.test.assertTrue
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val text: String? = "Hello"
|
|
||||||
assertTrue(1 == 2, message = "${"$"}text, the world is broken")
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Hello, the world is broken
|
|
||||||
assertTrue(1 == 2, message = "${"$"}text, the world is broken")
|
|
||||||
|
|
|
||||||
false
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun requireCustomMessage() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
require(1 == 2) { "the world is broken" }
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
the world is broken
|
|
||||||
require(1 == 2) { "the world is broken" }
|
|
||||||
|
|
|
||||||
false
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.require"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun checkCustomMessage() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
check(1 == 2) { "the world is broken" }
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
the world is broken
|
|
||||||
check(1 == 2) { "the world is broken" }
|
|
||||||
|
|
|
||||||
false
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.check"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun carriageReturnRemoval() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
val a = 0
|
|
||||||
assert(a == 42)
|
|
||||||
}""".replace("\n", "\r\n"),
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert(a == 42)
|
|
||||||
| |
|
|
||||||
| false
|
|
||||||
0
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun constantExpression() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
assert(true)
|
|
||||||
assert(false)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,330 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 Brian Norman
|
|
||||||
*
|
|
||||||
* 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 com.bnorm.power
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import kotlin.test.Test
|
|
||||||
|
|
||||||
class Junit5AssertionsTest {
|
|
||||||
@Test
|
|
||||||
fun `test JUnit5 Assertions#assertTrue transformation`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import org.junit.jupiter.api.Assertions.assertTrue
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
assertTrue(1 != 1)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assertTrue(1 != 1)
|
|
||||||
|
|
|
||||||
false ==> expected: <true> but was: <false>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test JUnit5 Assertions#assertTrue transformation with message`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import org.junit.jupiter.api.Assertions.assertTrue
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
assertTrue(1 != 1, "Message:")
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertTrue(1 != 1, "Message:")
|
|
||||||
|
|
|
||||||
false ==> expected: <true> but was: <false>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test JUnit5 Assertions#assertTrue transformation with local variable message`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import org.junit.jupiter.api.Assertions.assertTrue
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val message = "Message:"
|
|
||||||
assertTrue(1 != 1, message)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertTrue(1 != 1, message)
|
|
||||||
|
|
|
||||||
false ==> expected: <true> but was: <false>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test JUnit5 Assertions#assertTrue transformation with message supplier`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import org.junit.jupiter.api.Assertions.assertTrue
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
assertTrue(1 != 1) { "Message:" }
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertTrue(1 != 1) { "Message:" }
|
|
||||||
|
|
|
||||||
false ==> expected: <true> but was: <false>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test JUnit5 Assertions#assertTrue transformation with local variable message supplier`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import java.util.function.Supplier
|
|
||||||
import org.junit.jupiter.api.Assertions.assertTrue
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val supplier = Supplier { "Message:" }
|
|
||||||
assertTrue(1 != 1, supplier)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertTrue(1 != 1, supplier)
|
|
||||||
|
|
|
||||||
false ==> expected: <true> but was: <false>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test JUnit5 Assertions#assertFalse transformation`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import org.junit.jupiter.api.Assertions.assertFalse
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
assertFalse(1 == 1)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assertFalse(1 == 1)
|
|
||||||
|
|
|
||||||
true ==> expected: <false> but was: <true>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test JUnit5 Assertions#assertFalse transformation with message`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import org.junit.jupiter.api.Assertions.assertFalse
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
assertFalse(1 == 1, "Message:")
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertFalse(1 == 1, "Message:")
|
|
||||||
|
|
|
||||||
true ==> expected: <false> but was: <true>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test JUnit5 Assertions#assertFalse transformation with local variable message`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import org.junit.jupiter.api.Assertions.assertFalse
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val message = "Message:"
|
|
||||||
assertFalse(1 == 1, message)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertFalse(1 == 1, message)
|
|
||||||
|
|
|
||||||
true ==> expected: <false> but was: <true>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test JUnit5 Assertions#assertFalse transformation with message supplier`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import org.junit.jupiter.api.Assertions.assertFalse
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
assertFalse(1 == 1) { "Message:" }
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertFalse(1 == 1) { "Message:" }
|
|
||||||
|
|
|
||||||
true ==> expected: <false> but was: <true>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test JUnit5 Assertions#assertFalse transformation with local variable message supplier`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import java.util.function.Supplier
|
|
||||||
import org.junit.jupiter.api.Assertions.assertFalse
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val supplier = Supplier { "Message:" }
|
|
||||||
assertFalse(1 == 1, supplier)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertFalse(1 == 1, supplier)
|
|
||||||
|
|
|
||||||
true ==> expected: <false> but was: <true>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test JUnit5 Assertions#assertEquals transformation`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val greeting = "Hello"
|
|
||||||
val name = "World"
|
|
||||||
assertEquals(greeting, name)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
assertEquals(greeting, name)
|
|
||||||
| |
|
|
||||||
| World
|
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test JUnit5 Assertions#assertEquals transformation with message`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val greeting = "Hello"
|
|
||||||
val name = "World"
|
|
||||||
assertEquals(greeting, name, "Message:")
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertEquals(greeting, name, "Message:")
|
|
||||||
| |
|
|
||||||
| World
|
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test JUnit5 Assertions#assertEquals transformation with local variable message`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val greeting = "Hello"
|
|
||||||
val name = "World"
|
|
||||||
val message = "Message:"
|
|
||||||
assertEquals(greeting, name, message)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertEquals(greeting, name, message)
|
|
||||||
| |
|
|
||||||
| World
|
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test JUnit5 Assertions#assertEquals transformation with message supplier`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val greeting = "Hello"
|
|
||||||
val name = "World"
|
|
||||||
assertEquals(greeting, name) { "Message:" }
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertEquals(greeting, name) { "Message:" }
|
|
||||||
| |
|
|
||||||
| World
|
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test JUnit5 Assertions#assertEquals transformation with local variable message supplier`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import java.util.function.Supplier
|
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val greeting = "Hello"
|
|
||||||
val name = "World"
|
|
||||||
val supplier = Supplier { "Message:" }
|
|
||||||
assertEquals(greeting, name, supplier)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertEquals(greeting, name, supplier)
|
|
||||||
| |
|
|
||||||
| World
|
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,264 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 Brian Norman
|
|
||||||
*
|
|
||||||
* 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 com.bnorm.power
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import kotlin.test.Test
|
|
||||||
|
|
||||||
class KotlinTestAssertTest {
|
|
||||||
@Test
|
|
||||||
fun `test assertTrue transformation`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import kotlin.test.assertTrue
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
assertTrue(1 != 1)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assertTrue(1 != 1)
|
|
||||||
|
|
|
||||||
false
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test assertTrue transformation with message`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import kotlin.test.assertTrue
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
assertTrue(1 != 1, "Message:")
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertTrue(1 != 1, "Message:")
|
|
||||||
|
|
|
||||||
false
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test assertTrue transformation with local variable message`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import kotlin.test.assertTrue
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val message = "Message:"
|
|
||||||
assertTrue(1 != 1, message)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertTrue(1 != 1, message)
|
|
||||||
|
|
|
||||||
false
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test assertFalse transformation`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import kotlin.test.assertFalse
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
assertFalse(1 == 1)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assertFalse(1 == 1)
|
|
||||||
|
|
|
||||||
true
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertFalse"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test assertFalse transformation with message`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import kotlin.test.assertFalse
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
assertFalse(1 == 1, "Message:")
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertFalse(1 == 1, "Message:")
|
|
||||||
|
|
|
||||||
true
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertFalse"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test assertFalse transformation with local variable message`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import kotlin.test.assertFalse
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val message = "Message:"
|
|
||||||
assertFalse(1 == 1, message)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertFalse(1 == 1, message)
|
|
||||||
|
|
|
||||||
true
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertFalse"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test assertEquals transformation`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val greeting = "Hello"
|
|
||||||
val name = "World"
|
|
||||||
assertEquals(greeting, name)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
assertEquals(greeting, name)
|
|
||||||
| |
|
|
||||||
| World
|
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertEquals"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test assertEquals transformation with message`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val greeting = "Hello"
|
|
||||||
val name = "World"
|
|
||||||
assertEquals(greeting, name, "Message:")
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertEquals(greeting, name, "Message:")
|
|
||||||
| |
|
|
||||||
| World
|
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertEquals"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test assertEquals transformation with local variable message`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val greeting = "Hello"
|
|
||||||
val name = "World"
|
|
||||||
val message = "Message:"
|
|
||||||
assertEquals(greeting, name, message)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertEquals(greeting, name, message)
|
|
||||||
| |
|
|
||||||
| World
|
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertEquals"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test assertNotNull transformation`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import kotlin.test.assertNotNull
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val name: String? = null
|
|
||||||
assertNotNull(name)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
assertNotNull(name)
|
|
||||||
|
|
|
||||||
null ==> expected: not <null>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertNotNull"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test assertNotNull transformation with message`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import kotlin.test.assertNotNull
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val name: String? = null
|
|
||||||
assertNotNull(name, "Message:")
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertNotNull(name, "Message:")
|
|
||||||
|
|
|
||||||
null ==> expected: not <null>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertNotNull"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test assertNotNull transformation with local variable message`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
import kotlin.test.assertNotNull
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val name: String? = null
|
|
||||||
val message = "Message:"
|
|
||||||
assertNotNull(name, message)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Message:
|
|
||||||
assertNotNull(name, message)
|
|
||||||
|
|
|
||||||
null ==> expected: not <null>
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertNotNull"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 Brian Norman
|
|
||||||
*
|
|
||||||
* 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 com.bnorm.power
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import kotlin.test.Test
|
|
||||||
|
|
||||||
class LamdaTest {
|
|
||||||
@Test
|
|
||||||
fun `list operations assert`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
val list = listOf("Jane", "John")
|
|
||||||
assert(list.map { "Doe, ${'$'}it" }.any { it == "Scott, Michael" })
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert(list.map { "Doe, ${'$'}it" }.any { it == "Scott, Michael" })
|
|
||||||
| | |
|
|
||||||
| | false
|
|
||||||
| [Doe, Jane, Doe, John]
|
|
||||||
[Jane, John]
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `list operations require`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
val list = listOf("Jane", "John")
|
|
||||||
require(
|
|
||||||
value = list
|
|
||||||
.map { "Doe, ${'$'}it" }
|
|
||||||
.any { it == "Scott, Michael" }
|
|
||||||
)
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
require(
|
|
||||||
value = list
|
|
||||||
|
|
|
||||||
[Jane, John]
|
|
||||||
.map { "Doe, ${'$'}it" }
|
|
||||||
|
|
|
||||||
[Doe, Jane, Doe, John]
|
|
||||||
.any { it == "Scott, Michael" }
|
|
||||||
|
|
|
||||||
false
|
|
||||||
)
|
|
||||||
""".trimIndent(),
|
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.require"))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-157
@@ -1,157 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 Brian Norman
|
|
||||||
*
|
|
||||||
* 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 com.bnorm.power
|
|
||||||
|
|
||||||
import com.tschuchort.compiletesting.KotlinCompilation
|
|
||||||
import com.tschuchort.compiletesting.SourceFile
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import kotlin.test.Test
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
|
|
||||||
class MultiParameterFunctionTest {
|
|
||||||
@Test
|
|
||||||
fun `debug multi-parameter function transformation`() {
|
|
||||||
val actual = executeMainDebug(
|
|
||||||
"""
|
|
||||||
val operation = "sum"
|
|
||||||
dbg(operation, 1 + 2 + 3)
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
assertEquals(
|
|
||||||
"""
|
|
||||||
sum=6
|
|
||||||
dbg(operation, 1 + 2 + 3)
|
|
||||||
| | |
|
|
||||||
| | 6
|
|
||||||
| 3
|
|
||||||
sum
|
|
||||||
""".trimIndent(),
|
|
||||||
actual.trim(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `debug multi-parameter function transformation with complex booleans`() {
|
|
||||||
val actual = executeMainDebug(
|
|
||||||
"""
|
|
||||||
val greeting: String? = null
|
|
||||||
val name: String? = null
|
|
||||||
dbg(
|
|
||||||
key = greeting != null && greeting.length == 5,
|
|
||||||
value = name == null || name.length == 5
|
|
||||||
)
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
assertEquals(
|
|
||||||
"""
|
|
||||||
false=true
|
|
||||||
dbg(
|
|
||||||
key = greeting != null && greeting.length == 5,
|
|
||||||
| |
|
|
||||||
| false
|
|
||||||
null
|
|
||||||
value = name == null || name.length == 5
|
|
||||||
| |
|
|
||||||
| true
|
|
||||||
null
|
|
||||||
)
|
|
||||||
""".trimIndent(),
|
|
||||||
actual.trim(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `debug multi-parameter function transformation with message`() {
|
|
||||||
val actual = executeMainDebug(
|
|
||||||
"""
|
|
||||||
val operation = "sum"
|
|
||||||
dbg(operation, 1 + 2 + 3, "Message:")
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
assertEquals(
|
|
||||||
"""
|
|
||||||
sum=6
|
|
||||||
Message:
|
|
||||||
dbg(operation, 1 + 2 + 3, "Message:")
|
|
||||||
| | |
|
|
||||||
| | 6
|
|
||||||
| 3
|
|
||||||
sum
|
|
||||||
""".trimIndent(),
|
|
||||||
actual.trim(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `debug multi-parameter function transformation with message and complex booleans`() {
|
|
||||||
val actual = executeMainDebug(
|
|
||||||
"""
|
|
||||||
val greeting: String? = null
|
|
||||||
val name: String? = null
|
|
||||||
dbg(
|
|
||||||
key = greeting != null && greeting.length == 5,
|
|
||||||
value = name == null || name.length == 5,
|
|
||||||
msg = "Message:"
|
|
||||||
)
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
assertEquals(
|
|
||||||
"""
|
|
||||||
false=true
|
|
||||||
Message:
|
|
||||||
dbg(
|
|
||||||
key = greeting != null && greeting.length == 5,
|
|
||||||
| |
|
|
||||||
| false
|
|
||||||
null
|
|
||||||
value = name == null || name.length == 5,
|
|
||||||
| |
|
|
||||||
| true
|
|
||||||
null
|
|
||||||
msg = "Message:"
|
|
||||||
)
|
|
||||||
""".trimIndent(),
|
|
||||||
actual.trim(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun executeMainDebug(mainBody: String): String {
|
|
||||||
val file = SourceFile.kotlin(
|
|
||||||
name = "main.kt",
|
|
||||||
contents = """
|
|
||||||
fun <T> dbg(key: Any, value: T): T = value
|
|
||||||
|
|
||||||
fun <T> dbg(key: Any, value: T, msg: String): T {
|
|
||||||
throw RuntimeException("result:"+key.toString() + "=" + value + "\n" + msg)
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
$mainBody
|
|
||||||
}
|
|
||||||
""",
|
|
||||||
trimIndent = false,
|
|
||||||
)
|
|
||||||
|
|
||||||
val result = compile(listOf(file), PowerAssertCompilerPluginRegistrar(setOf(FqName("dbg"))))
|
|
||||||
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode)
|
|
||||||
|
|
||||||
val kClazz = result.classLoader.loadClass("MainKt")
|
|
||||||
val main = kClazz.declaredMethods.single { it.name == "main" && it.parameterCount == 0 }
|
|
||||||
return getMainResult(main)
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2023 Brian Norman
|
|
||||||
*
|
|
||||||
* 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 com.bnorm.power
|
|
||||||
|
|
||||||
import kotlin.test.Test
|
|
||||||
|
|
||||||
class OperatorTest {
|
|
||||||
@Test
|
|
||||||
fun `contains operator is correctly aligned`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
assert("Name" in listOf("Hello", "World"))
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert("Name" in listOf("Hello", "World"))
|
|
||||||
| |
|
|
||||||
| [Hello, World]
|
|
||||||
false
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `contains function is correctly aligned`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
assert(listOf("Hello", "World").contains("Name"))
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert(listOf("Hello", "World").contains("Name"))
|
|
||||||
| |
|
|
||||||
| false
|
|
||||||
[Hello, World]
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `negative contains operator is correctly aligned`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
assert("Hello" !in listOf("Hello", "World"))
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert("Hello" !in listOf("Hello", "World"))
|
|
||||||
| |
|
|
||||||
| [Hello, World]
|
|
||||||
false
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `negative contains function is correctly aligned`() {
|
|
||||||
assertMessage(
|
|
||||||
"""
|
|
||||||
fun main() {
|
|
||||||
assert(!listOf("Hello", "World").contains("Hello"))
|
|
||||||
}""",
|
|
||||||
"""
|
|
||||||
Assertion failed
|
|
||||||
assert(!listOf("Hello", "World").contains("Hello"))
|
|
||||||
|| |
|
|
||||||
|| true
|
|
||||||
|[Hello, World]
|
|
||||||
false
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
# suppress inspection "UnusedProperty" for whole file
|
|
||||||
junit.jupiter.execution.parallel.enabled = true
|
|
||||||
junit.jupiter.execution.parallel.mode.default = concurrent
|
|
||||||
+1
-1
@@ -27,7 +27,7 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.fail
|
import kotlin.test.fail
|
||||||
|
|
||||||
private val DEFAULT_COMPILER_PLUGIN_REGISTRARS = arrayOf(
|
private val DEFAULT_COMPILER_PLUGIN_REGISTRARS = arrayOf(
|
||||||
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.assert"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.assert"))),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun compile(
|
fun compile(
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
version: "1.0"
|
|
||||||
linter: jetbrains/qodana-jvm-community:2022.2
|
|
||||||
profile:
|
|
||||||
name: qodana.recommended
|
|
||||||
exclude:
|
|
||||||
- name: All
|
|
||||||
paths:
|
|
||||||
- sample
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
plugins {
|
|
||||||
kotlin("multiplatform") version "1.9.20"
|
|
||||||
id("com.bnorm.power.kotlin-power-assert") version "0.13.0"
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
jvm()
|
|
||||||
js(IR) {
|
|
||||||
browser()
|
|
||||||
nodejs()
|
|
||||||
}
|
|
||||||
|
|
||||||
val osName = System.getProperty("os.name")
|
|
||||||
val osArch = System.getProperty("os.arch")
|
|
||||||
when {
|
|
||||||
"Windows" in osName -> mingwX64("native")
|
|
||||||
"Mac OS" in osName -> when (osArch) {
|
|
||||||
"aarch64" -> macosArm64("native")
|
|
||||||
else -> macosX64("native")
|
|
||||||
}
|
|
||||||
else -> linuxX64("native")
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
val commonMain by getting {
|
|
||||||
}
|
|
||||||
val commonTest by getting {
|
|
||||||
dependencies {
|
|
||||||
implementation(kotlin("test-common"))
|
|
||||||
implementation(kotlin("test-annotations-common"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val jvmTest by getting {
|
|
||||||
dependencies {
|
|
||||||
implementation(kotlin("test-junit5"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val jsTest by getting {
|
|
||||||
dependencies {
|
|
||||||
implementation(kotlin("test-js"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val nativeMain by getting {
|
|
||||||
dependsOn(commonMain)
|
|
||||||
}
|
|
||||||
val nativeTest by getting {
|
|
||||||
dependsOn(commonTest)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Kotlin/JS loses class information at the IR level -> Soft-assertion doesn't work
|
|
||||||
// targets.all {
|
|
||||||
// compilations.all {
|
|
||||||
// kotlinOptions.languageVersion = "2.0"
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType<Test> {
|
|
||||||
useJUnitPlatform()
|
|
||||||
}
|
|
||||||
|
|
||||||
configure<com.bnorm.power.PowerAssertGradleExtension> {
|
|
||||||
functions = listOf(
|
|
||||||
"kotlin.assert",
|
|
||||||
"kotlin.test.assertTrue",
|
|
||||||
"kotlin.require",
|
|
||||||
"com.bnorm.power.AssertScope.assert",
|
|
||||||
"com.bnorm.power.assert",
|
|
||||||
"com.bnorm.power.dbg"
|
|
||||||
)
|
|
||||||
excludedSourceSets = listOf(
|
|
||||||
"commonMain",
|
|
||||||
"jvmMain",
|
|
||||||
"jsMain",
|
|
||||||
"nativeMain"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
org.gradle.daemon=false
|
|
||||||
org.gradle.jvmargs=-Xmx4g
|
|
||||||
kotlin.compiler.execution.strategy=in-process
|
|
||||||
kotlin.mpp.stability.nowarn=true
|
|
||||||
BIN
Binary file not shown.
@@ -1,7 +0,0 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
|
||||||
distributionPath=wrapper/dists
|
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
|
||||||
networkTimeout=10000
|
|
||||||
validateDistributionUrl=true
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
|
||||||
zipStorePath=wrapper/dists
|
|
||||||
Vendored
-249
@@ -1,249 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
#
|
|
||||||
# Copyright © 2015-2021 the original authors.
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
#
|
|
||||||
# https://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.
|
|
||||||
#
|
|
||||||
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# Gradle start up script for POSIX generated by Gradle.
|
|
||||||
#
|
|
||||||
# Important for running:
|
|
||||||
#
|
|
||||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
|
||||||
# noncompliant, but you have some other compliant shell such as ksh or
|
|
||||||
# bash, then to run this script, type that shell name before the whole
|
|
||||||
# command line, like:
|
|
||||||
#
|
|
||||||
# ksh Gradle
|
|
||||||
#
|
|
||||||
# Busybox and similar reduced shells will NOT work, because this script
|
|
||||||
# requires all of these POSIX shell features:
|
|
||||||
# * functions;
|
|
||||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
|
||||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
|
||||||
# * compound commands having a testable exit status, especially «case»;
|
|
||||||
# * various built-in commands including «command», «set», and «ulimit».
|
|
||||||
#
|
|
||||||
# Important for patching:
|
|
||||||
#
|
|
||||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
|
||||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
|
||||||
#
|
|
||||||
# The "traditional" practice of packing multiple parameters into a
|
|
||||||
# space-separated string is a well documented source of bugs and security
|
|
||||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
|
||||||
# options in "$@", and eventually passing that to Java.
|
|
||||||
#
|
|
||||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
|
||||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
|
||||||
# see the in-line comments for details.
|
|
||||||
#
|
|
||||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
|
||||||
# Darwin, MinGW, and NonStop.
|
|
||||||
#
|
|
||||||
# (3) This script is generated from the Groovy template
|
|
||||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
|
||||||
# within the Gradle project.
|
|
||||||
#
|
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
|
||||||
|
|
||||||
# Resolve links: $0 may be a link
|
|
||||||
app_path=$0
|
|
||||||
|
|
||||||
# Need this for daisy-chained symlinks.
|
|
||||||
while
|
|
||||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
|
||||||
[ -h "$app_path" ]
|
|
||||||
do
|
|
||||||
ls=$( ls -ld "$app_path" )
|
|
||||||
link=${ls#*' -> '}
|
|
||||||
case $link in #(
|
|
||||||
/*) app_path=$link ;; #(
|
|
||||||
*) app_path=$APP_HOME$link ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# This is normally unused
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
APP_BASE_NAME=${0##*/}
|
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
||||||
MAX_FD=maximum
|
|
||||||
|
|
||||||
warn () {
|
|
||||||
echo "$*"
|
|
||||||
} >&2
|
|
||||||
|
|
||||||
die () {
|
|
||||||
echo
|
|
||||||
echo "$*"
|
|
||||||
echo
|
|
||||||
exit 1
|
|
||||||
} >&2
|
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
|
||||||
cygwin=false
|
|
||||||
msys=false
|
|
||||||
darwin=false
|
|
||||||
nonstop=false
|
|
||||||
case "$( uname )" in #(
|
|
||||||
CYGWIN* ) cygwin=true ;; #(
|
|
||||||
Darwin* ) darwin=true ;; #(
|
|
||||||
MSYS* | MINGW* ) msys=true ;; #(
|
|
||||||
NONSTOP* ) nonstop=true ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
|
||||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
|
||||||
else
|
|
||||||
JAVACMD=$JAVA_HOME/bin/java
|
|
||||||
fi
|
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
JAVACMD=java
|
|
||||||
if ! command -v java >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
|
||||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|
||||||
case $MAX_FD in #(
|
|
||||||
max*)
|
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
|
||||||
# shellcheck disable=SC2039,SC3045
|
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
|
||||||
warn "Could not query maximum file descriptor limit"
|
|
||||||
esac
|
|
||||||
case $MAX_FD in #(
|
|
||||||
'' | soft) :;; #(
|
|
||||||
*)
|
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
|
||||||
# shellcheck disable=SC2039,SC3045
|
|
||||||
ulimit -n "$MAX_FD" ||
|
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Collect all arguments for the java command, stacking in reverse order:
|
|
||||||
# * args from the command line
|
|
||||||
# * the main class name
|
|
||||||
# * -classpath
|
|
||||||
# * -D...appname settings
|
|
||||||
# * --module-path (only if needed)
|
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
|
||||||
|
|
||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
||||||
if "$cygwin" || "$msys" ; then
|
|
||||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
|
||||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
|
||||||
|
|
||||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
|
||||||
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
for arg do
|
|
||||||
if
|
|
||||||
case $arg in #(
|
|
||||||
-*) false ;; # don't mess with options #(
|
|
||||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
|
||||||
[ -e "$t" ] ;; #(
|
|
||||||
*) false ;;
|
|
||||||
esac
|
|
||||||
then
|
|
||||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
|
||||||
fi
|
|
||||||
# Roll the args list around exactly as many times as the number of
|
|
||||||
# args, so each arg winds up back in the position where it started, but
|
|
||||||
# possibly modified.
|
|
||||||
#
|
|
||||||
# NB: a `for` loop captures its iteration list before it begins, so
|
|
||||||
# changing the positional parameters here affects neither the number of
|
|
||||||
# iterations, nor the values presented in `arg`.
|
|
||||||
shift # remove old arg
|
|
||||||
set -- "$@" "$arg" # push replacement arg
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Collect all arguments for the java command:
|
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
|
||||||
# and any embedded shellness will be escaped.
|
|
||||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
|
||||||
# treated as '${Hostname}' itself on the command line.
|
|
||||||
|
|
||||||
set -- \
|
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
|
||||||
-classpath "$CLASSPATH" \
|
|
||||||
org.gradle.wrapper.GradleWrapperMain \
|
|
||||||
"$@"
|
|
||||||
|
|
||||||
# Stop when "xargs" is not available.
|
|
||||||
if ! command -v xargs >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
die "xargs is not available"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Use "xargs" to parse quoted args.
|
|
||||||
#
|
|
||||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
|
||||||
#
|
|
||||||
# In Bash we could simply go:
|
|
||||||
#
|
|
||||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
|
||||||
# set -- "${ARGS[@]}" "$@"
|
|
||||||
#
|
|
||||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
|
||||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
|
||||||
# character that might be a shell metacharacter, then use eval to reverse
|
|
||||||
# that process (while maintaining the separation between arguments), and wrap
|
|
||||||
# the whole thing up as a single "set" statement.
|
|
||||||
#
|
|
||||||
# This will of course break if any of these variables contains a newline or
|
|
||||||
# an unmatched quote.
|
|
||||||
#
|
|
||||||
|
|
||||||
eval "set -- $(
|
|
||||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
|
||||||
xargs -n1 |
|
|
||||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
|
||||||
tr '\n' ' '
|
|
||||||
)" '"$@"'
|
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
|
||||||
Vendored
-92
@@ -1,92 +0,0 @@
|
|||||||
@rem
|
|
||||||
@rem Copyright 2015 the original author or authors.
|
|
||||||
@rem
|
|
||||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
@rem you may not use this file except in compliance with the License.
|
|
||||||
@rem You may obtain a copy of the License at
|
|
||||||
@rem
|
|
||||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
@rem
|
|
||||||
@rem Unless required by applicable law or agreed to in writing, software
|
|
||||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
@rem See the License for the specific language governing permissions and
|
|
||||||
@rem limitations under the License.
|
|
||||||
@rem
|
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
|
||||||
@rem ##########################################################################
|
|
||||||
@rem
|
|
||||||
@rem Gradle startup script for Windows
|
|
||||||
@rem
|
|
||||||
@rem ##########################################################################
|
|
||||||
|
|
||||||
@rem Set local scope for the variables with windows NT shell
|
|
||||||
if "%OS%"=="Windows_NT" setlocal
|
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
|
||||||
if "%DIRNAME%"=="" set DIRNAME=.
|
|
||||||
@rem This is normally unused
|
|
||||||
set APP_BASE_NAME=%~n0
|
|
||||||
set APP_HOME=%DIRNAME%
|
|
||||||
|
|
||||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
|
||||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
|
||||||
|
|
||||||
@rem Find java.exe
|
|
||||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
|
||||||
if %ERRORLEVEL% equ 0 goto execute
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
echo.
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
echo location of your Java installation.
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:findJavaFromJavaHome
|
|
||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
|
||||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
|
||||||
echo.
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
echo location of your Java installation.
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:execute
|
|
||||||
@rem Setup the command line
|
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
|
||||||
|
|
||||||
:end
|
|
||||||
@rem End local scope for the variables with windows NT shell
|
|
||||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
|
||||||
|
|
||||||
:fail
|
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
|
||||||
rem the _cmd.exe /c_ return code!
|
|
||||||
set EXIT_CODE=%ERRORLEVEL%
|
|
||||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
|
||||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
|
||||||
exit /b %EXIT_CODE%
|
|
||||||
|
|
||||||
:mainEnd
|
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
|
||||||
|
|
||||||
:omega
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,3 +0,0 @@
|
|||||||
rootProject.name = "kotlin-power-assert-sample"
|
|
||||||
|
|
||||||
includeBuild("..")
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package com.bnorm.power
|
|
||||||
|
|
||||||
import kotlin.contracts.*
|
|
||||||
|
|
||||||
typealias LazyMessage = () -> Any
|
|
||||||
|
|
||||||
interface AssertScope {
|
|
||||||
fun assert(assertion: Boolean, lazyMessage: LazyMessage? = null)
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalContracts::class)
|
|
||||||
fun assert(assertion: Boolean, lazyMessage: LazyMessage? = null) {
|
|
||||||
contract { returns() implies assertion }
|
|
||||||
if (!assertion) {
|
|
||||||
throw AssertionError(lazyMessage?.invoke()?.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SoftAssertScope : AssertScope {
|
|
||||||
private val assertions = mutableListOf<Throwable>()
|
|
||||||
|
|
||||||
override fun assert(assertion: Boolean, lazyMessage: LazyMessage?) {
|
|
||||||
if (!assertion) {
|
|
||||||
assertions.add(AssertionError(lazyMessage?.invoke()?.toString()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun close(exception: Throwable? = null) {
|
|
||||||
if (assertions.isNotEmpty()) {
|
|
||||||
val base = exception ?: AssertionError("Multiple failed assertions")
|
|
||||||
for (assertion in assertions) {
|
|
||||||
base.addSuppressed(assertion)
|
|
||||||
}
|
|
||||||
throw base
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalContracts::class)
|
|
||||||
fun <R> assertSoftly(block: AssertScope.() -> R): R {
|
|
||||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
|
||||||
|
|
||||||
val scope = SoftAssertScope()
|
|
||||||
val result = runCatching { scope.block() }
|
|
||||||
scope.close(result.exceptionOrNull())
|
|
||||||
return result.getOrThrow()
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.bnorm.power
|
|
||||||
|
|
||||||
val debugLog = StringBuilder()
|
|
||||||
|
|
||||||
fun <T> dbg(value: T): T = value
|
|
||||||
|
|
||||||
fun <T> dbg(value: T, msg: String): T {
|
|
||||||
debugLog.appendLine(msg)
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 Brian Norman
|
|
||||||
*
|
|
||||||
* 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 com.bnorm.power
|
|
||||||
|
|
||||||
data class Person(
|
|
||||||
val firstName: String,
|
|
||||||
val lastName: String,
|
|
||||||
) {
|
|
||||||
init {
|
|
||||||
require(firstName.isNotBlank())
|
|
||||||
require(lastName.isNotBlank())
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
val UNKNOWN = listOf(Person("John", "Doe"), Person("Jane", "Doe"))
|
|
||||||
override fun toString() = "Person.Companion"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,162 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 Brian Norman
|
|
||||||
*
|
|
||||||
* 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 com.bnorm.power
|
|
||||||
|
|
||||||
import kotlin.test.AfterTest
|
|
||||||
import kotlin.test.Test
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
import kotlin.test.assertFailsWith
|
|
||||||
import kotlin.test.assertTrue
|
|
||||||
|
|
||||||
class PowerAssertTest {
|
|
||||||
|
|
||||||
@AfterTest
|
|
||||||
fun cleanup() {
|
|
||||||
debugLog.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun assertTrue() {
|
|
||||||
val error = assertFailsWith<AssertionError> { assertTrue(Person.UNKNOWN.size == 1) }
|
|
||||||
assertEquals(
|
|
||||||
actual = error.message,
|
|
||||||
expected = """
|
|
||||||
Assertion failed
|
|
||||||
assertTrue(Person.UNKNOWN.size == 1)
|
|
||||||
| | | |
|
|
||||||
| | | false
|
|
||||||
| | 2
|
|
||||||
| [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)]
|
|
||||||
Person.Companion
|
|
||||||
""".trimIndent()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun require() {
|
|
||||||
val error = assertFailsWith<IllegalArgumentException> { require(Person.UNKNOWN.size == 1) }
|
|
||||||
assertEquals(
|
|
||||||
actual = error.message,
|
|
||||||
expected = """
|
|
||||||
Assertion failed
|
|
||||||
require(Person.UNKNOWN.size == 1)
|
|
||||||
| | | |
|
|
||||||
| | | false
|
|
||||||
| | 2
|
|
||||||
| [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)]
|
|
||||||
Person.Companion
|
|
||||||
""".trimIndent()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun excludedRequire() {
|
|
||||||
val error = assertFailsWith<IllegalArgumentException> { Person("", "") }
|
|
||||||
assertEquals(
|
|
||||||
actual = error.message,
|
|
||||||
expected = "Failed requirement."
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun softAssert() {
|
|
||||||
val unknown: List<Person>? = Person.UNKNOWN
|
|
||||||
assert(unknown != null)
|
|
||||||
assert(unknown.size == 2)
|
|
||||||
|
|
||||||
val error = assertFailsWith<AssertionError> {
|
|
||||||
val jane: Person
|
|
||||||
val john: Person
|
|
||||||
assertSoftly {
|
|
||||||
jane = unknown[0]
|
|
||||||
assert(jane.firstName == "Jane")
|
|
||||||
assert(jane.lastName == "Doe") { "bad jane last name" }
|
|
||||||
|
|
||||||
john = unknown[1]
|
|
||||||
assert(john.lastName == "Doe" && john.firstName == "John") { "bad john" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assertEquals(
|
|
||||||
actual = error.message,
|
|
||||||
expected = """
|
|
||||||
Multiple failed assertions
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
assertEquals(
|
|
||||||
actual = error.suppressedExceptions.size,
|
|
||||||
expected = 2,
|
|
||||||
)
|
|
||||||
assertEquals(
|
|
||||||
actual = error.suppressedExceptions[0].message,
|
|
||||||
expected = """
|
|
||||||
Assertion failed
|
|
||||||
assert(jane.firstName == "Jane")
|
|
||||||
| | |
|
|
||||||
| | false
|
|
||||||
| John
|
|
||||||
Person(firstName=John, lastName=Doe)
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
assertEquals(
|
|
||||||
actual = error.suppressedExceptions[1].message,
|
|
||||||
expected = """
|
|
||||||
bad john
|
|
||||||
assert(john.lastName == "Doe" && john.firstName == "John") { "bad john" }
|
|
||||||
| | | | | |
|
|
||||||
| | | | | false
|
|
||||||
| | | | Jane
|
|
||||||
| | | Person(firstName=Jane, lastName=Doe)
|
|
||||||
| | true
|
|
||||||
| Doe
|
|
||||||
Person(firstName=Jane, lastName=Doe)
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun dbgTest() {
|
|
||||||
val name = "Jane"
|
|
||||||
val greeting = dbg("Hello, $name")
|
|
||||||
assert(greeting == "Hello, Jane")
|
|
||||||
assertEquals(
|
|
||||||
actual = debugLog.toString().trim(),
|
|
||||||
expected = """
|
|
||||||
dbg("Hello, ${"$"}name")
|
|
||||||
| |
|
|
||||||
| Jane
|
|
||||||
Hello, Jane
|
|
||||||
""".trimIndent()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun dbgMessageTest() {
|
|
||||||
val name = "Jane"
|
|
||||||
val greeting = dbg("Hello, $name", "Greeting:")
|
|
||||||
assert(greeting == "Hello, Jane")
|
|
||||||
assertEquals(
|
|
||||||
actual = debugLog.toString().trim(),
|
|
||||||
expected = """
|
|
||||||
Greeting:
|
|
||||||
dbg("Hello, ${"$"}name", "Greeting:")
|
|
||||||
| |
|
|
||||||
| Jane
|
|
||||||
Hello, Jane
|
|
||||||
""".trimIndent()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 Brian Norman
|
|
||||||
*
|
|
||||||
* 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 com.bnorm.power
|
|
||||||
|
|
||||||
import kotlin.test.Test
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
import kotlin.test.assertFailsWith
|
|
||||||
|
|
||||||
class JsPowerAssertTest {
|
|
||||||
@Test
|
|
||||||
fun assert() {
|
|
||||||
val error = assertFailsWith<IllegalArgumentException> {
|
|
||||||
require(Person.UNKNOWN.size == 1) { "unknown persons: ${Person.UNKNOWN}" }
|
|
||||||
}
|
|
||||||
assertEquals(
|
|
||||||
actual = error.message,
|
|
||||||
expected = """
|
|
||||||
unknown persons: [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)]
|
|
||||||
require(Person.UNKNOWN.size == 1) { "unknown persons: ${"$"}{Person.UNKNOWN}" }
|
|
||||||
| | | |
|
|
||||||
| | | false
|
|
||||||
| | 2
|
|
||||||
| [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)]
|
|
||||||
Person.Companion
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 Brian Norman
|
|
||||||
*
|
|
||||||
* 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 com.bnorm.power
|
|
||||||
|
|
||||||
import kotlin.test.Test
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
import kotlin.test.assertFailsWith
|
|
||||||
|
|
||||||
class JvmPowerAssertTest {
|
|
||||||
@Test
|
|
||||||
fun assert() {
|
|
||||||
val error = assertFailsWith<AssertionError> {
|
|
||||||
assert(Person.UNKNOWN.size == 1) { "unknown persons: ${Person.UNKNOWN}" }
|
|
||||||
}
|
|
||||||
assertEquals(
|
|
||||||
actual = error.message,
|
|
||||||
expected = """
|
|
||||||
unknown persons: [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)]
|
|
||||||
assert(Person.UNKNOWN.size == 1) { "unknown persons: ${"$"}{Person.UNKNOWN}" }
|
|
||||||
| | | |
|
|
||||||
| | | false
|
|
||||||
| | 2
|
|
||||||
| [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)]
|
|
||||||
Person.Companion
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 Brian Norman
|
|
||||||
*
|
|
||||||
* 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 com.bnorm.power
|
|
||||||
|
|
||||||
import kotlin.test.Test
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
import kotlin.test.assertFailsWith
|
|
||||||
|
|
||||||
class NativePowerAssertTest {
|
|
||||||
@Test
|
|
||||||
fun assert() {
|
|
||||||
val error = assertFailsWith<AssertionError> {
|
|
||||||
assert(Person.UNKNOWN.size == 1) { "unknown persons: ${Person.UNKNOWN}" }
|
|
||||||
}
|
|
||||||
assertEquals(
|
|
||||||
actual = error.message,
|
|
||||||
expected = """
|
|
||||||
unknown persons: [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)]
|
|
||||||
assert(Person.UNKNOWN.size == 1) { "unknown persons: ${"$"}{Person.UNKNOWN}" }
|
|
||||||
| | | |
|
|
||||||
| | | false
|
|
||||||
| | 2
|
|
||||||
| [Person(firstName=John, lastName=Doe), Person(firstName=Jane, lastName=Doe)]
|
|
||||||
Person.Companion
|
|
||||||
""".trimIndent(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
rootProject.name = "kotlin-power-assert"
|
|
||||||
|
|
||||||
include(":kotlin-power-assert-gradle")
|
|
||||||
include(":kotlin-power-assert-plugin")
|
|
||||||
Reference in New Issue
Block a user