mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-07 17:03:00 +00:00
Various VM tests
These are largely copied across from Cobalt's test suite, with some
minor tweaks. It actually exposed one bug in Cobalt, which is pretty
nice.
One interesting thing from the coroutine tests, is that Lua 5.4 (and
one assumes 5.2/5.3) doesn't allow yielding from within the error
handler of xpcall - I rather thought it might.
This doesn't add any of the PUC Lua tests yet - I got a little
distracted.
Also:
- Allow skipping "keyword" tests, in the style of busted. This is
implemented on the Java side for now.
- Fix a bug with os.date("%I", _) not being 2 characters wide.
This commit is contained in:
@@ -42,6 +42,8 @@ import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static dan200.computercraft.api.lua.LuaValues.getType;
|
||||
@@ -67,6 +69,12 @@ public class ComputerTestDelegate
|
||||
|
||||
private static final long TIMEOUT = TimeUnit.SECONDS.toNanos( 10 );
|
||||
|
||||
private static final Set<String> SKIP_KEYWORDS = new HashSet<>(
|
||||
Arrays.asList( System.getProperty( "cc.skip_keywords", "" ).split( "," ) )
|
||||
);
|
||||
|
||||
private static final Pattern KEYWORD = Pattern.compile( ":([a-z_]+)" );
|
||||
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private Computer computer;
|
||||
|
||||
@@ -212,18 +220,23 @@ public class ComputerTestDelegate
|
||||
|
||||
void runs( String name, Executable executor )
|
||||
{
|
||||
DynamicNodeBuilder child = children.get( name );
|
||||
int id = 0;
|
||||
while( child != null )
|
||||
{
|
||||
id++;
|
||||
String subName = name + "_" + id;
|
||||
child = children.get( subName );
|
||||
}
|
||||
if( this.executor != null ) throw new IllegalStateException( name + " is leaf node" );
|
||||
if( children.containsKey( name ) ) throw new IllegalStateException( "Duplicate key for " + name );
|
||||
|
||||
children.put( name, new DynamicNodeBuilder( name, executor ) );
|
||||
}
|
||||
|
||||
boolean isActive()
|
||||
{
|
||||
Matcher matcher = KEYWORD.matcher( name );
|
||||
while( matcher.find() )
|
||||
{
|
||||
if( SKIP_KEYWORDS.contains( matcher.group( 1 ) ) ) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DynamicNode build()
|
||||
{
|
||||
return executor == null
|
||||
@@ -233,7 +246,9 @@ public class ComputerTestDelegate
|
||||
|
||||
Stream<DynamicNode> buildChildren()
|
||||
{
|
||||
return children.values().stream().map( DynamicNodeBuilder::build );
|
||||
return children.values().stream()
|
||||
.filter( DynamicNodeBuilder::isActive )
|
||||
.map( DynamicNodeBuilder::build );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user