-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is an assertion, which can be disabled at build time. For now, it is not disabled by default. For now, it is also unused.
- Loading branch information
Showing
15 changed files
with
338 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
core/shared/src/test/scala/dev/tauri/choam/core/AssertSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2016-2024 Daniel Urban and contributors listed in NOTICE.txt | ||
* | ||
* 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 dev.tauri.choam | ||
package core | ||
|
||
final class AssertSpec extends BaseSpec { | ||
|
||
test("_assert should be enabled during tests (for now)".fail) { | ||
_assert(false) | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
internal-helpers/src/test/scala-2.13/dev/tauri/choam/helpers/ChoamUtils2.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2016-2024 Daniel Urban and contributors listed in NOTICE.txt | ||
* | ||
* 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 dev.tauri.choam | ||
package helpers | ||
|
||
import scala.annotation.{ elidable, nowarn } | ||
|
||
// Note: this is duplicated from `ChoamUtils`, | ||
// so that we can test disabling `_assert`. | ||
@nowarn("msg=elidable") | ||
private[choam] abstract class ChoamUtils2 { | ||
|
||
@elidable(elidable.ASSERTION) | ||
private[choam] final def _assert(ok: Boolean): Unit = { | ||
if (!ok) { | ||
throw new AssertionError | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...l-helpers/src/test/scala-2.13/dev/tauri/choam/helpers/DisableAssertionsSpecScala213.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2016-2024 Daniel Urban and contributors listed in NOTICE.txt | ||
* | ||
* 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 dev.tauri.choam | ||
package helpers | ||
|
||
final class DisableAssertionsSpecScala213 extends BaseSpec { | ||
|
||
test("The Scala 2.13 `-Xelide-below` also affects Predef.assert") { | ||
Predef.assert(false) | ||
Predef.assert(false, "foo") | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
internal-helpers/src/test/scala-3/dev/tauri/choam/helpers/ChoamUtils2.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2016-2024 Daniel Urban and contributors listed in NOTICE.txt | ||
* | ||
* 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 dev.tauri.choam | ||
package helpers | ||
|
||
// Note: this is duplicated from `ChoamUtils`, | ||
// so that we can test disabling `_assert`. | ||
private[choam] abstract class ChoamUtils2 { | ||
|
||
private[choam] inline final val assertionsEnabled = | ||
BuildInfo.assertionsEnabled | ||
|
||
private[choam] inline final def _assert(inline ok: Boolean): Unit = { | ||
inline if (assertionsEnabled) { | ||
if (!ok) { | ||
throw new AssertionError | ||
} | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
internal-helpers/src/test/scala/dev/tauri/choam/helpers/DisabledAssertionsSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2016-2024 Daniel Urban and contributors listed in NOTICE.txt | ||
* | ||
* 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 dev.tauri.choam | ||
package helpers | ||
|
||
final class DisableAssertionsSpec extends BaseSpec { | ||
|
||
test("_assert should have no effect") { | ||
_assert(false) | ||
_assert({ throw new Exception; false }) : @nowarn("cat=w-flag-dead-code") | ||
} | ||
|
||
test("munit assert should still work".fail) { | ||
this.assert(false) | ||
} | ||
|
||
test("require(Boolean) should still work".fail) { | ||
require(false) | ||
} | ||
|
||
test("require(Boolean, => Any) should still work".fail) { | ||
require(false, "foo") | ||
} | ||
|
||
test("impossible should still work".fail) { | ||
impossible("foo") | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
internal-helpers/src/test/scala/dev/tauri/choam/helpers/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2016-2024 Daniel Urban and contributors listed in NOTICE.txt | ||
* | ||
* 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 dev.tauri.choam | ||
|
||
package object helpers extends ChoamUtils2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
mcas/shared/src/test/scala/dev/tauri/choam/internal/mcas/AssertSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2016-2024 Daniel Urban and contributors listed in NOTICE.txt | ||
* | ||
* 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 dev.tauri.choam | ||
package internal | ||
package mcas | ||
|
||
final class AssertSpec extends BaseSpec { | ||
|
||
test("_assert should be enabled during tests (for now)".fail) { | ||
_assert(false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
skiplist/jvm/src/test/scala/dev/tauri/choam/internal/skiplist/AssertSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2016-2024 Daniel Urban and contributors listed in NOTICE.txt | ||
* | ||
* 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 dev.tauri.choam | ||
package internal | ||
package skiplist | ||
|
||
final class AssertSpec extends munit.FunSuite { | ||
|
||
test("_assert should be enabled during tests (for now)".fail) { | ||
_assert(false) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
skiplist/shared/src/main/scala-2.13/dev/tauri/choam/internal/ChoamUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2016-2024 Daniel Urban and contributors listed in NOTICE.txt | ||
* | ||
* 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 dev.tauri.choam | ||
package internal | ||
|
||
import scala.annotation.{ elidable, nowarn } | ||
|
||
// Note: this code is duplicated for (1) Scala 2.13/3, and (2) for tests in `helpers`. | ||
@nowarn("msg=elidable") | ||
private[choam] abstract class ChoamUtils { | ||
|
||
@elidable(elidable.ASSERTION) | ||
private[choam] final def _assert(ok: Boolean): Unit = { | ||
if (!ok) { | ||
throw new AssertionError | ||
} | ||
} | ||
} |
Oops, something went wrong.