Ejemplo n.º 1
0
        public void Cmd_UnexistentAppTest()
        {
            var p = new TestProcess("gsudo --debug qaqswswdewfwerferfwe");

            p.WaitForExit();
            Assert.AreNotEqual(0, p.ExitCode, p.GetStdOut());
            Assert.AreNotEqual(0, 999, p.GetStdOut());
        }
Ejemplo n.º 2
0
        public void Cmd_BatchFileWithoutExtensionTest()
        {
            File.WriteAllText("HelloWorld.bat", "@echo Hello");

            var p = new TestProcess("gsudo --debug HelloWorld");

            p.WaitForExit();
            Assert.IsTrue(p.GetStdOut().Contains("Hello\r\n"), p.GetStdOut());
            Assert.AreEqual(0, p.ExitCode);
        }
Ejemplo n.º 3
0
        public void Cmd_ChangeDirTest()
        {
            // TODO: Test --raw, --vt, --attached
            var testDir = Environment.CurrentDirectory;
            var p1      = new TestProcess("gsudo.exe", "cmd /c cd");

            p1.WaitForExit();

            var otherDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, ".."));

            Environment.CurrentDirectory = otherDir;

            Assert.AreEqual(string.Empty, p1.GetStdErr());
            Assert.AreEqual($"{testDir}\r\n", p1.GetStdOut());
            Assert.AreEqual(0, p1.ExitCode);

            try
            {
                var p2 = new TestProcess(Path.Combine(testDir, "gsudo.exe"), "cmd /c cd");
                p2.WaitForExit();

                Assert.AreEqual(string.Empty, p2.GetStdErr());
                Assert.AreEqual($"{otherDir}\r\n", p2.GetStdOut());
                Assert.AreEqual(0, p2.ExitCode);
            }
            finally
            {
                Environment.CurrentDirectory = testDir;
            }
        }
Ejemplo n.º 4
0
        public void Cmd_DirTest()
        {
            var p = new TestProcess("gsudo cmd /c dir");

            p.WaitForExit();
            Assert.IsTrue(p.GetStdOut().Contains(" bytes free"));
            Assert.AreEqual(0, p.ExitCode);
        }
Ejemplo n.º 5
0
        public void Cmd_EchoSimpleQuotesTest()
        {
            var p = new TestProcess("gsudo.exe", "cmd /c echo 1 \'2 3\'");

            p.WaitForExit();
            Assert.AreEqual("1 \'2 3\'\r\n", p.GetStdOut());
            Assert.AreEqual(0, p.ExitCode);
        }
Ejemplo n.º 6
0
        public void Cmd_EchoSimpleQuotesTest()
        {
            var p = new TestProcess("gsudo cmd /c echo 1 \'2 3\'");

            p.WaitForExit();
            p.GetStdOut().AssertHasLine("1 \'2 3\'");
            Assert.AreEqual(0, p.ExitCode);
        }
Ejemplo n.º 7
0
        public void PS_CommandLineEchoDoubleQuotesTest()
        {
            var p = new TestProcess("gsudo", "powershell -command echo 1 '\\\"2 3\\\"'");

            p.WaitForExit();
            Assert.AreEqual("1\r\n\"2 3\"\r\n", p.GetStdOut());
            Assert.AreEqual(0, p.Process.ExitCode);
        }
Ejemplo n.º 8
0
        public void Cmd_ExitCodeTest()
        {
            var p = new TestProcess("gsudo.exe", "--loglevel none exit /b 12345");

            p.WaitForExit();
            Assert.AreEqual(string.Empty, p.GetStdErr());
            Assert.AreEqual(string.Empty, p.GetStdOut());
            Assert.AreEqual(12345, p.ExitCode);
        }
Ejemplo n.º 9
0
        public void Cmd_DirTest()
        {
            var p = new TestProcess("gsudo.exe", "--debug cmd /c dir");

            p.WaitForExit();
            Assert.AreNotEqual(string.Empty, p.GetStdErr());
            Assert.IsTrue(p.GetStdOut().Contains(" bytes free"));
            Assert.AreEqual(0, p.ExitCode);
        }
Ejemplo n.º 10
0
        public void Cmd_CommandLineAppNoWaitTest()
        {
            // ping should take 20 seconds
            var p = new TestProcess("gsudo.exe", "-n ping 127.0.0.1 -n 20");

            // but gsudo should exit immediately.
            p.WaitForExit(2000);
            Assert.AreEqual(string.Empty, p.GetStdOut());
        }
Ejemplo n.º 11
0
        public void PS_CommandLineEchoDoubleQuotesTest()
        {
            var p = new TestProcess("gsudo powershell -noprofile -NoLogo -command echo 1 '\\\"2 3\\\"'");

            p.WaitForExit();
            p.GetStdOut()
            .AssertHasLine("1")
            .AssertHasLine("\"2 3\"");
            Assert.AreEqual(0, p.ExitCode);
        }
Ejemplo n.º 12
0
        public void Cmd_BatchFileWithoutExtensionTest()
        {
            File.WriteAllText("HelloWorld.bat", "@echo Hello");

            var p = new TestProcess("gsudo.exe", "HelloWorld");

            p.WaitForExit();
            Assert.AreEqual(string.Empty, p.GetStdErr());
            Assert.AreEqual("Hello\r\n", p.GetStdOut());
            Assert.AreEqual(0, p.ExitCode);
        }
Ejemplo n.º 13
0
        public virtual void PS_EchoDoubleQuotesTest()
        {
            var p = new TestProcess(
                $@"{PS_FILENAME} {PS_ARGS}
./gsudo 'echo 1 \""2 3\""'
exit");

            p.WaitForExit();
            p.GetStdOut()
            .AssertHasLine("1")
            .AssertHasLine("2 3")
            ;
            Assert.AreEqual(0, p.ExitCode);
        }
Ejemplo n.º 14
0
        public void Cmd_WindowsAppWithQuotesTest()
        {
            var p = new TestProcess("gsudo \"c:\\Program Files (x86)\\Windows NT\\Accessories\\wordpad.exe\"");

            try
            {
                p.WaitForExit();
                Assert.AreEqual(0, p.ExitCode, $"Output was: {p.GetStdOut()}");
            }
            finally
            {
                Process.Start("gsudo", "taskkill.exe /IM Wordpad.exe").WaitForExit();
            }
        }
Ejemplo n.º 15
0
        public void Cmd_WindowsAppNoWaitTest()
        {
            var p = new TestProcess("gsudo.exe", "notepad");

            try
            {
                p.WaitForExit();
            }
            finally
            {
                Process.Start("C:\\Windows\\sysnative\\tskill.exe", "notepad").WaitForExit();
            }
            Assert.AreEqual(string.Empty, p.GetStdErr());
            Assert.AreEqual(string.Empty, p.GetStdOut());
        }
Ejemplo n.º 16
0
        public void PS_EchoNoQuotesTest()
        {
            var p = new TestProcess(PS_FILENAME, PS_ARGS);

            p.WriteInput("./gsudo 'echo 1 2 3'\r\n");
            p.WriteInput("exit\r\n");
            p.WaitForExit();
            Assert.AreEqual(
                $@"# ./gsudo 'echo 1 2 3'
1
2
3
# exit
", FixAppVeyor(p.GetStdOut()));
            Assert.AreEqual(0, p.Process.ExitCode);
        }
Ejemplo n.º 17
0
        public void Cmd_WindowsAppWithQuotesTest()
        {
            var p = new TestProcess("gsudo.exe", $"\"c:\\Program Files (x86)\\Windows NT\\Accessories\\wordpad.exe\"");

            try
            {
                p.WaitForExit();
                Assert.AreEqual(0, p.ExitCode);
            }
            finally
            {
                Process.Start("C:\\Windows\\sysnative\\tskill.exe", "wordpad").WaitForExit();
            }
            Assert.AreEqual(string.Empty, p.GetStdErr());
            Assert.AreEqual(string.Empty, p.GetStdOut());
        }
Ejemplo n.º 18
0
        public void PS_EchoNoQuotesTest()
        {
            var p = new TestProcess(
                $@"./gsudo 'echo 1 2 3'
exit
", $"{PS_FILENAME} {PS_ARGS}");

            p.WaitForExit();

            p.GetStdOut()
            .AssertHasLine("1")
            .AssertHasLine("2")
            .AssertHasLine("3");

            Assert.AreEqual(0, p.ExitCode);
        }
Ejemplo n.º 19
0
        public void Cmd_WindowsAppWaitTest()
        {
            bool stillWaiting = false;
            var  p            = new TestProcess("gsudo.exe", "-w notepad");

            try
            {
                p.WaitForExit(2000);
            }
            catch (Exception)
            {
                stillWaiting = true;
            }

            Assert.IsTrue(stillWaiting);
            Process.Start("C:\\Windows\\sysnative\\tskill.exe", "notepad").WaitForExit();
            Assert.AreEqual(string.Empty, p.GetStdErr());
            Assert.AreEqual(string.Empty, p.GetStdOut());
        }
Ejemplo n.º 20
0
        public void Cmd_ChangeDirTest()
        {
            // TODO: Test --raw, --vt, --attached
            var testDir = Environment.CurrentDirectory;
            var p1      = new TestProcess(
                $"\"{testDir}\\gsudo\" cmd /c cd \r\n"
                + $"cd .. \r\n"
                + $"\"{testDir}\\gsudo\" cmd /c cd \r\n"
                );

            p1.WaitForExit();

            var otherDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, ".."));

            p1.GetStdOut()
            .AssertHasLine($"{testDir}")
            .AssertHasLine($"{otherDir}");

            Assert.AreEqual(0, p1.ExitCode);
        }
Ejemplo n.º 21
0
        public virtual void PS_EchoDoubleQuotesTest()
        {
            var p = new TestProcess(PS_FILENAME, PS_ARGS);

            p.WriteInput("./gsudo 'echo 1 \\\"\"2 3\\\"\"'\r\nexit\r\n");
            p.WaitForExit();
            Assert.AreEqual($"# ./gsudo 'echo 1 \\\"\"2 3\\\"\"'\r\n1\r\n2 3\r\n# exit\r\n", FixAppVeyor(p.GetStdOut()));
            Assert.AreEqual(0, p.Process.ExitCode);
        }