proxygen
ShellTest.cpp File Reference
#include <glog/logging.h>
#include <folly/portability/GTest.h>
#include <folly/system/Shell.h>

Go to the source code of this file.

Functions

 TEST (Shell, ShellQuote)
 
 TEST (Shell, Shellify)
 
FOLLY_PUSH_WARNING TEST (Shell, Shellify_deprecated)
 

Function Documentation

TEST ( Shell  ,
ShellQuote   
)

Definition at line 24 of file ShellTest.cpp.

References EXPECT_EQ, and folly::shellQuote().

24  {
25  EXPECT_EQ(shellQuote("a"), "'a'");
26  EXPECT_EQ(shellQuote("a'b"), "'a'\\''b'");
27  EXPECT_EQ(shellQuote("a\"b"), "'a\"b'");
28 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::string shellQuote(StringPiece argument)
Definition: Shell.cpp:21
TEST ( Shell  ,
Shellify   
)

Definition at line 30 of file ShellTest.cpp.

References EXPECT_EQ, FOLLY_GNU_DISABLE_WARNING, and FOLLY_PUSH_WARNING.

30  {
31  auto command = "rm -rf /"_shellify();
32  EXPECT_EQ(command[0], "/bin/sh");
33  EXPECT_EQ(command[1], "-c");
34  EXPECT_EQ(command[2], "rm -rf /");
35 
36  command = "rm -rf {}"_shellify("someFile.txt");
37  EXPECT_EQ(command[2], "rm -rf 'someFile.txt'");
38 
39  command = "rm -rf {}"_shellify(5);
40  EXPECT_EQ(command[2], "rm -rf '5'");
41 
42  command = "ls {}"_shellify("blah'; rm -rf /");
43  EXPECT_EQ(command[2], "ls 'blah'\\''; rm -rf /'");
44 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
FOLLY_PUSH_WARNING TEST ( Shell  ,
Shellify_deprecated   
)

Definition at line 50 of file ShellTest.cpp.

References EXPECT_EQ, FOLLY_POP_WARNING, and folly::shellify().

50  {
51  auto command = shellify("rm -rf /");
52  EXPECT_EQ(command[0], "/bin/sh");
53  EXPECT_EQ(command[1], "-c");
54  EXPECT_EQ(command[2], "rm -rf /");
55 
56  command = shellify("rm -rf {}", "someFile.txt");
57  EXPECT_EQ(command[2], "rm -rf 'someFile.txt'");
58 
59  command = shellify("rm -rf {}", 5);
60  EXPECT_EQ(command[2], "rm -rf '5'");
61 
62  command = shellify("ls {}", "blah'; rm -rf /");
63  EXPECT_EQ(command[2], "ls 'blah'\\''; rm -rf /'");
64 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::vector< std::string > shellify(StringPiece format, Arguments &&...arguments)
Definition: Shell.h:43