From d52c1fb406b1cef82c5f5a28fc1804d7d99a49d8 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 17 Nov 2016 01:35:29 +0300 Subject: Add support for build2 for tests and examples --- unit-tests/.gitignore | 1 + unit-tests/buildfile | 7 ++ unit-tests/lexer/buildfile | 12 +++ unit-tests/lexer/driver.cxx | 123 ++++++++++++++++++++++ unit-tests/lexer/testscript | 192 ++++++++++++++++++++++++++++++++++ unit-tests/parser/buildfile | 14 +++ unit-tests/parser/driver.cxx | 46 ++++++++ unit-tests/parser/testscript | 243 +++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 638 insertions(+) create mode 100644 unit-tests/.gitignore create mode 100644 unit-tests/buildfile create mode 100644 unit-tests/lexer/buildfile create mode 100644 unit-tests/lexer/driver.cxx create mode 100644 unit-tests/lexer/testscript create mode 100644 unit-tests/parser/buildfile create mode 100644 unit-tests/parser/driver.cxx create mode 100644 unit-tests/parser/testscript (limited to 'unit-tests') diff --git a/unit-tests/.gitignore b/unit-tests/.gitignore new file mode 100644 index 0000000..e54525b --- /dev/null +++ b/unit-tests/.gitignore @@ -0,0 +1 @@ +driver diff --git a/unit-tests/buildfile b/unit-tests/buildfile new file mode 100644 index 0000000..6e25aae --- /dev/null +++ b/unit-tests/buildfile @@ -0,0 +1,7 @@ +# file : unit-tests/buildfile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +d = lexer/ parser/ +./: $d +include $d diff --git a/unit-tests/lexer/buildfile b/unit-tests/lexer/buildfile new file mode 100644 index 0000000..483250e --- /dev/null +++ b/unit-tests/lexer/buildfile @@ -0,0 +1,12 @@ +# file : unit-tests/lexer/buildfile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +#@@ Temporary until we get utility library support. +# +import libs = libcutl%lib{cutl} +src = lexer + +exe{driver}: cxx{driver} ../../cli/cxx{$src} $libs test{testscript} + +include ../../cli/ diff --git a/unit-tests/lexer/driver.cxx b/unit-tests/lexer/driver.cxx new file mode 100644 index 0000000..471bc1b --- /dev/null +++ b/unit-tests/lexer/driver.cxx @@ -0,0 +1,123 @@ +// file : unit-tests/lexer/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include +#include + +using namespace std; + +const char* keywords[] = +{ + "source", + "include", + "namespace", + "class", + "signed", + "unsigned", + "bool", + "char", + "wchar_t", + "short", + "int", + "long", + "float", + "double" +}; + +const char* punctuation[] = { + ";", ",", ":", "::", "{", "}", /*"(", ")",*/ "=", "|"}; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " file.cli" << endl; + return 1; + } + + ifstream ifs; + ifs.exceptions (ifstream::failbit | ifstream::badbit); + ifs.open (argv[1]); + + lexer l (ifs, argv[1]); + + while (true) + { + token t (l.next ()); + + switch (t.type ()) + { + case token::t_eos: + { + cout << "" << endl; + return 0; + } + case token::t_keyword: + { + cout << "keyword: " << keywords[t.keyword ()] << endl; + break; + } + case token::t_identifier: + { + cout << "identifier: " << t.identifier () << endl; + break; + } + case token::t_punctuation: + { + cout << punctuation[t.punctuation ()] << endl; + break; + } + case token::t_cxx_path_lit: + { + cout << "c++ path: " << t.literal () << endl; + break; + } + case token::t_cli_path_lit: + { + cout << "cli path: " << t.literal () << endl; + break; + } + case token::t_string_lit: + { + cout << t.literal () << endl; + break; + } + case token::t_char_lit: + { + cout << t.literal () << endl; + break; + } + case token::t_bool_lit: + { + cout << t.literal () << endl; + break; + } + case token::t_int_lit: + { + cout << t.literal () << endl; + break; + } + case token::t_float_lit: + { + cout << t.literal () << endl; + break; + } + case token::t_call_expr: + { + cout << t.expression () << endl; + break; + } + case token::t_template_expr: + { + cout << t.expression () << endl; + break; + } + } + } +} diff --git a/unit-tests/lexer/testscript b/unit-tests/lexer/testscript new file mode 100644 index 0000000..fb4f862 --- /dev/null +++ b/unit-tests/lexer/testscript @@ -0,0 +1,192 @@ +# file : unit-tests/lexer/testscript +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +# @@ Give tests some meaningfull descriptions. +# + +: 000 +: +cat <>>test.cli; +help +help-me +-h +--help +--help-me +--help-me- +/h +/help-me +/help/me +--_ + +EOI +$* test.cli >>EOO +identifier: help +identifier: help-me +identifier: -h +identifier: --help +identifier: --help-me +identifier: --help-me- +identifier: /h +identifier: /help-me +identifier: /help +identifier: /me +identifier: --_ + +EOO + +: 001 +: +cat <>>test.cli; +5 +123456 +-12345 +- 1 +- +123 +EOI +$* test.cli >>EOO +5 +123456 +-12345 +-1 +-123 + +EOO + +: 002 +: +cat <>>test.cli; +'a' +'\\n' +'\\\\' +'\\0' +'\\'' +'\\xaf' +'\\111' +EOI +$* test.cli >>EOO +'a' +'\\n' +'\\\\' +'\\0' +'\\'' +'\\xaf' +'\\111' + +EOO + +: 003 +: +cat <>>test.cli; +"abc"; +"a\\nb"; +"abc\\\\"; +"aaa\\0"; +"\\""; +"a\\xaf"; +"a\\111"; +"abc""def"; +"abc" "def"; +"abc + def + + xyz"; +EOI +$* test.cli >>EOO +"abc" +; +"a\\nb" +; +"abc\\\\" +; +"aaa\\0" +; +"\\"" +; +"a\\xaf" +; +"a\\111" +; +"abc""def" +; +"abc""def" +; +"abc + def + + xyz" +; + +EOO + +: 004 +: +cat <>>test.cli; +include "foo/abc.hxx"; +include ; +include "c++:map"; +include ; +include "map.cli" +EOI +$* test.cli >>EOO +keyword: include +c++ path: "foo/abc.hxx" +; +keyword: include +c++ path: +; +keyword: include +c++ path: "map" +; +keyword: include +cli path: +; +keyword: include +cli path: "map.cli" + +EOO + +: 005 +: +cat <>>test.cli; +\(abc, 123 - 345, 12.34) + +EOI +$* test.cli >>EOO +\(abc, 123 - 345, 12.34) + + +EOO + +: 006 +: +cat <>>test.cli; +// c++ comment ; +/* c comment ; */ +; +"a" // foo +"b" +"a" /* foo +bar +baz */ "b"; +- // aaa +5; +- /* a +a +a*/ 5 +// eos +: +:: +EOI +$* test.cli >>EOO +; +"a""b""a""b" +; +-5 +; +-5 +: +:: + +EOO diff --git a/unit-tests/parser/buildfile b/unit-tests/parser/buildfile new file mode 100644 index 0000000..c7a2b59 --- /dev/null +++ b/unit-tests/parser/buildfile @@ -0,0 +1,14 @@ +# file : unit-tests/parser/buildfile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +#@@ Temporary until we get utility library support. +# +import libs = libcutl%lib{cutl} +src = lexer parser \ +semantics/{class elements expression namespace option unit} \ +traversal/{class elements namespace option unit} + +exe{driver}: cxx{driver} ../../cli/cxx{$src} $libs test{testscript} + +include ../../cli/ diff --git a/unit-tests/parser/driver.cxx b/unit-tests/parser/driver.cxx new file mode 100644 index 0000000..b2dc9d5 --- /dev/null +++ b/unit-tests/parser/driver.cxx @@ -0,0 +1,46 @@ +// file : unit-tests/parser/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include +#include +#include + +using namespace std; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " file.cli" << endl; + return 1; + } + + try + { + semantics::path path (argv[1]); + + ifstream ifs; + ifs.exceptions (ifstream::failbit | ifstream::badbit); + ifs.open (path.string ().c_str ()); + + parser::paths include_paths; + parser p (include_paths); + p.parse (ifs, path); + } + catch (semantics::invalid_path const& e) + { + cerr << "error: '" << e.path () << "' is not a valid filesystem path" + << endl; + return 1; + } + catch (parser::invalid_input const&) + { + return 1; + } +} diff --git a/unit-tests/parser/testscript b/unit-tests/parser/testscript new file mode 100644 index 0000000..0ae0378 --- /dev/null +++ b/unit-tests/parser/testscript @@ -0,0 +1,243 @@ +# file : unit-tests/parser/testscript +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +# @@ Give tests some meaningfull descriptions. Probably move c++-style comments +# from the test.cli files to test descriptions. +# + +: 000 +: +cat <>>test.cli; +// def-unit +// +include ; +namespace n {} +class c {}; +EOI +$* test.cli >:"" + +: 001 +: +cat <>>base.cli; +EOI +cat <>>common.cli; +include "base.cli"; +EOI +cat <>>test.cli; +// include-decl-seq, include-decl +// +include ; +include "types.hxx"; +include "common.cli"; +include "../001/base.cli"; +EOI +$* test.cli >:"" + +: 002 +: +cat <>>test.cli; +// namespace-def, namespace-def-body +// +namespace n1 {} + +namespace n1 +{ + namespace n2 {} + class c {}; + namespace n2 + { + namespace n3 {} + } +} + +namespace n4 {} +EOI +$* test.cli >:"" + +: 003 +: +cat <>>test.cli; +// class-def, inheritance-spec, abstract-spec +// +class c1 +{ +}; + +class c2 = 0 +{ +}; + +class c3: c1, ::c2 +{ +}; + +namespace n1 +{ + class c {}; +} + +class c4: n1::c = 0 +{ +}; + +EOI +$* test.cli >:"" + +: 004 +: +cat <>>test.cli; +// option-def-seq +// +class c +{ + bool -a; + int -b; + float -c; +}; +EOI +$* test.cli >:"" + +: 005 +: +cat <>>test.cli; +// option-def, type-spec, fundamental-type-spec, option-name-seq, +// option-name, initializer, initializer-expr +// +class c +{ + bool --bool; + char --char; + + int -i1; + unsigned int -i2; + int unsigned -i3; + long -i4; + long int -i5; + int long -i6; + unsigned long -i7; + long unsigned -i8; + + unsigned long int -i9; + long unsigned int -i10; + int long unsigned -i11; + unsigned int long -i12; + + short -i13; + unsigned short -i14; + short unsigned -i15; + + char -i16; + signed char -i17; + char signed -i18; + unsigned char -i19; + char unsigned -i20; + + long long -ll1; + long long int -ll2; + long long unsigned -ll3; + int long long -ll4; + unsigned long long -ll5; + long long int unsigned -ll6; + long long unsigned int -ll7; + unsigned long long int -ll8; + unsigned int long long -ll9; + int long long unsigned -ll10; + int unsigned long long -ll11; + + double -d1; + long double -d2; + double long -d3; + + foo -o1; + ::foo -o2; + ::foo -o3; + foo::bar -o4; + ::foo::bar -o5; + ::foo::baz -o6; + ::foo::baz< ::fox<2> > -o7; + + bool -n1|--name1|/name1; + bool "-n2"|"--name2"; + + string -init1 = "string"; + char -init2 = 'c'; + int -init3 = -5; + bool -inti4 = true; + long -init5 = \(2 * 4 - 5); + type -init6 = type::default_value; + type -init7 \(abc, 2 - 1); +}; +EOI +$* test.cli >:"" + +: 006 +: +cat <>>test.cli; +// option-doc +// +class c +{ + bool --help | -h {"Help me"}; + + int --comp = 5 + { + "", + "Set compression level", + "Set compression level to . + + The minimum value for this options is 0 and + maximum is 9." + }; +}; +EOI +$* test.cli >:"" + +: 007 +: +cat <>>base.cli; +class b1 {}; + +namespace n1 +{ + class b2 {}; + + namespace i1 + { + class b3 {}; + } +} +EOI +cat <>>test.cli; +// base class lookup +// + +include "base.cli"; + +class c1 {}; +class c2: c1 {}; +class c3: ::c1 {}; + +namespace n1 +{ + class c4 {}; + class c5: c4 {}; + class c6: n1::c4 {}; + class c7: ::n1::c4 {}; + + class c8: b2 {}; // From included. + class c9: i1::b3 {}; // From included. + + namespace i1 + { + class c10: c4 {}; // Outer scope. + class c11: b3 {}; // From included. + class c12: b2 {}; // Outer scope from included. + class c4: n1::c4 {}; // Qualified name from outer scope. + } +} + +class c13: n1::c4 {}; +class c14: ::n1::c4 {}; +EOI +$* test.cli >:"" -- cgit v1.1