package brooklyn.util.os;

import static org.testng.Assert.assertEquals;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.Test;

@Test
public class OsTest {

    private static final Logger log = LoggerFactory.getLogger(OsTest.class);
    
    public void testTmp() {
        log.info("tmp dir is: "+Os.tmp());
        Assert.assertNotNull(Os.tmp());
    }
    
    public void testHome() {
        log.info("home dir is: "+Os.home());
        Assert.assertNotNull(Os.home());        
    }
    
    public void testUser() {
        log.info("user name is: "+Os.user());
        Assert.assertNotNull(Os.user());        
    }

    public void testTidyFilePath() throws Exception {
        String userhome = System.getProperty("user.home");
        assertEquals(Os.tidyPath("/a/b"), "/a/b");
        assertEquals(Os.tidyPath("~/a/b"), userhome+"/a/b");
    }
    
    public void testMergePaths() throws Exception {
        assertEquals(Os.mergePaths("a"), "a"); 
        assertEquals(Os.mergePaths("a", "b"), "a/b"); 
        assertEquals(Os.mergePaths("a/", "b"), "a/b");
        assertEquals(Os.mergePaths("a", "b/"), "a/b/");
        assertEquals(Os.mergePaths("/a", "b"), "/a/b");
    }

}

@@ -187,16 +187,64 @@
 .Test;%0A%0A
+import com.google.common.collect.ImmutableSet;%0A%0A
 @Test%0Apu
@@ -761,16 +761,884 @@
 Tidy
-File
 Path
+Canonicalize() throws Exception %7B%0A        for (String path : ImmutableSet.of(%22/a/b%22, %22//a///b%22, %22/a/b/%22, %22/a/b/.%22, %22/q/../a/b%22)) %7B%0A            assertEquals(Os.tidyPath(path), %22/a/b%22);%0A        %7D%0A    %7D%0A%0A    public void testTidyPathSimplify() throws Exception %7B%0A        assertEquals(Os.tidyPath(%22x/y/z%22), %22x/y/z%22);%0A        assertEquals(Os.tidyPath(%22%22), %22.%22);%0A        assertEquals(Os.tidyPath(%22.%22), %22.%22);%0A        assertEquals(Os.tidyPath(%22..%22), %22..%22);%0A        assertEquals(Os.tidyPath(%22./x%22), %22x%22);%0A        assertEquals(Os.tidyPath(%22../x%22), %22../x%22);%0A        assertEquals(Os.tidyPath(%22/..%22), %22/%22);%0A        assertEquals(Os.tidyPath(%22x%22), %22x%22);%0A        assertEquals(Os.tidyPath(%22/%22), %22/%22);%0A        assertEquals(Os.tidyPath(%22///%22), %22/%22);%0A        assertEquals(Os.tidyPath(%22/x%5C%5C%22), %22/x%5C%5C%22);%0A        assertEquals(Os.tidyPath(%22/x%5C%5Cy/..%22), %22/%22);%0A    %7D%0A%0A    public void testTidyPathHome
 () t
@@ -1748,24 +1748,25 @@
 dyPath(%22
+~
 /a/b%22), 
 %22/a/b%22);
@@ -1753,24 +1753,33 @@
 h(%22~/a/b%22), 
+userhome+
 %22/a/b%22);%0A   
@@ -1802,36 +1802,32 @@
 s(Os.tidyPath(%22~
-/a/b
 %22), userhome+%22/a
@@ -1814,36 +1814,84 @@
 h(%22~%22), userhome
-+%22/a
+);%0A        assertEquals(Os.tidyPath(%22/a/~/b%22), %22/a/~
 /b%22);%0A    %7D%0A    

Add more comprehensive tidyPath unit tests