1 //===-- Loader test to check args to main ---------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #undef NDEBUG
10 #include "src/assert/assert.h"
11 
my_streq(const char * lhs,const char * rhs)12 static bool my_streq(const char *lhs, const char *rhs) {
13   const char *l, *r;
14   for (l = lhs, r = rhs; *l != '\0' && *r != '\0'; ++l, ++r)
15     if (*l != *r)
16       return false;
17 
18   return *l == '\0' && *r == '\0';
19 }
20 
main(int argc,char ** argv,char ** envp)21 int main(int argc, char **argv, char **envp) {
22   assert(argc == 4 && "Unexpected argc.");
23   assert(my_streq(argv[1], "1") && "Unexpected argv[1].");
24   assert(my_streq(argv[2], "2") && "Unexpected argv[2].");
25   assert(my_streq(argv[3], "3") && "Unexpected argv[3].");
26 
27   bool found_france = false;
28   bool found_germany = false;
29   for (; *envp != nullptr; ++envp) {
30     if (my_streq(*envp, "FRANCE=Paris"))
31       found_france = true;
32     if (my_streq(*envp, "GERMANY=Berlin"))
33       found_germany = true;
34   }
35 
36   assert(found_france && found_germany &&
37          "Did not find whats expected in envp.");
38 
39   return 0;
40 }
41