monotone

monotone Mtn Source Tree

Root/test/unit-testsuite.lua

1-- Copyright (C) 2007 Zack Weinberg <zackw@panix.com>
2--
3-- This program is made available under the GNU GPL version 2.0 or
4-- greater. See the accompanying file COPYING for details.
5--
6-- This program is distributed WITHOUT ANY WARRANTY; without even the
7-- implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8-- PURPOSE.
9
10-- This test suite is special; it synthesizes all its __driver__.lua
11-- files on the fly. Each one runs the 'unit_tester' binary over just
12-- one of the test cases it can run.
13
14testdir = initial_dir.."/test/unit/tests"
15
16function prepare_to_enumerate_tests (P)
17 local unit_test_path = getpathof("test/bin/unit_tester")
18 if unit_test_path == nil then return 1 end
19
20 writefile_q("in", nil)
21 prepare_redirect("in", "out", "err")
22 local status = execute(unit_test_path)
23 local out = readfile_q("out")
24 local err = readfile_q("err")
25
26 if status == 0 and err == "" and out ~= "" then
27 -- clean up any on-the-fly tests from a previous run, in case the
28 -- set changed; we mustn't blow away the entire directory because
29 -- it's shared with the makefile (and possibly the source code)
30 unlogged_mkdir(testdir)
31 for _,candidate in ipairs(read_directory(testdir)) do
32 if exists(testdir .. "/" .. candidate .. "/__driver__.lua") then
33 unlogged_remove(testdir .. "/" .. candidate)
34 end
35 end
36
37 for tcase in string.gmatch(out, "[%w_:]+") do
38 local tdir = string.gsub(tcase, ':', '_')
39 unlogged_mkdir(testdir .. "/" .. tdir)
40 writefile_q(testdir .. "/" .. tdir .. "/__driver__.lua",
41 string.format("check({ %q, %q }, 0, true, true)\n",
42 unit_test_path, tcase))
43 end
44 else
45 P(string.format("%s: exit %d\nstdout:\n", unit_test_path, status))
46 P(out)
47 P("stderr:\n")
48 P(err)
49
50 if status == 0 then status = 1 end
51 end
52
53 unlogged_remove("in")
54 unlogged_remove("out")
55 unlogged_remove("err")
56 return status
57end
58
59-- Cloned from testsuite.lua; just dumps information about the monotone
60-- build into the master logfile.
61
62function prepare_to_run_tests (P)
63 local monotone_path = getpathof("mtn")
64 if monotone_path == nil then monotone_path = "mtn" end
65
66 writefile_q("in", nil)
67 prepare_redirect("in", "out", "err")
68
69 local status = execute(monotone_path, "version", "--full")
70 local out = readfile_q("out")
71 local err = readfile_q("err")
72
73 if status == 0 and err == "" and out ~= "" then
74 logfile:write(out)
75 else
76 P(string.format("mtn version --full: exit %d\nstdout:\n", status))
77 P(out)
78 P("stderr:\n")
79 P(err)
80
81 if status == 0 then status = 1 end
82 end
83
84 unlogged_remove("in")
85 unlogged_remove("out")
86 unlogged_remove("err")
87 return status
88end

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status