Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix assert(Not)Equal & add tests #1945

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions base/src/testing.act
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,14 @@ class NotIsInstanceError(AssertionError):


def assertEqual[T(Eq)](a: ?T, b: ?T, msg: ?str):
if a is not None and b is not None and not (a == b):
if ((a is None and b is not None)
or (a is not None and b is None)
or (a is not None and b is not None and not (a == b))):
raise NotEqualError(a, b, msg)

def assertNotEqual(a, b, msg: ?str):
if not (a != b):
def assertNotEqual[T(Eq)](a: ?T, b: ?T, msg: ?str):
if ((a is None and b is None)
or (a is not None and b is not None and a == b)):
raise EqualError(a, b, msg)

def assertTrue(a, msg: ?str):
Expand Down
12 changes: 6 additions & 6 deletions test/stdlib_tests/src/test_logging.act
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ actor MyApp(log_handler):
actor LogTester(report_result: action(?bool, ?Exception) -> None, log_handler: logging.Handler):

expected_logs = [
logging.Message(logging.INFO, [], "", "hej", None),
logging.Message(logging.INFO, [], "", "hello", None),
logging.Message(logging.DEBUG, [], "", "dello", None),
logging.Message(logging.INFO, ["MyApp"], "", "Starting up", None),
logging.Message(logging.INFO, ["MyApp"], "", "Doing some work", None),
logging.Message(logging.INFO, ["MyApp"], "", "Bidabopp", {"actor": "MyApp", "thing": "bopp", "number": 42}),
logging.Message(logging.INFO, [], None, "hej", None),
logging.Message(logging.INFO, [], None, "hello", None),
logging.Message(logging.DEBUG, [], None, "dello", None),
logging.Message(logging.INFO, ["MyApp"], None, "Starting up", None),
logging.Message(logging.INFO, ["MyApp"], None, "Doing some work", None),
logging.Message(logging.INFO, ["MyApp"], None, "Bidabopp", {"actor": "MyApp", "thing": "bopp", "number": 42}),
logging.Message(logging.EMERGENCY, ["MyApp", "deepfun", "deepy"], "deepy", "deep emergency", None),
logging.Message(logging.ALERT, ["MyApp", "deepfun", "deepy"], "deepy", "deep alert", None),
logging.Message(logging.CRITICAL, ["MyApp", "deepfun", "deepy"], "deepy", "deep critical", None),
Expand Down
72 changes: 72 additions & 0 deletions test/stdlib_tests/src/test_testing_asserts.act
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

import testing
from testing import NotEqualError

def _test_assert_equal() -> None:
"""Test assertEqual"""

# should raise NotEqualError because 1 != 2
try:
testing.assertEqual(1, 2)
except AssertionError as e:
pass
else:
raise Exception("assertEqual(1, 2) should have raised NotEqualError")

# should raise NotEqualError because 1 != None
try:
testing.assertEqual(1, None)
except AssertionError as e:
pass
else:
raise Exception("assertEqual(1, None) should have raised NotEqualError")

# should raise NotEqualError because None != 1
try:
testing.assertEqual(None, 1)
except AssertionError as e:
pass
else:
raise Exception("assertEqual(None, 1) should have raised NotEqualError")

# should not raise NotEqualError because None == None
try:
testing.assertEqual(None, None)
except AssertionError as e:
raise Exception("assertEqual(None, None) should not have raised NotEqual")

def _test_assert_not_equal() -> None:
"""Test assertNotEqual"""

# should not raise NotEqualError because 1 != 2
try:
testing.assertNotEqual(1, 2)
except AssertionError as e:
raise Exception("assertNotEqual(1, 2) should not have raised NotEqualError")

# should not raise NotEqualError because 1 != None
try:
testing.assertNotEqual(1, None)
except AssertionError as e:
raise Exception("assertNotEqual(1, None) should not have raised NotEqualError")

# should not raise NotEqualError because None != 1
try:
testing.assertNotEqual(None, 1)
except AssertionError as e:
raise Exception("assertNotEqual(None, 1) should not have raised NotEqualError")

# should raise NotEqualError because None == None
try:
testing.assertNotEqual(None, None)
except AssertionError as e:
pass
else:
raise Exception("assertNotEqual(None, None) should have raised NotEqual")

try:
testing.assertNotEqual(1, 1)
except AssertionError as e:
pass
else:
raise Exception("assertNotEqual(1, 1) should have raised NotEqual")
Loading