View Javadoc

1   /***
2    * Copyright (C) 2009, Gajo Csaba
3    *
4    * This file is free software; the author gives unlimited 
5    * permission to copy and/or distribute it, with or without
6    * modifications, as long as this notice is preserved.
7    * 
8    * For more information read the LICENSE file that came
9    * with this distribution. 
10   */
11  package net.sourceforge.makefileparser.test.objects;
12  
13  import net.sourceforge.makefileparser.managers.EnvManager;
14  import net.sourceforge.makefileparser.managers.VariableManager;
15  import net.sourceforge.makefileparser.objects.Command;
16  import net.sourceforge.makefileparser.objects.Variable;
17  import junit.framework.TestCase;
18  
19  /***
20   * @author cgajo
21   *
22   */
23  public class CommandTest extends TestCase {
24  
25  	private EnvManager envManager;
26  	private VariableManager varManager;
27  	
28  	protected void setUp() throws Exception {
29  		super.setUp();
30  		varManager = new VariableManager();
31  		varManager.addNew(new Variable("aaa", "~/stuff/"));
32  		varManager.addNew(new Variable("bbb", "$(aaa)-xxx"));
33  		varManager.addNew(new Variable("ccc", "hello $(ddd)!"));
34  		varManager.addNew(new Variable("ddd", "csaba"));
35  		varManager.addNew(new Variable("xxx", "xxx"));
36  		
37  		envManager = EnvManager.get();
38  		envManager.setProperty("HOME", "/home/cgajo");
39  	}
40  	
41  	public void testHomeDir() {
42  		Command comm = new Command("~/ls");
43  		comm.expandVariables(varManager);
44  		assertEquals("/home/cgajo/ls", comm.getValue());
45  	}
46  	
47  	public void testVariables1() {
48  		Command comm = new Command("cd $(aaa)");
49  		comm.expandVariables(varManager);
50  		assertEquals("cd /home/cgajo/stuff/", comm.getValue());
51  	}
52  	
53  	public void testVariables2() {
54  		Command comm = new Command("$($(xxx))");
55  		comm.expandVariables(varManager);
56  		assertEquals("xxx", comm.getValue());
57  	}
58  	
59  	public void testVariables3() {
60  		Command comm = new Command("echo $(ccc)");
61  		comm.expandVariables(varManager);
62  		assertEquals("echo hello csaba!", comm.getValue());
63  	}
64  }