Skip to content

Commit

Permalink
[cpp refactor] Create //cpp/osh and associated test
Browse files Browse the repository at this point in the history
Fix bin/osh_eval dependencies
  • Loading branch information
Andy C committed Nov 13, 2022
1 parent a959ba4 commit f8a9a8c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 23 deletions.
2 changes: 2 additions & 0 deletions bin/NINJA_subgraph.py
Expand Up @@ -37,6 +37,8 @@ def NinjaGraph(ru):
top_level = True, # _bin/cxx-dbg/osh_eval
deps = [
'//cpp/core',
'//cpp/libc',
'//cpp/osh',
'//cpp/bindings',
'//cpp/frontend_flag_spec',
'//cpp/frontend_match',
Expand Down
19 changes: 15 additions & 4 deletions cpp/NINJA_subgraph.py
Expand Up @@ -95,19 +95,30 @@ def NinjaGraph(ru):
deps = ['//cpp/libc'],
matrix = ninja_lib.COMPILERS_VARIANTS)

ru.cc_library(
'//cpp/osh',
srcs = ['cpp/osh.cc'],
deps = [
'//frontend/syntax.asdl',
'//cpp/core',
'//mycpp/runtime',
]
)

ru.cc_binary(
'cpp/osh_test.cc',
deps = ['//cpp/osh'],
matrix = ninja_lib.COMPILERS_VARIANTS)

ru.cc_library(
'//cpp/bindings',
# TODO: split these into their own libraries
srcs = [
'cpp/frontend_tdop.cc',
'cpp/osh.cc',
'cpp/pgen2.cc',
'cpp/pylib.cc',
'cpp/stdlib.cc',
],
deps = [
'//frontend/syntax.asdl', # osh depends on this
]
)

ru.cc_binary(
Expand Down
8 changes: 6 additions & 2 deletions cpp/TEST.sh
Expand Up @@ -75,10 +75,12 @@ unit() {

# Other tests
for variant in ubsan asan; do
run-test-in-dir cpp/binding_test '' $variant
run-one-test cpp/binding_test '' $variant

run-test-in-dir cpp/libc_test '' $variant # has testdata

run-one-test cpp/osh_test '' $variant

# Need -D CPP_UNIT_TEST
run-special-test cpp/frontend_flag_spec_test '' $variant

Expand All @@ -104,10 +106,12 @@ coverage() {

run-one-test cpp/qsn_test $compiler $variant

run-test-in-dir cpp/binding_test $compiler $variant
run-one-test cpp/binding_test $compiler $variant

run-test-in-dir cpp/libc_test $compiler $variant # has testdata

run-one-test cpp/osh_test $compiler $variant

# Need -D CPP_UNIT_TEST
run-special-test cpp/frontend_flag_spec_test $compiler $variant

Expand Down
17 changes: 0 additions & 17 deletions cpp/binding_test.cc
Expand Up @@ -69,22 +69,6 @@ TEST posix_test() {
PASS();
}

TEST bool_stat_test() {
int fail = 0;
try {
bool_stat::isatty(StrFromC("invalid"), nullptr);
} catch (error::FatalRuntime* e) {
fail++;
}
ASSERT_EQ(1, fail);

bool b2 = bool_stat::isatty(StrFromC("0"), nullptr);
// This will be true interactively
log("stdin isatty = %d", b2);

PASS();
}

TEST os_path_test() {
// TODO: use gc_mylib here, with NewStr(), StackRoots, etc.
Str* s = nullptr;
Expand Down Expand Up @@ -129,7 +113,6 @@ int main(int argc, char** argv) {
RUN_TEST(show_sizeof);
RUN_TEST(time_test);
RUN_TEST(posix_test);
RUN_TEST(bool_stat_test);
RUN_TEST(os_path_test);
RUN_TEST(putenv_test);

Expand Down
35 changes: 35 additions & 0 deletions cpp/osh_test.cc
@@ -0,0 +1,35 @@
#include "cpp/osh.h"
#include "cpp/core_error.h"
#include "mycpp/runtime.h"
#include "vendor/greatest.h"

TEST bool_stat_test() {
int fail = 0;
try {
bool_stat::isatty(StrFromC("invalid"), nullptr);
} catch (error::FatalRuntime* e) {
fail++;
}
ASSERT_EQ(1, fail);

bool b2 = bool_stat::isatty(StrFromC("0"), nullptr);
// This will be true interactively
log("stdin isatty = %d", b2);

PASS();
}

GREATEST_MAIN_DEFS();

int main(int argc, char** argv) {
gHeap.Init();

GREATEST_MAIN_BEGIN();

RUN_TEST(bool_stat_test);

gHeap.CleanProcessExit();

GREATEST_MAIN_END();
return 0;
}

0 comments on commit f8a9a8c

Please sign in to comment.