Commit Graph

8 Commits

Author SHA1 Message Date
SquidDev a0e7c4a74c Add a little bit of source code checking to Gradle
- Adds a CheckStyle configuration which is pretty similar to CC's
   existing one.
 - Add the Gradle license plugin.
 - Ensure the existing source code is compatible with these additional
   checks.

See #239
2019-06-08 00:28:03 +01:00
hydraz 9048deeb95 Add a function for type-checking arguments (#207)
- Define an expect(index, actual_value, types...) helper function which
   takes an argument index, value and list of permissable types and
   ensures the value is of one of those types.
   If not, it will produce an error message with the expected and actual
   type, as well as the argument number and (if available) the function
   name.
 - Expose expect in the global scope as _G["~expect"], hopefully making
   it clear it is internal.
 - Replace most manual type checks with this helper method.
 - Write tests to ensure this argument validation works as expected

Also fix a couple of bugs exposed by this refactor and the subsequent
tests:
 - Make rednet checks a little more strict - rednet.close(false) is no
   longer valid.
 - Error when attempting to redirect the terminal to itself 
   (term.redirect(term)).
2019-05-30 19:36:28 +01:00
SquidDev 52e1906d42 Add a basic test framework for CraftOS
This runs tests on CraftOS using a tiny test runner that I originally
knocked up for LuaDash. It can be run both from JUnit (so IDEA and
Gradle) and in-game in the shell, so is pretty accessible to work with.

I also add a very basic POC test for the io library. I'd like to flesh
this out soon enough to contain most of the things from the original io
test.
2019-03-10 10:45:25 +00:00
SquidDev eaf24a3ceb Update to JUnit 5
Also display test results within the Gradle build
2019-03-10 09:40:06 +00:00
SquidDev b3e6a53868 Allow pausing Lua machines
TimeoutState now introduces a TIMESLICE, which is the maximum period of
time a computer can run before we will look into pausing it.

When we have executed a task for more than this period, and if there are
other computers waiting to execute work, then we will suspend the
machine.

Suspending the machine sets a flag on the ComputerExecutor, and pauses
the "cumulative" time - the time spent handling this particular event.
When resuming the machine, we restart our timer and resume the machine.
2019-02-28 16:49:06 +00:00
SquidDev 218f8e53bb Further improvements to computer execution
Oh goodness, when will it end?

 - Computer errors are shown in red.

 - Lua machine operations provide whether they succeeded, and an
   optional error message (reason bios failed to load, timeout error,
   another Lua error), which is then shown to the user.

 - Clear the Cobalt "thrown soft abort" flag when resuming, rather than
   every n instructions.

 - Computers will clear their "should start" flag once the time has
   expired, irrespective of whether it turned on or not. Before
   computers would immediately restart after shutting down if the flag
   had been set much earlier.

Errors within the Lua machine are displayed in a more friendly
2019-02-28 15:44:43 +00:00
SquidDev 67af7a698b Migrate the computer tasks into a separate thread
- Move state management (turnOn, shutdown, etc...) event handling and
   the command queue into a ComputerExecutor

 - This means the computer thread now just handles running "work" on
   computer executors, rather than managing a separate command queue +
   requeuing it.
2019-02-26 13:50:09 +00:00
SquidDev c373583723 Add a test which boots a computer and runs forever
Ideally we'd add a couple more tests in the future, but this'll do for
now.

The bootstrap class is largely yoinked from CCTweaks-Lua, so is a tad
ugly. It works though.
2019-02-26 08:44:17 +00:00