Skip to content

Commit

Permalink
FORGE-1009: SetPlugin now removes variable if no value is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jul 11, 2013
1 parent 1d73f9c commit fb8d057
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ public void run(@Option(description = "varname",
}
else
{
forge.setProperty(variable, Echo.tokensToString(value));
if (value == null)
{
forge.removeProperty(variable);
}
else
{
forge.setProperty(variable, Echo.tokensToString(value));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.shell.plugins.builtin;

import org.jboss.forge.test.AbstractShellTest;
import org.junit.Assert;
import org.junit.Test;

public class SetPluginTest extends AbstractShellTest
{

@Test
public void testSetProperty() throws Exception
{
getShell().execute("set");
Assert.assertFalse(getOutput().contains("ABC=avalue"));
getShell().execute("set ABC avalue");
getShell().execute("set");
Assert.assertTrue(getOutput().contains("ABC=avalue"));
}

@Test
public void testRemoveProperty() throws Exception
{
getShell().execute("set ABC avalue");
getShell().execute("set");
Assert.assertTrue(getOutput().contains("ABC=avalue"));
resetOutput();
getShell().execute("set ABC");
getShell().execute("set");
Assert.assertFalse(getOutput().contains("ABC=avalue"));
}
}

0 comments on commit fb8d057

Please sign in to comment.