Ticket #593: xapian-1.2.9-lua-smoketest.diff

File xapian-1.2.9-lua-smoketest.diff, 2.5 KB (added by istr, 13 years ago)

check that require returns xapian module and sets global xapian

  • xapian-bindings-1.2.

    old new  
    2121-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    2222-- USA
    2323
    24 require("xapian")
    25 
    26 function expect(m, n)
     24---
     25-- m: expected value
     26-- n: obtained value
     27-- msg: failure message (a string)
     28function expect(m, n, msg)
     29  msg = msg and msg..': ' or ''
    2730  if type(m) == "table" then
    28     assert(#m == #n)
     31    assert('table' == type(n), msg..'not a table')
     32    assert(#m == #n, msg..'got: '..tostring(#n)..' want: '..tostring(#m))
    2933    for i = 1, #m do
    3034      expect(m[i], n[i])
    3135    end
    3236  else
    33     assert(m == n)
     37    assert(m == n, msg..'got: '..(tostring(n) or '???')..' want: '..(tostring(m) or '???'))
    3438  end
    3539end
    3640
    3741function run_tests()
     42  print('Xapian Lua binding smoke test...')
     43
     44  -- require must return module table
     45  local xap = require'xapian'
     46  expect(true, nil ~= xap, 'xapian returned by require is nil')
     47  expect('table', type(xap), 'xapian returned by require is not a table')
     48  -- require must set global "xapian"
     49  expect(true, nil ~= xapian, 'global xapian is nil')
     50  expect('table', type(xapian), 'global xapian is not a table')
     51
    3852  stem = xapian.Stem("english")
    3953  doc = xapian.Document()
    4054  doc:set_data("is there anybody out there?")
     
    6377
    6478  -- Test stem
    6579  expect(tostring(stem), "Xapian::Stem(english)")
    66   expect("is", stem("is"))
    67   expect("go", stem("going"))
    68   expect("want", stem("wanted"))
    69   expect("refer", stem("reference"))
     80  expect("is", stem("is"), 'stem noop "is" fails')
     81  expect("go", stem("going"), 'stem noop "go" fails')
     82  expect("want", stem("wanted"), 'stem(english) "wanted" -> "want" fails')
     83  expect("refer", stem("reference"), 'stem(english) "reference" -> "refer" fails')
    7084
    7185  -- Test document
    7286  expect(doc:termlist_count(), 5)
     
    7690
    7791  -- Test database
    7892  expect(tostring(db), "WritableDatabase()")
    79   expect(db:get_doccount(), 1)
     93  expect(db:get_doccount(), 1, 'db should have 1 document')
    8094
    8195  term_count = 0
    8296  for term in db:allterms() do
     
    193207    for j = 0, #a -1 do
    194208      hit = mset:get_hit(j)
    195209      if hit:get_docid() ~= a[j + 1] then
    196         print(string.format("Expected MSet[%i] to be %i, got %i.\n", j, a[j + 1], hit:get_docid()))
    197         os.exit(-1)
     210        print(string.format("Expected MSet[%i] to be %i, got %i.\n", j, a[j + 1], hit:get_docid()))
     211        os.exit(-1)
    198212      end
    199213    end
    200214  end