From fabbe60b014a02b2ab94e57ab3866e28c67d36ce Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 22 Aug 2009 10:25:12 +0200 Subject: Add a test for the parser --- tests/makefile | 2 +- tests/parser/driver.cxx | 34 +++++++++++++++++++ tests/parser/makefile | 83 +++++++++++++++++++++++++++++++++++++++++++++++ tests/parser/test-000.cli | 3 ++ tests/parser/test-000.std | 0 tests/parser/test-001.cli | 2 ++ tests/parser/test-001.std | 0 tests/parser/test-002.cli | 13 ++++++++ tests/parser/test-002.std | 0 tests/parser/test-003.cli | 13 ++++++++ tests/parser/test-003.std | 0 tests/parser/test-004.cli | 7 ++++ tests/parser/test-004.std | 0 tests/parser/test-005.cli | 6 ++++ tests/parser/test-005.std | 0 tests/parser/test-006.cli | 51 +++++++++++++++++++++++++++++ tests/parser/test-006.std | 0 17 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 tests/parser/driver.cxx create mode 100644 tests/parser/makefile create mode 100644 tests/parser/test-000.cli create mode 100644 tests/parser/test-000.std create mode 100644 tests/parser/test-001.cli create mode 100644 tests/parser/test-001.std create mode 100644 tests/parser/test-002.cli create mode 100644 tests/parser/test-002.std create mode 100644 tests/parser/test-003.cli create mode 100644 tests/parser/test-003.std create mode 100644 tests/parser/test-004.cli create mode 100644 tests/parser/test-004.std create mode 100644 tests/parser/test-005.cli create mode 100644 tests/parser/test-005.std create mode 100644 tests/parser/test-006.cli create mode 100644 tests/parser/test-006.std (limited to 'tests') diff --git a/tests/makefile b/tests/makefile index fa8b833..7e54132 100644 --- a/tests/makefile +++ b/tests/makefile @@ -5,7 +5,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make -tests := lexer +tests := lexer parser default := $(out_base)/ test := $(out_base)/.test diff --git a/tests/parser/driver.cxx b/tests/parser/driver.cxx new file mode 100644 index 0000000..c783503 --- /dev/null +++ b/tests/parser/driver.cxx @@ -0,0 +1,34 @@ +// file : tests/parser/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#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 + { + ifstream ifs; + ifs.exceptions (ifstream::failbit | ifstream::badbit); + ifs.open (argv[1]); + + Parser parser; + parser.parse (ifs, argv[1]); + } + catch (Parser::InvalidInput const&) + { + return 1; + } +} diff --git a/tests/parser/makefile b/tests/parser/makefile new file mode 100644 index 0000000..4642b6d --- /dev/null +++ b/tests/parser/makefile @@ -0,0 +1,83 @@ +# file : tests/parser/makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2009 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +cxx_tun := driver.cxx + +tests := 000 001 002 003 004 005 006 + +# +# +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(cxx_obj) $(out_root)/cli/lexer.o $(out_root)/cli/parser.o + +$(cxx_obj) $(cxx_od): cpp_options := -I$(src_base) -I$(src_root) + +$(call include-dep,$(cxx_od)) + + +# Alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +test_targets := $(addprefix $(out_base)/.test-,$(tests)) + +.PHONY: $(test) +$(test): $(test_targets) + + +$(test_targets): driver := $(driver) + +.PHONY: $(out_base)/.test-% +$(out_base)/.test-%: $(driver) $(src_base)/test-%.cli $(src_base)/test-%.std + $(call message,test $(out_base)/$*,$(driver) $(src_base)/test-$*.cli | diff -u $(src_base)/test-$*.std -) + + +# Clean. +# +.PHONY: $(clean) + +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(bld_root)/install.make) + +# Dependencies. +# +$(call import,$(src_root)/cli/makefile) diff --git a/tests/parser/test-000.cli b/tests/parser/test-000.cli new file mode 100644 index 0000000..5951dc6 --- /dev/null +++ b/tests/parser/test-000.cli @@ -0,0 +1,3 @@ +include ; +namespace n {} +class c {}; diff --git a/tests/parser/test-000.std b/tests/parser/test-000.std new file mode 100644 index 0000000..e69de29 diff --git a/tests/parser/test-001.cli b/tests/parser/test-001.cli new file mode 100644 index 0000000..a27e027 --- /dev/null +++ b/tests/parser/test-001.cli @@ -0,0 +1,2 @@ +include ; +include "types.hxx"; diff --git a/tests/parser/test-001.std b/tests/parser/test-001.std new file mode 100644 index 0000000..e69de29 diff --git a/tests/parser/test-002.cli b/tests/parser/test-002.cli new file mode 100644 index 0000000..2413b71 --- /dev/null +++ b/tests/parser/test-002.cli @@ -0,0 +1,13 @@ +namespace n1 {} + +namespace n1 +{ + namespace n2 {} + class c {}; + namespace n2 + { + namespace n3 {} + } +} + +namespace n4 {} diff --git a/tests/parser/test-002.std b/tests/parser/test-002.std new file mode 100644 index 0000000..e69de29 diff --git a/tests/parser/test-003.cli b/tests/parser/test-003.cli new file mode 100644 index 0000000..2413b71 --- /dev/null +++ b/tests/parser/test-003.cli @@ -0,0 +1,13 @@ +namespace n1 {} + +namespace n1 +{ + namespace n2 {} + class c {}; + namespace n2 + { + namespace n3 {} + } +} + +namespace n4 {} diff --git a/tests/parser/test-003.std b/tests/parser/test-003.std new file mode 100644 index 0000000..e69de29 diff --git a/tests/parser/test-004.cli b/tests/parser/test-004.cli new file mode 100644 index 0000000..5497dca --- /dev/null +++ b/tests/parser/test-004.cli @@ -0,0 +1,7 @@ +class c1 +{ +}; + +class c2 +{ +}; \ No newline at end of file diff --git a/tests/parser/test-004.std b/tests/parser/test-004.std new file mode 100644 index 0000000..e69de29 diff --git a/tests/parser/test-005.cli b/tests/parser/test-005.cli new file mode 100644 index 0000000..84dc24f --- /dev/null +++ b/tests/parser/test-005.cli @@ -0,0 +1,6 @@ +class c +{ + bool -a; + int -b; + float -c; +}; diff --git a/tests/parser/test-005.std b/tests/parser/test-005.std new file mode 100644 index 0000000..e69de29 diff --git a/tests/parser/test-006.cli b/tests/parser/test-006.cli new file mode 100644 index 0000000..7c70887 --- /dev/null +++ b/tests/parser/test-006.cli @@ -0,0 +1,51 @@ +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; + + 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 -n|--name|/name; + + 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); +}; diff --git a/tests/parser/test-006.std b/tests/parser/test-006.std new file mode 100644 index 0000000..e69de29 -- cgit v1.1