summaryrefslogtreecommitdiff
path: root/src/test-option-parser.cc
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2020-05-21 12:58:02 -0400
committerGitHub <noreply@github.com>2020-05-21 09:58:02 -0700
commit7639690bbc2a2a35f315e2ee061cfa8cfeb1c5b1 (patch)
treecc17293bc25af39a1bb9a6a2fcae9e8d5204facd /src/test-option-parser.cc
parent3625539c176839c9a45d58143767a63c04b95559 (diff)
downloadwabt-7639690bbc2a2a35f315e2ee061cfa8cfeb1c5b1.tar.gz
wabt-7639690bbc2a2a35f315e2ee061cfa8cfeb1c5b1.tar.bz2
wabt-7639690bbc2a2a35f315e2ee061cfa8cfeb1c5b1.zip
wasi: Implement more of the wasi API (#1430)
I've been used the tests from wasi-sdk to get started: https://github.com/WebAssembly/wasi-sdk/tree/master/tests All these tests now pass. Still this isn't saying much, there are still some big missing pieces. Started using the new serdes (serialize/deserialze) API in uvwasi. I think we are almost at the point were we can look at auto-generating some of this stuff from witx to avoid having the hand code all this marshelling stuff. Add support for ArgumentCount::ZeroOrMore to OptionParser and also the ability to force the end of option processing using `--`. This allows is to pass options through the underlying wasi program when running wasm-interp.
Diffstat (limited to 'src/test-option-parser.cc')
-rw-r--r--src/test-option-parser.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/test-option-parser.cc b/src/test-option-parser.cc
index 3d190e71..9295c581 100644
--- a/src/test-option-parser.cc
+++ b/src/test-option-parser.cc
@@ -150,3 +150,32 @@ TEST(OptionParser, OneOrMoreArguments) {
parser.Parse(3, const_cast<char**>(args));
EXPECT_EQ("hellogoodbye", argument);
}
+
+TEST(OptionParser, ZeroOrMoreArguments) {
+ std::string argument;
+ OptionParser parser("prog", "desc");
+ parser.AddArgument("arg", OptionParser::ArgumentCount::ZeroOrMore,
+ [&](const char* arg) { argument += arg; });
+
+ const char* args_none[] = {"prog name"};
+ parser.Parse(1, const_cast<char**>(args_none));
+ EXPECT_EQ("", argument);
+
+ const char* args_many[] = {"prog name", "hello", "goodbye"};
+ parser.Parse(3, const_cast<char**>(args_many));
+ EXPECT_EQ("hellogoodbye", argument);
+}
+
+TEST(OptionParser, StopProccessing) {
+ std::string argument;
+ bool has_x = false;
+ OptionParser parser("prog", "desc");
+ parser.AddArgument("arg", OptionParser::ArgumentCount::ZeroOrMore,
+ [&](const char* arg) { argument += arg; });
+ parser.AddOption('x', "x", "help", [&]() { has_x = true; });
+
+ const char* args_many[] = {"prog name", "-x", "--", "foo", "-x", "-y", "bar"};
+ parser.Parse(7, const_cast<char**>(args_many));
+ EXPECT_TRUE(has_x);
+ EXPECT_EQ("foo-x-ybar", argument);
+}