diff options
| author | Alexander M Pickering <alex@cogarr.net> | 2025-01-09 18:11:46 -0600 |
|---|---|---|
| committer | Alexander M Pickering <alex@cogarr.net> | 2025-01-09 18:11:46 -0600 |
| commit | decb72f936060a65bff18e9cbf33642ea3a71cd0 (patch) | |
| tree | 3b07bb1bfc1e4f0e39ec4ff8e0c243cd4fab0d61 /spec/log_spec.lua | |
| parent | 726876d42270f8974fd495be91127ea7585472ff (diff) | |
| download | ggj25-decb72f936060a65bff18e9cbf33642ea3a71cd0.tar.gz ggj25-decb72f936060a65bff18e9cbf33642ea3a71cd0.tar.bz2 ggj25-decb72f936060a65bff18e9cbf33642ea3a71cd0.zip | |
Work
Diffstat (limited to 'spec/log_spec.lua')
| -rw-r--r-- | spec/log_spec.lua | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/log_spec.lua b/spec/log_spec.lua new file mode 100644 index 0000000..415c72e --- /dev/null +++ b/spec/log_spec.lua @@ -0,0 +1,53 @@ +describe("log module", function() + before_each(function() + local succ, log= pcall(require,"log") + if succ then log.reset() end + end) + it("should load",function() + require("log") + end) + it("should ingest a log",function() + local log = require("log") + log.log("test",nil,"blah") + end) + it("should return ingested logs from levels",function() + local log = require("log") + local ret = {} + log.log("test",nil,"blah") + log.of_level("blah",function(msg) + table.insert(ret, msg) + end) + assert(#ret == 1) + assert(ret[1].message == "test") + end) + it("should return ingested logs from tags", function() + local log = require("log") + local ret = {} + log.info("one",{"one"}) + log.info("two",{"two"}) + log.info("one two",{"one","two"}) + log.of_tags({"one"},function(msg) + table.insert(ret,msg) + end) + assert(#ret == 2) + assert(ret[1].message == "one") + assert(ret[2].message == "one two") + end) + it("should allow observers to see the message stream", function() + local log = require("log") + local ret = {} + log.observe(function(chunk) + if chunk.level == "panic" then + table.insert(ret,chunk) + end + end) + log.info("one") + log.info("two") + assert(#ret == 0) + log.panic("three") + assert(#ret == 1) + log.info("four") + assert(#ret == 1) + assert(ret[1].message == "three") + end) +end) |
