vala-tests r2 - in trunk: . src tests tests/compiler
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala-tests r2 - in trunk: . src tests tests/compiler
- Date: Fri, 17 Oct 2008 17:42:36 +0000 (UTC)
Author: juergbi
Date: Fri Oct 17 17:42:36 2008
New Revision: 2
URL: http://svn.gnome.org/viewvc/vala-tests?rev=2&view=rev
Log:
Add skeleton for testsuite
Added:
trunk/MAINTAINERS
trunk/Makefile
trunk/src/
trunk/src/posix.vapi
trunk/src/testcase.vala
trunk/src/testsuite.vala (contents, props changed)
trunk/tests/
trunk/tests/compiler/
trunk/tests/compiler/hello.test (contents, props changed)
Added: trunk/MAINTAINERS
==============================================================================
--- (empty file)
+++ trunk/MAINTAINERS Fri Oct 17 17:42:36 2008
@@ -0,0 +1,4 @@
+JÃrg Billeter
+E-mail: j bitron ch
+Userid: juergbi
+
Added: trunk/Makefile
==============================================================================
--- (empty file)
+++ trunk/Makefile Fri Oct 17 17:42:36 2008
@@ -0,0 +1,11 @@
+VALAC = valac
+
+all: testsuite
+
+check: testsuite
+ gtester --g-fatal-warnings -k -o test-report.xml testsuite
+ gtester-report test-report.xml > test-report.html
+
+testsuite: src/testsuite.vala src/testcase.vala src/posix.vapi
+ $(VALAC) -o $@ $^
+
Added: trunk/src/posix.vapi
==============================================================================
--- (empty file)
+++ trunk/src/posix.vapi Fri Oct 17 17:42:36 2008
@@ -0,0 +1,27 @@
+/* posix.vapi
+ *
+ * Copyright (C) 2008 JÃrg Billeter
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * JÃrg Billeter <j bitron ch>
+ */
+
+namespace Posix {
+ [CCode (cname = "execl", cheader_filename = "unistd.h")]
+ public int execl (string path, string arg, ...);
+}
+
Added: trunk/src/testcase.vala
==============================================================================
--- (empty file)
+++ trunk/src/testcase.vala Fri Oct 17 17:42:36 2008
@@ -0,0 +1,69 @@
+/* testcase.vala
+ *
+ * Copyright (C) 2008 JÃrg Billeter
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * JÃrg Billeter <j bitron ch>
+ */
+
+public class Vala.TestCase : Object {
+ public string path { get; set; }
+
+ public TestCase (string path) {
+ this.path = path;
+ }
+
+ public void run () {
+ // prepare test dir
+ string testdir = Path.build_filename (Environment.get_current_dir (), "test");
+
+ try {
+ Process.spawn_command_line_sync ("rm -rf \"" + testdir + "\"");
+ } catch (SpawnError e) {
+ error ("Failed to cleanup test directory: %s", e.message);
+ }
+
+ DirUtils.create (testdir, 0775);
+
+ string testcase = Path.build_filename (Environment.get_current_dir (), "tests" + path + ".test");
+
+ // run test case
+ string[] args = new string[] { "/bin/sh", "-c", Shell.quote (testcase) + " 2>&1" };
+ int exit_status;
+ string output;
+
+ try {
+ Process.spawn_sync (testdir, args, null, 0, null, out output, null, out exit_status);
+ } catch (SpawnError e) {
+ error ("Failed to run test case: %s", e.message);
+ }
+
+ // cleanup
+ try {
+ Process.spawn_command_line_sync ("rm -rf \"" + testdir + "\"");
+ } catch (SpawnError e) {
+ error ("Failed to cleanup test directory: %s", e.message);
+ }
+
+ // report error
+ if (exit_status != 0) {
+ string format = "\n%s";
+ error (format, output);
+ }
+ }
+}
+
Added: trunk/src/testsuite.vala
==============================================================================
--- (empty file)
+++ trunk/src/testsuite.vala Fri Oct 17 17:42:36 2008
@@ -0,0 +1,54 @@
+/* testsuite.vala
+ *
+ * Copyright (C) 2008 JÃrg Billeter
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * JÃrg Billeter <j bitron ch>
+ */
+
+public class Vala.TestSuite : Object {
+ List<TestCase> tests;
+
+ public void add_directory (string dirpath, string testpath = "/") {
+ try {
+ var dir = Dir.open (dirpath);
+ string file;
+ while ((file = dir.read_name ()) != null) {
+ string filepath = Path.build_filename (dirpath, file);
+ if (FileUtils.test (filepath, FileTest.IS_DIR)) {
+ add_directory (filepath, testpath + file + "/");
+ } else if (file.has_suffix (".test") && FileUtils.test (filepath, FileTest.IS_EXECUTABLE)) {
+ var test = new TestCase (testpath + file.substring (0, file.length - ".test".length));
+ tests.append (test);
+ Test.add_data_func (test.path, test.run);
+ }
+ }
+ } catch (FileError e) {
+ warning ("Unable to open directory `%s'", dirpath);
+ }
+ }
+
+ static void main (string[] args) {
+ Test.init (ref args);
+
+ var suite = new TestSuite ();
+ suite.add_directory ("tests");
+
+ Test.run ();
+ }
+}
+
Added: trunk/tests/compiler/hello.test
==============================================================================
--- (empty file)
+++ trunk/tests/compiler/hello.test Fri Oct 17 17:42:36 2008
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+set -e
+
+cat > hello.vala << "END"
+void main () {
+ print ("Hello world\n");
+}
+END
+
+$VALAC -o hello hello.vala
+./hello
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]