diff options
Diffstat (limited to 'src/test/test_cmdline_args.py')
-rwxr-xr-x | src/test/test_cmdline_args.py | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/src/test/test_cmdline_args.py b/src/test/test_cmdline_args.py index 55d1cdb805..57641974db 100755 --- a/src/test/test_cmdline_args.py +++ b/src/test/test_cmdline_args.py @@ -49,22 +49,25 @@ def contents(fn): finally: f.close() -def run_tor(args, failure=False): - p = subprocess.Popen([TOR] + args, stdout=subprocess.PIPE) - output, _ = p.communicate() +def run_tor(args, failure=False, stdin=None): + kwargs = {} + if stdin != None: + kwargs['stdin'] = subprocess.PIPE + p = subprocess.Popen([TOR] + args, stdout=subprocess.PIPE, **kwargs) + output, _ = p.communicate(input=stdin) result = p.poll() if result and not failure: raise UnexpectedFailure() elif not result and failure: raise UnexpectedSuccess() - return b2s(output) + return b2s(output.replace('\r\n','\n')) def spaceify_fp(fp): for i in range(0, len(fp), 4): yield fp[i:i+4] def lines(s): - out = s.split("\n") + out = s.splitlines() if out and out[-1] == '': del out[-1] return out @@ -151,7 +154,7 @@ class CmdlineTests(unittest.TestCase): if os.stat(TOR).st_mtime < os.stat(main_c).st_mtime: self.skipTest(TOR+" not up to date") out = run_tor(["--digests"]) - main_line = [ l for l in lines(out) if l.endswith("/main.c") ] + main_line = [ l for l in lines(out) if l.endswith("/main.c") or l.endswith(" main.c") ] digest, name = main_line[0].split() f = open(main_c, 'rb') actual = hashlib.sha1(f.read()).hexdigest() @@ -234,20 +237,26 @@ class CmdlineTests(unittest.TestCase): def test_cmdline_args(self): default_torrc = NamedTemporaryFile() torrc = NamedTemporaryFile() - torrc.write("SocksPort 9999\n") - torrc.write("SocksPort 9998\n") - torrc.write("ORPort 9000\n") - torrc.write("ORPort 9001\n") - torrc.write("Nickname eleventeen\n") - torrc.write("ControlPort 9500\n") - torrc.close() + contents = ("SocksPort 9999\n" + "SocksPort 9998\n" + "ORPort 9000\n" + "ORPort 9001\n" + "Nickname eleventeen\n" + "ControlPort 9500\n") + torrc.write(contents) default_torrc.write("") default_torrc.close() + torrc.close() out_sh = out_nb = out_fl = None + + opts_stdin = [ "-f", "-", + "--defaults-torrc", default_torrc.name, + "--dump-config", "short" ] opts = [ "-f", torrc.name, "--defaults-torrc", default_torrc.name, "--dump-config", "short" ] try: + out_0 = run_tor(opts_stdin,stdin=contents) out_1 = run_tor(opts) out_2 = run_tor(opts+["+ORPort", "9003", "SocksPort", "9090", @@ -258,9 +267,18 @@ class CmdlineTests(unittest.TestCase): os.unlink(torrc.name) os.unlink(default_torrc.name) + out_0 = [ l for l in lines(out_0) if not l.startswith("DataDir") ] out_1 = [ l for l in lines(out_1) if not l.startswith("DataDir") ] out_2 = [ l for l in lines(out_2) if not l.startswith("DataDir") ] + self.assertEqual(out_0, + ["ControlPort 9500", + "Nickname eleventeen", + "ORPort 9000", + "ORPort 9001", + "SocksPort 9999", + "SocksPort 9998"]) + self.assertEqual(out_1, ["ControlPort 9500", "Nickname eleventeen", @@ -268,6 +286,7 @@ class CmdlineTests(unittest.TestCase): "ORPort 9001", "SocksPort 9999", "SocksPort 9998"]) + self.assertEqual(out_2, ["ExtORPort 9005", "Nickname eleventeen", |