#!/bin/sh
"""": # -*-python-*-
bup_python="$(dirname "$0")/../config/bin/python" || exit $?
exec "$bup_python" "$0" ${1+"$@"}
"""
# end of bup preamble

from __future__ import absolute_import, print_function

from os.path import abspath, dirname
from random import randint
from subprocess import check_output
from sys import stderr, stdout
import sys

script_home = abspath(dirname(__file__))
sys.path[:0] = [abspath(script_home + '/../lib'), abspath(script_home + '/..')]

from wvtest import wvcheck, wvfail, wvmsg, wvpass, wvpasseq, wvpassne, wvstart

wvstart('command line arguments are not mangled')

def rand_bytes(n):
    return bytes([randint(1, 255) for x in range(n)])

for trial in range(100):
    cmd = [b't/echo-argv-bytes', rand_bytes(randint(1, 32))]
    out = check_output(cmd)
    wvpasseq(b'\0\n'.join(cmd) + b'\0\n', out)
