File: unit-testsuite.lua

package info (click to toggle)
monotone 1.1-4+deb8u2
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 20,664 kB
  • ctags: 8,113
  • sloc: cpp: 86,443; sh: 6,906; perl: 924; makefile: 838; python: 517; lisp: 379; sql: 118; exp: 91; ansic: 52
file content (88 lines) | stat: -rw-r--r-- 2,731 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
-- Copyright (C) 2007 Zack Weinberg <zackw@panix.com>
--
-- This program is made available under the GNU GPL version 2.0 or
-- greater. See the accompanying file COPYING for details.
--
-- This program is distributed WITHOUT ANY WARRANTY; without even the
-- implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-- PURPOSE.

-- This test suite is special; it synthesizes all its __driver__.lua
-- files on the fly.  Each one runs the 'unit_tester' binary over just
-- one of the test cases it can run.

testdir = initial_dir.."/test/unit/tests"

function prepare_to_enumerate_tests (P)
   local unit_test_path = getpathof("test/bin/unit_tester")
   if unit_test_path == nil then return 1 end

   writefile_q("in", nil)
   prepare_redirect("in", "out", "err")
   local status = execute(unit_test_path)
   local out = readfile_q("out")
   local err = readfile_q("err")

   if status == 0 and err == "" and out ~= "" then
      -- clean up any on-the-fly tests from a previous run, in case the
      -- set changed; we mustn't blow away the entire directory because
      -- it's shared with the makefile (and possibly the source code)
      unlogged_mkdir(testdir)
      for _,candidate in ipairs(read_directory(testdir)) do
	 if exists(testdir .. "/" .. candidate .. "/__driver__.lua") then
	    unlogged_remove(testdir .. "/" .. candidate)
	 end
      end

      for tcase in string.gmatch(out, "[%w_:]+") do
	 local tdir = string.gsub(tcase, ':', '_')
	 unlogged_mkdir(testdir .. "/" .. tdir)
	 writefile_q(testdir .. "/" .. tdir .. "/__driver__.lua",
		     string.format("check({ %q, %q }, 0, true, true)\n",
				   unit_test_path, tcase))
      end
   else
      P(string.format("%s: exit %d\nstdout:\n", unit_test_path, status))
      P(out)
      P("stderr:\n")
      P(err)

      if status == 0 then status = 1 end
   end

   unlogged_remove("in")
   unlogged_remove("out")
   unlogged_remove("err")
   return status
end

-- Cloned from testsuite.lua; just dumps information about the monotone
-- build into the master logfile.

function prepare_to_run_tests (P)
   local monotone_path = getpathof("mtn")
   if monotone_path == nil then monotone_path = "mtn" end

   writefile_q("in", nil)
   prepare_redirect("in", "out", "err")

   local status = execute(monotone_path, "version", "--full")
   local out = readfile_q("out")
   local err = readfile_q("err")

   if status == 0 and err == "" and out ~= "" then
      logfile:write(out)
   else
      P(string.format("mtn version --full: exit %d\nstdout:\n", status))
      P(out)
      P("stderr:\n")
      P(err)

      if status == 0 then status = 1 end
   end

   unlogged_remove("in")
   unlogged_remove("out")
   unlogged_remove("err")
   return status
end