Example #1
0
 def test_utilities(self):
     self.assertEqual(
         "grep '--max-count' '4' '--regexp' '[a-z][0-9]' 'a.txt'",
         qsh("(@grep ~~max-count 4 ~~regexp '[a-z][0-9]' a.txt)")
     )
     self.assertEqual(
         "gzip '-9' 'a.txt'",
         qsh("(@gzip ~9 a.txt)")
     )
Example #2
0
    def test_logical(self):
        self.assertEqual('1 -eq 2', qsh('(@eq? 1 2)'))
        self.assertEqual('"$A" -gt 2', qsh('(@gt? (@var A) 2)'))
        self.assertNotEqual('"$A" -gt "2"', qsh('(@gtt? "$A" 2)'))
        self.assertEqual("'hello' -eq 'world'", qsh("(@eq? 'hello' 'world')"))
        if_else_qsh = "(@let A 1)(@if-else (@gt? (@var A) 2) "\
                      "(@export X 2) (@export Y 3))"
        if_else_compiled = """
A=1
if [ "$A" -gt 2 ]; then
    export X=2
else
    export Y=3
fi
        """
        self.assertEqual(qsh(if_else_qsh), if_else_compiled.strip())
Example #3
0
 def test_array(self):
     self.assertEqual(
         qsh("(@array (@var A) (@var B))"),
         '("$A" "$B")'
     )
Example #4
0
 def test_operations(self):
     self.assertEqual('$((1 + 1))', qsh('(+ 1 1)'))
Example #5
0
 def test_atom(self):
     self.assertEqual('nil', qsh('(nil)'))
     self.assertEqual('false', qsh('(false)'))
     self.assertEqual('true', qsh('(true)'))
     self.assertEqual('1.1', qsh('(1.1)'))
     self.assertEqual('1', qsh('(1)'))
Example #6
0
    code = """
    (@let a "b")(@let b "C")
    (@let A (* (+ 2 3) (* 2 4)))
    (@let B (* (+ 3 3) (* 4 4)))
    (@tar ~zcpf "archive.tar.gz" "archive")
    (@for a ls (@echo (@var a) (* 2 2)))
    (@let VAR1 (@range 1 10))
    (@let VAR2 'HELLO WORLD!')
    /* This is a raw command */
    (@comment 'a raw command')
    (@raw 'cat myfile.txt | gzip --best - > myfile.txt.gz')
    // Quick Bash comment (C++ style) (will be omitted in the output)
    (@comment 'the following exports a variable named B')
    (@export B "hello world\'")    
    (@pipe (@echo 'hello') (@ssh host1))
    (@if-else (== 1 2) (@echo (@exec 'date')) (@ls ~alr))
    (@if-else 
        (@eq? 1 2) 
            (@let R (@range 2 10)) 
        (@let R (@range 1 5))
    )
    (@if-else 
        (@ne? "$a" "$b") 
            (@let G (@range 2 10)) 
        (@let G (@range 1 5))
    )
    (@let CURRENT_DATETIME (:datetime.datetime.utcnow))
    (@let A_DATETIME (:datetime.datetime.strptime "2014-05-06" "%Y-%m-%d"))
    """
    print qsh(code)