shithub: mc

Download patch

ref: a3684bcdf61e987bc4dc83bdcc5a881566bece78
parent: 6a9dbb951669f51e106423bd4a3b8f5b532bfc0f
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Jul 21 19:07:42 EDT 2017

Using implicit util files in tests is a bad idea.

	Also, it's going to go away in the new mbld.

--- a/lib/crypto/bld.sub
+++ b/lib/crypto/bld.sub
@@ -21,3 +21,11 @@
 	lib ../thread:thread
 ;;
 
+
+lib testutil =
+	util.myr
+;;
+
+testdeps =
+	testutil
+;;
--- a/lib/crypto/test/md5.myr
+++ b/lib/crypto/test/md5.myr
@@ -1,8 +1,6 @@
 use std
 use crypto
 
-use "util"
-
 const main = {
 	hasheq(crypto.md5("")[:], \
 		"d41d8cd98f00b204e9800998ecf8427e")
@@ -16,3 +14,16 @@
 		"3b0bb4c5ece4a6568caa7266e740a140")
 }
 
+const hasheq = {got, expected
+	var sb, str
+
+	sb = std.mksb()
+	for x : got
+		std.sbfmt(sb, "{p=0,w=2,x}", x)
+	;;
+	str = std.sbfin(sb)
+	if (!std.sleq(str, expected))
+		std.fatal("mismatched hashes:\n\tgot:\t{}\n\texpected:\t{}\n", str, expected)
+	;;
+	std.slfree(str)
+}
--- a/lib/crypto/test/sha1.myr
+++ b/lib/crypto/test/sha1.myr
@@ -1,8 +1,6 @@
 use std
 use crypto
 
-use "util"
-
 const main = {
 	hasheq(crypto.sha1("")[:], \
 		"da39a3ee5e6b4b0d3255bfef60951890d8af0709")
@@ -16,3 +14,16 @@
 		"4eb17e52bb55910b037869438f69d9c87643d75a")
 }
 
+const hasheq = {got, expected
+	var sb, str
+
+	sb = std.mksb()
+	for x : got
+		std.sbfmt(sb, "{p=0,w=2,x}", x)
+	;;
+	str = std.sbfin(sb)
+	if (!std.sleq(str, expected))
+		std.fatal("mismatched hashes:\n\tgot:\t{}\n\texpected:\t{}\n", str, expected)
+	;;
+	std.slfree(str)
+}
--- a/lib/crypto/test/sha256.myr
+++ b/lib/crypto/test/sha256.myr
@@ -1,8 +1,6 @@
 use std
 use crypto
 
-use "util"
-
 const main = {
 	hasheq(crypto.sha224("")[:], \
 		"d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f")
@@ -27,3 +25,16 @@
 		"bac8bf0f9794a520a5bf0ec64d3206edd1b9f2ef5ea118c9cad5365d84578de4")
 }
 
+const hasheq = {got, expected
+	var sb, str
+
+	sb = std.mksb()
+	for x : got
+		std.sbfmt(sb, "{p=0,w=2,x}", x)
+	;;
+	str = std.sbfin(sb)
+	if (!std.sleq(str, expected))
+		std.fatal("mismatched hashes:\n\tgot:\t{}\n\texpected:\t{}\n", str, expected)
+	;;
+	std.slfree(str)
+}
--- a/lib/crypto/test/sha512.myr
+++ b/lib/crypto/test/sha512.myr
@@ -1,8 +1,6 @@
 use std
 use crypto
 
-use "util"
-
 const main = {
 	hasheq(crypto.sha384("")[:], \
 		"38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b")
@@ -27,3 +25,17 @@
 		"d5c989d2e41299b6bfd57562b4b09cd2efa56f13c8fa109e0ce5ddbd6bfb5b34f8563608d6162104bef750023732581f22704d5df43feecbb05742be1d7c34fa")
 }
 
+
+const hasheq = {got, expected
+	var sb, str
+
+	sb = std.mksb()
+	for x : got
+		std.sbfmt(sb, "{p=0,w=2,x}", x)
+	;;
+	str = std.sbfin(sb)
+	if (!std.sleq(str, expected))
+		std.fatal("mismatched hashes:\n\tgot:\t{}\n\texpected:\t{}\n", str, expected)
+	;;
+	std.slfree(str)
+}
--- a/lib/crypto/test/util.myr
+++ /dev/null
@@ -1,19 +1,0 @@
-use std
-
-pkg =
-	const hasheq	: (got : byte[:], expected : byte[:] -> void)
-;;
-
-const hasheq = {got, expected
-	var sb, str
-
-	sb = std.mksb()
-	for x : got
-		std.sbfmt(sb, "{p=0,w=2,x}", x)
-	;;
-	str = std.sbfin(sb)
-	if (!std.sleq(str, expected))
-		std.fatal("mismatched hashes:\n\tgot:\t{}\n\texpected:\t{}\n", str, expected)
-	;;
-	std.slfree(str)
-}
--- /dev/null
+++ b/lib/crypto/util.myr
@@ -1,0 +1,19 @@
+use std
+
+pkg testutil =
+	const hasheq	: (got : byte[:], expected : byte[:] -> void)
+;;
+
+const hasheq = {got, expected
+	var sb, str
+
+	sb = std.mksb()
+	for x : got
+		std.sbfmt(sb, "{p=0,w=2,x}", x)
+	;;
+	str = std.sbfin(sb)
+	if (!std.sleq(str, expected))
+		std.fatal("mismatched hashes:\n\tgot:\t{}\n\texpected:\t{}\n", str, expected)
+	;;
+	std.slfree(str)
+}
--- a/lib/thread/bld.sub
+++ b/lib/thread/bld.sub
@@ -45,3 +45,7 @@
         lib ../sys:sys
         lib ../std:std
 ;;
+
+lib testutil =
+	util.myr
+;;
--- a/lib/thread/test/atomic.myr
+++ b/lib/thread/test/atomic.myr
@@ -1,7 +1,7 @@
 use std
 use thread
 
-use "util"
+use testutil
 
 const Nherd = 20
 
@@ -11,7 +11,7 @@
 const main = {
 	done = 0
 	val = 0
-	mkherd(Nherd, incvar)
+	testutil.mkherd(Nherd, incvar)
 	while thread.xget(&done) != Nherd
 		/* nothing */
 	;;
--- a/lib/thread/test/mutex.myr
+++ b/lib/thread/test/mutex.myr
@@ -1,7 +1,7 @@
 use std
 use thread
 
-use "util"
+use testutil
 
 const Nherd = 20
 
@@ -14,7 +14,7 @@
 	val = 0
 
 	mtx = thread.mkmtx()
-	mkherd(Nherd, incvar)
+	testutil.mkherd(Nherd, incvar)
 	while thread.xget(&done) != Nherd
 		/* nothing */
 	;;
--- a/lib/thread/test/util.myr
+++ /dev/null
@@ -1,12 +1,0 @@
-use std
-use thread
-
-pkg =
-	const mkherd : (n : uint32, fn : (-> void) ->void)
-;;
-
-const mkherd = {n, fn
-	for var i = 0; i < n; i++
-		std.try(thread.spawn(fn))
-	;;
-}
--- /dev/null
+++ b/lib/thread/util.myr
@@ -1,0 +1,12 @@
+use std
+use thread
+
+pkg testutil =
+	const mkherd : (n : uint32, fn : (-> void) ->void)
+;;
+
+const mkherd = {n, fn
+	for var i = 0; i < n; i++
+		std.try(thread.spawn(fn))
+	;;
+}
--- a/mk/c.mk
+++ b/mk/c.mk
@@ -9,7 +9,7 @@
 _LIBPATHS=$(addprefix -l, $(patsubst lib%.a,%,$(notdir $(DEPS)))) $(_PCLIBS)
 
 # yeah, I should probably remove -Werror, but it's nice for developing alone.
-CFLAGS += -Wall -Werror -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare -Wno-char-subscripts -g -O0
+CFLAGS += -Wall -Werror -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare -Wno-char-subscripts -g -O3
 CFLAGS += -MMD -MP -MF .deps/$(subst /,-,$*).d
 
 LIB ?= $(INSTLIB)