OILS / cpp / osh_test.cc View on Github | oilshell.org

50 lines, 31 significant
1#include "cpp/osh.h"
2
3#include "mycpp/runtime.h"
4// To avoid circular dependency with error.FatalRuntime
5#include "prebuilt/core/error.mycpp.h"
6#include "vendor/greatest.h"
7
8TEST bool_stat_test() {
9 int fail = 0;
10 try {
11 bool_stat::isatty(StrFromC("invalid"), nullptr);
12 } catch (error::FatalRuntime* e) {
13 fail++;
14 }
15 ASSERT_EQ(1, fail);
16
17 bool b2 = bool_stat::isatty(StrFromC("0"), nullptr);
18 // This will be true interactively
19 log("stdin isatty = %d", b2);
20
21 PASS();
22}
23
24TEST functions_test() {
25 ASSERT(sh_expr_eval::IsLower(StrFromC("a")));
26 ASSERT(!sh_expr_eval::IsLower(StrFromC("A")));
27 ASSERT(!sh_expr_eval::IsLower(StrFromC("9")));
28
29 ASSERT(sh_expr_eval::IsUpper(StrFromC("Z")));
30 ASSERT(!sh_expr_eval::IsUpper(StrFromC("z")));
31 ASSERT(!sh_expr_eval::IsUpper(StrFromC("9")));
32
33 PASS();
34}
35
36GREATEST_MAIN_DEFS();
37
38int main(int argc, char** argv) {
39 gHeap.Init();
40
41 GREATEST_MAIN_BEGIN();
42
43 RUN_TEST(bool_stat_test);
44 RUN_TEST(functions_test);
45
46 gHeap.CleanProcessExit();
47
48 GREATEST_MAIN_END();
49 return 0;
50}