Gentoo Archives: gentoo-commits

From: "Petteri Räty" <betelgeuse@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/libbash:master commit in: scripts/, /, test/
Date: Sat, 02 Apr 2011 15:51:03
Message-Id: b7e8f0d374b8dea54247d191fa4257ec0812c900.betelgeuse@gentoo
1 commit: b7e8f0d374b8dea54247d191fa4257ec0812c900
2 Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
3 AuthorDate: Sat Apr 2 05:52:22 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Sat Apr 2 15:46:51 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=b7e8f0d3
7
8 Implement a custom test for variable retrieval
9
10 *.ebuild under ./scripts will be parsed and compared with
11 ./*.ebuild.result by calling diff. No output should be generated
12 by diff if everything goes fine.
13
14 ---
15 .gitignore | 1 +
16 Makefile.am | 18 ++++++++++---
17 scripts/var_def.ebuild.result | 10 +++++++
18 test/script_compiler.sh | 11 ++++++++
19 test/variable_printer.cpp | 57 +++++++++++++++++++++++++++++++++++++++++
20 5 files changed, 93 insertions(+), 4 deletions(-)
21
22 diff --git a/.gitignore b/.gitignore
23 index 4bf6402..18020e7 100644
24 --- a/.gitignore
25 +++ b/.gitignore
26 @@ -18,6 +18,7 @@ missing
27 Makefile
28 autom4te.cache
29 cppunittests
30 +variable_printer
31 libbash.g
32 libbash.tokens
33 bashast.tokens
34
35 diff --git a/Makefile.am b/Makefile.am
36 index b6b2616..e14c26a 100644
37 --- a/Makefile.am
38 +++ b/Makefile.am
39 @@ -23,7 +23,7 @@ include doxygen.am
40
41 ACLOCAL_AMFLAGS = -I m4
42
43 -TEST_EXTENSIONS= .gunit
44 +TEST_EXTENSIONS= .gunit .ebuild
45 GUNIT_LOG_COMPILER = $(srcdir)/bashast/gunit/runtests.sh
46 AM_GUNIT_LOG_FLAGS = @antlr_cp@:.
47 GUNIT_TESTS = bashast/gunit/arith_main.gunit \
48 @@ -46,7 +46,11 @@ GUNIT_TESTS = bashast/gunit/arith_main.gunit \
49 bashast/gunit/simp_command.gunit \
50 bashast/gunit/simp_prog.gunit
51
52 -TESTS = $(GUNIT_TESTS)
53 +EBUILD_LOG_COMPILER = $(srcdir)/test/script_compiler.sh
54 +EBUILD_TESTS = scripts/var_def.ebuild
55 +EBUILD_RESULT = scripts/var_def.ebuild.result
56 +
57 +TESTS = $(GUNIT_TESTS) $(EBUILD_TESTS)
58 # these get cleaned so only add autogenerated stuff or modify CLEANFILES
59 check_JAVA = bashast/bashastLexer.java bashast/bashastParser.java
60 AM_JAVACFLAGS = -classpath @antlr_cp@
61 @@ -72,7 +76,7 @@ endif
62
63 if HAVE_GTEST
64 TESTS += cppunittests
65 -check_PROGRAMS = cppunittests
66 +check_PROGRAMS = cppunittests variable_printer
67
68 cppunittests_SOURCES = test/run_tests.cpp \
69 src/core/tests/symbols_test.cpp \
70 @@ -87,6 +91,9 @@ cppunittests_LDADD = libcppbash.la \
71 $(BOOST_SYSTEM_LIB) \
72 $(BOOST_FILESYSTEM_LIB)
73 cppunittests_LDFLAGS = -static
74 +
75 +variable_printer_SOURCES = test/variable_printer.cpp
76 +variable_printer_LDADD = libcppbash.la
77 endif
78
79 GENERATED_PARSER_C = libbashLexer.c libbashParser.c
80 @@ -136,8 +143,11 @@ libcppbash_la_CFLAGS = $(AM_CFLAGS) $(HIDDEN_FLAGS)
81
82 EXTRA_DIST = bashast/bashast.g \
83 bashast/libbashWalker.g \
84 + $(EBUILD_TESTS) \
85 + $(EBUILD_RESULT) \
86 $(GUNIT_TESTS) \
87 - $(GUNIT_LOG_COMPILER)
88 + $(GUNIT_LOG_COMPILER) \
89 + $(EBUILD_LOG_COMPILER)
90
91 coding_standard.pdf: coding_standard/coding_standard.tex
92 $(AM_V_GEN)@PDFLATEX@ coding_standard/coding_standard.tex 2&>1 > /dev/null
93
94 diff --git a/scripts/var_def.ebuild.result b/scripts/var_def.ebuild.result
95 new file mode 100644
96 index 0000000..6a3a0b8
97 --- /dev/null
98 +++ b/scripts/var_def.ebuild.result
99 @@ -0,0 +1,10 @@
100 +DESCRIPTION=SunPinyin is a SLM (Statistical Language Model) based IME
101 +EAPI=1
102 +HOMEPAGE=http://sunpinyin.googlecode.com
103 +IUSE=abc
104 +KEYWORDS=~amd64 ~x86
105 +LICENSE=LGPL-2.1 CDDL
106 +RDEPEND=dev-db/sqlite:3
107 +SLOT=0
108 +SRC_URI=http://open-gram.googlecode.com/files/dict.utf8.tar.bz2
109 + http://open-gram.googlecode.com/files/lm_sc.t3g.arpa.tar.bz2
110
111 diff --git a/test/script_compiler.sh b/test/script_compiler.sh
112 new file mode 100755
113 index 0000000..d409673
114 --- /dev/null
115 +++ b/test/script_compiler.sh
116 @@ -0,0 +1,11 @@
117 +#!/bin/sh
118 +
119 +declare -i error=0
120 +
121 +for script in $@
122 +do
123 + ./variable_printer $script | diff -u $script.result -
124 + error+=$?
125 +done
126 +
127 +exit $error
128
129 diff --git a/test/variable_printer.cpp b/test/variable_printer.cpp
130 new file mode 100644
131 index 0000000..ab2b4cb
132 --- /dev/null
133 +++ b/test/variable_printer.cpp
134 @@ -0,0 +1,57 @@
135 +/*
136 + Please use git log for copyright holder and year information
137 +
138 + This file is part of libbash.
139 +
140 + libbash is free software: you can redistribute it and/or modify
141 + it under the terms of the GNU General Public License as published by
142 + the Free Software Foundation, either version 2 of the License, or
143 + (at your option) any later version.
144 +
145 + libbash is distributed in the hope that it will be useful,
146 + but WITHOUT ANY WARRANTY; without even the implied warranty of
147 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
148 + GNU General Public License for more details.
149 +
150 + You should have received a copy of the GNU General Public License
151 + along with libbash. If not, see <http://www.gnu.org/licenses/>.
152 +*/
153 +///
154 +/// \file variable_printer.cpp
155 +/// \author Mu Qiao
156 +/// \brief a program to write variables in a script into standard output
157 +///
158 +
159 +#include <algorithm>
160 +#include <iostream>
161 +#include <vector>
162 +
163 +#include <boost/range/adaptor/map.hpp>
164 +#include <boost/range/algorithm/for_each.hpp>
165 +#include <boost/range/algorithm/sort.hpp>
166 +#include <gtest/gtest.h>
167 +
168 +#include "libbash.h"
169 +
170 +using namespace std;
171 +
172 +int main(int argc, char** argv)
173 +{
174 + if(argc != 2)
175 + {
176 + cerr<<"Please provide your script as an argument"<<endl;
177 + exit(EXIT_FAILURE);
178 + }
179 +
180 + unordered_map<string, string> variables;
181 + libbash::interpret(argv[1], variables);
182 +
183 + auto keys = variables | boost::adaptors::map_keys;
184 + vector<string> names(keys.begin(), keys.end());
185 + auto sorted = boost::sort(names);
186 + boost::for_each(boost::sort(names), [&](const string& key){
187 + cout << key << '=' << variables[key] << endl;
188 + });
189 +
190 + return 0;
191 +}