HeyPuter / phoenix

🔥 Puter's pure-javascript shell
https://puter.com/app/terminal
GNU Affero General Public License v3.0
88 stars 15 forks source link

Add a basic test harness for builtin coreutil functions #25

Closed AtkinsSJ closed 4 months ago

AtkinsSJ commented 4 months ago

This is a first attempt at making our builtins testable. It provides a mock context that lets us pass in parameters and options directly (without running parsing code) and check that the return value, and stdout/stderr outputs are as they should be.

Includes tests for true, false, basename and echo, since those do not touch the filesystem. The echo test is missing coverage for the -e and -E options because as far as I can tell, our echo doesn't perform the interpretation properly, but just skips over the escape sequence, regardless of which options are provided.

AtkinsSJ commented 4 months ago

I'm very unfamiliar with Mocha so I'm probably doing something wrong. In particular, it'd be nice if all the builtins were grouped together, but I couldn't see a way to do that without putting all the tests in the same file, which is awkward.

KernelDeimos commented 4 months ago

I'm very unfamiliar with Mocha so I'm probably doing something wrong. In particular, it'd be nice if all the builtins were grouped together, but I couldn't see a way to do that without putting all the tests in the same file, which is awkward.

I wasn't sure myself but after a quick test it looks like this approach works:

image

AtkinsSJ commented 4 months ago

Thanks! I couldn't directly use require() because we use JS modules, but I've done the equivalent with imports and calling the functions, and that works:

image