#!/usr/bin/env python

from nose.tools import *
from subprocess import Popen, PIPE, STDOUT
import os

import os, sys, glob, mapnik

def test_mapnik_config_no_args():
    process = Popen('mapnik-config', shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
    result = process.communicate()
    eq_(process.returncode,1)
    eq_('Usage: mapnik-config ' in result[0],True)
    eq_(result[1],'')

def test_mapnik_config_help():
    process = Popen('mapnik-config --help', shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
    result = process.communicate()
    eq_(process.returncode,0)
    eq_('Usage: mapnik-config ' in result[0],True)
    eq_(result[1],'')

def test_mapnik_config_help_short():
    process = Popen('mapnik-config -h', shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
    result = process.communicate()
    eq_(process.returncode,0)
    eq_('Usage: mapnik-config ' in result[0],True)
    eq_(result[1],'')

def test_mapnik_config_valid_opts():
    valid_args = [
      '-h',
      '--help',
      '-v',
      '--version',
      '--version-number',
      '--git-revision',
      '--git-describe',
      '--fonts',
      '--input-plugins',
      '--defines',
      '--prefix',
      '--lib-name',
      '--libs',
      '--dep-libs',
      '--ldflags',
      '--includes',
      '--dep-includes',
      '--cxxflags',
      '--cflags',
      '--all-flags',
      '--cxx'
    ]
    for item in valid_args:
        cmd = 'mapnik-config ' + item
        process = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        result = process.communicate()
        eq_(process.returncode,0)
        eq_(len(result[0]) > 1,True,cmd)
        eq_(result[1],'')

def test_mapnik_config_invalid_option():
    cmd = 'mapnik-config --invalid-does-not-exist'
    process = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
    result = process.communicate()
    eq_(process.returncode,0)
    eq_(result[0],'')
    eq_(result[1],'unknown option --invalid-does-not-exist\n')

def test_mapnik_config_valid_and_invalid_option():
    cmd = 'mapnik-config --libs --invalid-does-not-exist'
    process = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
    result = process.communicate()
    eq_(process.returncode,0)
    eq_('-lmapnik' in result[0],True)
    eq_(result[1],'unknown option --invalid-does-not-exist\n')

if __name__ == "__main__":
    [eval(run)() for run in dir() if 'test_' in run]

@@ -285,38 +285,8 @@
 e()%0A
-    eq_(process.returncode,1)%0A
     
@@ -345,32 +345,62 @@
 q_(result%5B1%5D,'')
+%0A    eq_(process.returncode,1)
 %0A%0Adef test_mapni
@@ -549,38 +549,8 @@
 e()%0A
-    eq_(process.returncode,0)%0A
     
@@ -609,32 +609,62 @@
 q_(result%5B1%5D,'')
+%0A    eq_(process.returncode,0)
 %0A%0Adef test_mapni
@@ -815,38 +815,8 @@
 e()%0A
-    eq_(process.returncode,0)%0A
     
@@ -875,32 +875,62 @@
 q_(result%5B1%5D,'')
+%0A    eq_(process.returncode,0)
 %0A%0Adef test_mapni
@@ -1916,16 +1916,24 @@
 esult%5B0%5D
+.strip()
 ,'')%0A   
@@ -1938,32 +1938,40 @@
    eq_(result%5B1%5D
+.strip()
 ,'unknown option
@@ -1991,26 +1991,24 @@
 es-not-exist
-%5Cn
 ')%0A%0Adef test
@@ -2230,41 +2230,9 @@
 eq_(
-process.returncode,0)%0A    eq_('-l
+'
 mapn
@@ -2271,16 +2271,24 @@
 esult%5B1%5D
+.strip()
 ,'unknow
@@ -2324,11 +2324,39 @@
 xist
-%5Cn'
+')%0A    eq_(process.returncode,0
 )%0A%0Ai

make the mapnik-config test slightly more cross platform