Skip to content

Commit

Permalink
test/objects: 10% progress
Browse files Browse the repository at this point in the history
  • Loading branch information
abesto committed Feb 2, 2025
1 parent db91618 commit ea45f18
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 53 deletions.
2 changes: 0 additions & 2 deletions crates/kernel/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ pub mod scheduler_test_utils {
player: &Obj,
command: &str,
) -> Result<Var, SchedulerError> {
eprintln!("call_command: {}", command);
execute(|| scheduler.submit_command_task(&SYSTEM_OBJECT, player, command, session))
}

Expand All @@ -306,7 +305,6 @@ pub mod scheduler_test_utils {
player: &Obj,
code: String,
) -> Result<Var, SchedulerError> {
eprintln!("call_eval: {}", code);
execute(|| {
scheduler.submit_eval_task(player, player, code, session, FeaturesConfig::default())
})
Expand Down
6 changes: 5 additions & 1 deletion crates/kernel/src/tasks/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,11 @@ impl Task {
return None;
};

warn!(task_id = self.task_id, "Task exception");
warn!(
task_id = self.task_id,
msg = exception.msg,
"Task exception"
);
self.vm_host.stop();

task_scheduler_client.exception(exception);
Expand Down
79 changes: 44 additions & 35 deletions crates/kernel/testsuite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,49 @@ This is mostly a port of (part of) the regression suite bundled with Stunt MOO:

https://github.com/toddsundsted/stunt/tree/master/test

| Status | `stunt` test(s) | `moor` test(s) | Notes |
| ------ | ---------------------------------------------- | ------------------------ | ------------------------------------------------------------------------------------------- |
|| `test_algorithms.rb` | `algorithms.moot` | `stunt` added multiple hashing algorithms (not supported in `moor`). Fuzz tests not ported. |
| 🚫 | `test_anonymous.rb` | N/A | `moor` doesn't support anonymous objects. |
|| `test_basic.rb`, `basic/*` | `basic/*.moot` | |
| 🔜 | `test_canned_dbs.rb` | N/A | |
| 🤔 | `test_collection_improvements.rb` | N/A | Are these tests valuable / relevant for `moor`? |
|| `test_create.rb` | `create.moot` | |
|| `test_equality.rb` | `equality.moot` | |
|| `test_eval.rb` | `eval/*.moot` | |
| 🚫 | `test_exec.rb` | N/A | `moor` doesn't support this Stunt extension. |
| 🚫 | `test_fileio.rb` | N/A | `moor` doesn't support this Stunt extension. |
| 🚫 | `test_garbage_collection.rb` | N/A | `moor` doesn't support this Stunt extension. |
| 🚫 | `test_http.rb` | N/A | `moor` doesn't support this Stunt extension. |
|| `test_huh.rb` | `huh.moot` | See also `huh` test in the `telnet-host` crate. |
| 🚫 | `test_index_and_range_extensions.rb` | N/A | `moor` doesn't support this Stunt extension. |
| 🚫 | `test_json.rb` | N/A | `moor` doesn't support this Stunt extension. |
| 🔜 | `test_limits.rb` | N/A | |
|| `test_looping.rb` | `looping.moot` | |
||`test_map.rb` | `map.moot` | |
|| `test_math.rb` | `math.moot` | |
| 🚫 | `test_miscellaneous.rb` | N/A | `moor` doesn't support this Stunt extension (`isa`) |
|| `test_moocode_parsing.rb` | N/A | Dropped tests for Stunt extensions (`^` collection, bitwise operators) |
| 🔜 | `test_objects.rb` | N/A | |
| 🔜 | `test_objects_and_properties.rb` | N/A | |
| 🔜 | `test_objects_and_verbs.rb` | N/A | |
| 🔜 | `test_primitives.rb` | N/A | |
|| `test_recycle.rb` | `recycle.moot` | |
| 🔜 | `test_stress_objects.rb` | N/A | |
|| `test_string_operations.rb` | `string_operations.moot` | Extended with cases based on LambdaMOO Programmer's Manual |
| 🚫 | `test_switch_player.rb` | N/A | `moor` doesn't support this Stunt extension. |
| 🚫 | `test_system_builtins.rb` | N/A | `moor` doesn't support this Stunt extension (`getenv`). |
| 🔜 | `test_task_local.rb` | N/A | |
| 🔜 | `test_things_that_used_to_crash_the_server.rb` | N/A | Probably useful to test these, since they were tricky for another server at somepoint |
| 🚫 | `test_verb_cache.rb` | N/A | `moor` doesn't support this Stunt extension. |
| Status | `stunt` test(s) | `moor` test(s) | Notes |
| ------ | ---------------------------------------------- | ---------------------------- | ------------------------------------------------------------------------------------------- |
|| `test_algorithms.rb` | `algorithms.moot` | `stunt` added multiple hashing algorithms (not supported in `moor`). Fuzz tests not ported. |
| 🚫 | `test_anonymous.rb` | N/A | `moor` doesn't support anonymous objects. |
|| `test_basic.rb`, `basic/*` | `basic/*.moot` | |
| 🔜 | `test_canned_dbs.rb` | N/A | |
| 🤔 | `test_collection_improvements.rb` | N/A | Are these tests valuable / relevant for `moor`? |
|| `test_create.rb` | `create.moot` | |
|| `test_equality.rb` | `equality.moot` | |
|| `test_eval.rb` | `eval/*.moot` | |
| 🚫 | `test_exec.rb` | N/A | `moor` doesn't support this Stunt extension. |
| 🚫 | `test_fileio.rb` | N/A | `moor` doesn't support this Stunt extension. |
| 🚫 | `test_garbage_collection.rb` | N/A | `moor` doesn't support this Stunt extension. |
| 🚫 | `test_http.rb` | N/A | `moor` doesn't support this Stunt extension. |
|| `test_huh.rb` | `huh.moot` | See also `huh` test in the `telnet-host` crate. |
| 🚫 | `test_index_and_range_extensions.rb` | N/A | `moor` doesn't support this Stunt extension. |
| 🚫 | `test_json.rb` | N/A | `moor` doesn't support this Stunt extension. |
| 🔜 | `test_limits.rb` | N/A | |
|| `test_looping.rb` | `looping.moot` | |
||`test_map.rb` | `map.moot` | |
|| `test_math.rb` | `math.moot` | |
| 🚫 | `test_miscellaneous.rb` | N/A | `moor` doesn't support this Stunt extension (`isa`) |
|| `test_moocode_parsing.rb` | N/A | Dropped tests for Stunt extensions (`^` collection, bitwise operators) |
| 🚧 | `test_objects.rb` | `objects/{test_method}.moot` | See `test_objects` heading below |
| 🔜 | `test_objects_and_properties.rb` | N/A | |
| 🔜 | `test_objects_and_verbs.rb` | N/A | |
| 🔜 | `test_primitives.rb` | N/A | |
|| `test_recycle.rb` | `recycle.moot` | |
| 🔜 | `test_stress_objects.rb` | N/A | |
|| `test_string_operations.rb` | `string_operations.moot` | Extended with cases based on LambdaMOO Programmer's Manual |
| 🚫 | `test_switch_player.rb` | N/A | `moor` doesn't support this Stunt extension. |
| 🚫 | `test_system_builtins.rb` | N/A | `moor` doesn't support this Stunt extension (`getenv`). |
| 🔜 | `test_task_local.rb` | N/A | |
| 🔜 | `test_things_that_used_to_crash_the_server.rb` | N/A | Probably useful to test these, since they were tricky for another server at somepoint |
| 🚫 | `test_verb_cache.rb` | N/A | `moor` doesn't support this Stunt extension. |

`.moot` files not mentioned above are not related to Stunt.

## `test_objects`

- `moor` doesn't support multiple inheritence.
- Stunt changes how `create()` behaves when arguments are not a valid object reference. `moor` follows the LambdaMOO behavior.
- https://github.com/toddsundsted/stunt/blob/e83e946/test/test_objects.rb#L65-L75
- https://github.com/toddsundsted/stunt/blob/e83e946/test/test_objects.rb#L84-L94
- https://github.com/toddsundsted/stunt/blob/e83e946/test/test_objects.rb#L106-L111
- https://github.com/toddsundsted/stunt/blob/e83e946/test/test_objects.rb#L164-L169
62 changes: 62 additions & 0 deletions crates/kernel/testsuite/moot/objects/test_create.moot
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Adapted from https://github.com/toddsundsted/stunt/blob/e83e946/test/test_objects.rb
// def test_create

@wizard
; add_property($system, "a", create($nothing), {$wizard_player, "rwc"});
; add_property($system, "b", create($a), {$wizard_player, "rwc"});
; add_property($system, "c", create($b, $nothing), {$wizard_player, "rwc"});
; add_property($system, "d", create($b, $a), {$wizard_player, "rwc"});

// test that `parent()' works for single inheritance hierarchies
; return parent($a);
$nothing
; return parent($b);
$a
; return parent($c);
$b
; return parent($c);
$b

// test that `children()' works for single inheritance hierarchies
; return children($a);
{$b}
; return children($b);
{$c, $d}
; return children($c);
{}
; return children($d);
{}

// test that create sets the owner correctly
; return $a.owner;
$wizard_player
; return $b.owner;
$wizard_player
; return $c.owner;
$c
; return $d.owner;
$a

; add_property($system, "e", create($nothing, $nothing), {$wizard_player, "rwc"});
; add_property($system, "f", create($nothing, $ambiguous_match), {$wizard_player, "rwc"});
; add_property($system, "g", create($nothing, $failed_match), {$wizard_player, "rwc"});
; add_property($system, "h", create($nothing, $invalid_object), {$wizard_player, "rwc"});

; return $e.owner;
$e
; return $f.owner;
// TODO: for $f.owner LMOO returns the object we passed in, we get E_INVIND instead.
// We get E_INVIND from the default branch of `get_property()` in `vm/moo_execute.rs'
// Stunt returns E_INVARG.
E_INVIND
; return $g.owner;
$failed_match
; return $h.owner;
$invalid_object

@programmer
// TODO: these should all fail with E_PERM, but they currently pass
; create($nothing, $nothing);
; create($nothing, $ambiguous_match);
; create($nothing, $failed_match);
; create($nothing, $invalid_object);
72 changes: 72 additions & 0 deletions crates/kernel/testsuite/moot/objects/test_create_errors.moot
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Adapted from https://github.com/toddsundsted/stunt/blob/e83e946/test/test_objects.rb
// def test_create_errors

@wizard
; create();
E_ARGS
; return create(1);
E_TYPE
; return create("1");
E_TYPE
; return create(1, 2);
E_TYPE
; return create($object, "2");
E_TYPE

// TODO: these three should all fail with E_PERM, but they currently pass
& create($ambiguous_match);
& create($failed_match);
& create($invalid_object);

; return create({1});
E_TYPE
; return create({"1"});
E_TYPE
; return create({$nothing});
E_TYPE
; return create({$ambiguous_match});
E_TYPE
; return create({$failed_match});
E_TYPE
; return create({$invalid_object});
E_TYPE

// A variety of tests that check permissions.

; add_property($system, "a", create($nothing), {$wizard_player, "rwc"});
; add_property($system, "b", create($a, $a), {$wizard_player, "rwc"});
; $b.f = 1;
; return $a.owner;
$wizard_player
; return $b.owner;
$a

@programmer
; create($a);
E_PERM
// TODO this three should fail with E_PERM, but currently passes
& create($b, $invalid_object);
& create($b, $wizard_player);
& create($b, $nothing);

; return valid(create($b));
1

; add_property($system, "c", create($nothing), {$programmer_player, ""});
; add_property($system, "d", create($b, $programmer_player), {$programmer_player, "rwc"});
; $d.f = 1;

; return $c.owner;
$programmer_player
; return $d.owner;
$programmer_player

@wizard
; return valid(create($a));
1
; return valid(create($b, $wizard_player));
1
; return valid(create($c, $programmer_player));
1
; return valid(create($d));
1
2 changes: 0 additions & 2 deletions crates/kernel/testsuite/moot/single.moot

This file was deleted.

2 changes: 1 addition & 1 deletion crates/kernel/testsuite/moot_suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,5 @@ fn test(db: Box<dyn Database>, path: &Path) {
fn test_single() {
// cargo test -p moor-kernel --test moot-suite test_single -- --ignored
// CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --test moot-suite -- test_single --ignored
test_with_db(&testsuite_dir().join("moot/create.moot"));
test_with_db(&testsuite_dir().join("moot/objects/test_create_errors.moot"));
}
49 changes: 39 additions & 10 deletions crates/testing/moot/Test.db
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#0
System Object

16
48
3
-1
-1
Expand All @@ -22,14 +22,20 @@ do_login_command
3
173
-1
6
12
nothing
tmp
tmp1
tmp2
system
object
6
invalid_object
ambiguous_match
failed_match
programmer_player
wizard_player
player
12
1
-1
3
Expand All @@ -54,6 +60,30 @@ object
-1
3
7
1
2147483647
3
7
1
-2
3
7
1
-3
3
7
1
4
3
7
1
3
3
7
1
5
3
7
#1
Root Class

Expand Down Expand Up @@ -130,21 +160,20 @@ nonprogrammer
0
#0:0
if (length(args) >= 2)
return eval("return " + args[2] + ";")[2];
return eval(("return " + args[2]) + ";")[2];
else
return player;
return player;
endif
.
#2:0
set_task_perms(player);
try
notify(player, toliteral(eval(argstr + ";")[2]));
except err (ANY)
notify(player, toliteral(err[1]));
notify(player, toliteral(eval(argstr + ";")[2]));
except ERR (ANY)
notify(player, toliteral(ERR[1]));
endtry
.
0 clocks
0 queued tasks
0 suspended tasks
1 active connections with listeners
3 0
0 active connections with listeners
8 changes: 7 additions & 1 deletion crates/testing/moot/Test.db.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ Notable objects:
- `#4`: programmer player
- `#5`: non-programmer player

Globals:
Corified globals:

- `$nothing`: `#-1`
- `$ambiguous_match`: `#-2`
- `$failed_match`: `#-3`
- `$system`: `#0`
- `$wizard_player`: `#3`
- `$programmer_player`: `#4`
- `$player`: `#5`
- `$object`, `$tmp`, `$tmp1`, `$tmp2`: for use as variables that persist across commands
- `$invalid_object`: `toobj(2142147483647)`

Verbs:

Expand Down
Loading

0 comments on commit ea45f18

Please sign in to comment.