Skip to content

Commit

Permalink
change Execute BIF to SystemExecute
Browse files Browse the repository at this point in the history
  • Loading branch information
jclausen committed Apr 24, 2024
1 parent 71f40d6 commit ea15d8c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@

@BoxBIF

public class Execute extends BIF {
public class SystemExecute extends BIF {

/**
* Constructor
*/
public Execute() {
public SystemExecute() {
super();
// Uncomment and define declare argument to this BIF
declaredArguments = new Argument[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public BodyResult _invoke( IBoxContext context, IStruct attributes, ComponentBod
attributes.put( Key.error, attributes.get( errorFileKey ) );
}

IStruct response = StructCaster.cast( runtime.getFunctionService().getGlobalFunction( Key.execute ).invoke( context, attributes, false, Key.execute ) );
IStruct response = StructCaster.cast( runtime.getFunctionService().getGlobalFunction( Key.systemExecute ).invoke( context, attributes, false, Key.execute ) );

// Set the result(s) back into the page
ExpressionInterpreter.setVariable( context, attributes.getAsString( Key.variable ), response.getAsString( Key.output ) );
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ortus/boxlang/runtime/scopes/Key.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ public class Key implements Comparable<Key>, Serializable {
public static final Key suffix = Key.of( "suffix" );
public static final Key suppressWhiteSpace = Key.of( "suppressWhiteSpace" );
public static final Key system = Key.of( "system" );
public static final Key systemExecute = Key.of( "systemExecute" );
public static final Key target = Key.of( "target" );
public static final Key template = Key.of( "template" );
public static final Key terminate = Key.of( "terminate" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import ortus.boxlang.runtime.types.Struct;
import ortus.boxlang.runtime.util.FileSystemUtil;

public class ExecuteTest {
public class SystemExecuteTest {

static BoxRuntime instance;
IBoxContext context;
Expand Down Expand Up @@ -71,12 +71,12 @@ public void setupEach() {
}
}

@DisplayName( "It tests the BIF Execute with default args" )
@DisplayName( "It tests the BIF SystemExecute with default args" )
@Test
public void testBifExecute() {
instance.executeSource(
"""
result = Execute( "java", "--version" );
result = SystemExecute( "java", "--version" );
""",
context );
assertTrue(
Expand All @@ -100,13 +100,13 @@ public void testBifExecute() {

}

@DisplayName( "It tests the BIF Execute with default args" )
@DisplayName( "It tests the BIF SystemExecute with default args" )
@Test
@Disabled( "Not working on windows: Cannot run program 'echo': CreateProcess error=2, The system cannot find the file specified " )
public void testQuotedStringArgs() {
instance.executeSource(
"""
result = Execute( "echo", "blah 'foo bar baz'" );
result = SystemExecute( "echo", "blah 'foo bar baz'" );
""",
context );
assertTrue(
Expand All @@ -124,12 +124,12 @@ public void testQuotedStringArgs() {

}

@DisplayName( "It tests the BIF Execute with an error" )
@DisplayName( "It tests the BIF SystemExecute with an error" )
@Test
public void testBifError() {
instance.executeSource(
"""
result = Execute( "java", "--blah" );
result = SystemExecute( "java", "--blah" );
""",
context );
assertTrue(
Expand All @@ -151,13 +151,13 @@ public void testBifError() {

}

@DisplayName( "It tests the BIF Execute with output to a file" )
@DisplayName( "It tests the BIF SystemExecute with output to a file" )
@Test
public void testBifFileOutput() {
variables.put( Key.of( "outputFile" ), testTextFile );
instance.executeSource(
"""
result = Execute( name="java", arguments="--version", output=outputFile );
result = SystemExecute( name="java", arguments="--version", output=outputFile );
""",
context );
assertTrue(
Expand Down Expand Up @@ -187,13 +187,13 @@ public void testBifFileOutput() {

}

@DisplayName( "It tests the BIF Execute with output to a file" )
@DisplayName( "It tests the BIF SystemExecute with output to a file" )
@Test
public void testBifFileError() {
variables.put( Key.of( "outputFile" ), testTextFile );
instance.executeSource(
"""
result = Execute( name="java", arguments="--blah", error=outputFile );
result = SystemExecute( name="java", arguments="--blah", error=outputFile );
""",
context );
assertTrue(
Expand Down Expand Up @@ -223,7 +223,7 @@ public void testBifFileError() {

}

@DisplayName( "It tests the BIF Execute with timeout" )
@DisplayName( "It tests the BIF SystemExecute with timeout" )
@Test
public void testBifExecuteWithTimeout() {
// Skipping this whole test block on Windows, for now, as attempting to use timeout from ProcessManager will fail
Expand All @@ -232,7 +232,7 @@ public void testBifExecuteWithTimeout() {
variables.put( Key.of( "cmd" ), FileSystemUtil.IS_WINDOWS ? "timeout" : "sleep" );
instance.executeSource(
"""
result = Execute( cmd, "5", 1 );
result = SystemExecute( cmd, "5", 1 );
""",
context );

Expand All @@ -258,7 +258,7 @@ public void testBifExecuteWithTimeout() {

instance.executeSource(
"""
result = Execute( cmd, "5", 1, true );
result = SystemExecute( cmd, "5", 1, true );
""",
context );
assertTrue(
Expand Down

0 comments on commit ea15d8c

Please sign in to comment.