Skip to content

Commit 038aaa9

Browse files
acozzettecopybara-github
authored andcommitted
Remove our vendored copy of lunit
The [upstream](https://github.com/mrothNET/lunit) project is apparently unmaintained and unavailable in BCR. Since our Lua protobuf implementation is experimental and not being very actively developed, I think we might as well drop our lunit dependency and use simple `assert` statements instead. While I was at it I noticed we had some cases of multiple test functions with the same name, causing the later definitions to shadow earlier ones. We had two functions called `test_utf8()` that tested roughly the same thing, so I deleted one of them. We also had two functions named `test_string_double_map()`, but one of them was actually testing packed repeated fields, so I just renamed it. PiperOrigin-RevId: 741324780
1 parent 177036a commit 038aaa9

File tree

9 files changed

+62
-974
lines changed

9 files changed

+62
-974
lines changed

lua/BUILD.bazel

-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ cc_test(
7070
":test_proto_lua",
7171
"//:descriptor_proto",
7272
"//conformance:conformance_proto",
73-
"//third_party/lunit:console.lua",
74-
"//third_party/lunit:lunit.lua",
7573
],
7674
linkstatic = 1,
7775
deps = [

lua/main.c

-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const char* init =
3030
"package.preload['lupb'] = ... "
3131
"package.path = '"
3232
"./?.lua;"
33-
"./third_party/lunit/?.lua;"
3433
"external/com_google_protobuf/?.lua;"
3534
"external/com_google_protobuf/src/?.lua;"
3635
"bazel-bin/?.lua;"
@@ -40,7 +39,6 @@ const char* init =
4039
// These additional paths handle the case where this test is invoked from
4140
// the protobuf repo's Bazel workspace.
4241
"external/?.lua;"
43-
"external/third_party/lunit/?.lua;"
4442
"src/?.lua;"
4543
"bazel-bin/external/?.lua;"
4644
"external/lua/?.lua"

lua/test_upb.lua

+62-30
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,12 @@ https://developers.google.com/open-source/licenses/bsd
1010
--]]--------------------------------------------------------------------------
1111

1212
local upb = require "lupb"
13-
local lunit = require "lunit"
1413
local upb_test = require "lua.test_pb"
1514
local test_messages_proto3 = require "google.protobuf.test_messages_proto3_pb"
1615
local test_messages_proto2 = require "google.protobuf.test_messages_proto2_pb"
1716
local descriptor = require "google.protobuf.descriptor_pb"
1817
local empty = require "google.protobuf.empty_pb"
1918

20-
if _VERSION >= 'Lua 5.2' then
21-
_ENV = lunit.module("testupb", "seeall")
22-
else
23-
module("testupb", lunit.testcase, package.seeall)
24-
end
25-
2619
function iter_to_array(iter)
2720
local arr = {}
2821
for v in iter do
@@ -31,6 +24,36 @@ function iter_to_array(iter)
3124
return arr
3225
end
3326

27+
function assert_equal(a, b)
28+
assert(a == b)
29+
end
30+
31+
function assert_not_equal(a, b)
32+
assert(a ~= b)
33+
end
34+
35+
function assert_nil(x)
36+
assert(x == nil)
37+
end
38+
39+
function assert_not_nil(x)
40+
assert(x ~= nil)
41+
end
42+
43+
function assert_true(x)
44+
assert(x)
45+
end
46+
47+
function assert_error(f)
48+
assert(not pcall(f))
49+
end
50+
51+
function assert_error_match(expected, f)
52+
local status, err = pcall(f)
53+
assert(not status)
54+
assert(string.find(err, expected) ~= nil)
55+
end
56+
3457
function test_def_readers()
3558
local m = test_messages_proto3.TestAllTypesProto3
3659
assert_equal("TestAllTypesProto3", m:name())
@@ -173,7 +196,7 @@ function test_utf8()
173196
-- Decoding invalid UTF-8 succeeds in proto2.
174197
upb.decode(test_messages_proto2.TestAllTypesProto2, serialized)
175198

176-
-- Decoding invalid UTF-8 fails in proto2.
199+
-- Decoding invalid UTF-8 fails in proto3.
177200
assert_error_match("Error decoding protobuf", function()
178201
upb.decode(test_messages_proto3.TestAllTypesProto3, serialized)
179202
end)
@@ -207,7 +230,7 @@ function test_string_double_map()
207230
assert_equal(2.5, msg2.map_string_double["two point five"])
208231
end
209232

210-
function test_string_double_map()
233+
function test_packed_repeated()
211234
local function fill_msg(msg)
212235
msg.i32_packed[1] = 100
213236
msg.i32_packed[2] = 200
@@ -440,22 +463,6 @@ local numeric_types = {
440463
},
441464
}
442465

443-
function test_utf8()
444-
local invalid_utf8 = "\xff"
445-
local proto2_msg = test_messages_proto2.TestAllTypesProto2{
446-
optional_string = invalid_utf8,
447-
}
448-
449-
-- As proto2, invalid UTF-8 parses and serializes fine.
450-
local serialized = upb.encode(proto2_msg)
451-
local proto2_msg2 = upb.decode(test_messages_proto2.TestAllTypesProto2, serialized)
452-
453-
-- Decoding as proto3 fails.
454-
assert_error(function()
455-
upb.decode(test_messages_proto3.TestAllTypesProto3, serialized)
456-
end)
457-
end
458-
459466
function test_msg_primitives()
460467
local msg = test_messages_proto3.TestAllTypesProto3{
461468
optional_int32 = 10,
@@ -822,8 +829,33 @@ function test_b9440()
822829
assert_equal(8, m.id)
823830
end
824831

825-
local stats = lunit.main()
826-
827-
if stats.failed > 0 or stats.errors > 0 then
828-
error("One or more errors in test suite")
829-
end
832+
-- Run all tests
833+
test_def_readers()
834+
test_msg_map()
835+
test_map_sorting()
836+
test_utf8()
837+
test_string_double_map()
838+
test_packed_repeated()
839+
test_msg_string_map()
840+
test_msg_array()
841+
test_array_append()
842+
test_msg_submsg()
843+
test_finalizer()
844+
test_msg_primitives()
845+
test_string_array()
846+
test_numeric_array()
847+
test_numeric_map()
848+
test_unknown()
849+
test_foo()
850+
test_descriptor()
851+
test_descriptor_error()
852+
test_duplicate_enumval()
853+
test_duplicate_filename_error()
854+
test_encode_skipunknown()
855+
test_json_emit_defaults()
856+
test_json_locale()
857+
test_encode_depth_limit()
858+
test_large_field_number()
859+
test_timestamp_minutes()
860+
test_gc()
861+
test_b9440()

third_party/lunit/BUILD.bazel

-10
This file was deleted.

third_party/lunit/LICENSE

-32
This file was deleted.

third_party/lunit/README.google

-9
This file was deleted.

third_party/lunit/console.lua

-156
This file was deleted.

0 commit comments

Comments
 (0)