Annotate

spec/util_strbitop.lua @ 11748:88ba05494d17 0.11

makefile: fix prosody.version target POSIX is quite explicit regarding the precedence of AND-OR lists [0]: > The operators "&&" and "||" shall have equal precedence and shall be > evaluated with left associativity. For example, both of the following > commands write solely `bar` to standard output: > false && echo foo || echo bar > true || echo foo && echo bar Given that, `prosody.version` target behaves as ((((((test -f prosody.release && cp ...) || test -f ...) && sed ...) || test -f ...) && hexdump ...) || echo unknown > $@) In the case of release tarballs, `prosody.release` does exist, so the first AND pair is executed. Given that it's successful, then the first `test -f` in the OR pair is ignored, and instead the `sed` in the AND pair is executed. `sed` success, as `.hg_archival.txt` exists, making the second `test -f` in the OR pair ignored, and `hexdump` in the AND pair is executed. Now, given that `.hg` doesn't exist, it fails, so the last `echo` is run, overwriting `prosody.version` with `unknown`. This can be worked around placing `()` around the AND pairs. Decided to use conditionals instead, as I think they better communicate the intention of the block. [0]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_03
author Lucas <lucas@sexy.is>
date Sun, 15 Aug 2021 04:10:36 +0000
parent 11168:cde600e2fdf9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11168
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local strbitop = require "util.strbitop";
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 describe("util.strbitop", function ()
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 describe("sand()", function ()
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 it("works", function ()
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 assert.equal(string.rep("Aa", 100), strbitop.sand(string.rep("a", 200), "Aa"));
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 end);
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 it("returns empty string if first argument is empty", function ()
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 assert.equal("", strbitop.sand("", ""));
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 assert.equal("", strbitop.sand("", "key"));
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 end);
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 it("returns initial string if key is empty", function ()
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 assert.equal("hello", strbitop.sand("hello", ""));
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 end);
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 end);
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 describe("sor()", function ()
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 it("works", function ()
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 assert.equal(string.rep("a", 200), strbitop.sor(string.rep("Aa", 100), "a"));
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 end);
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 it("returns empty string if first argument is empty", function ()
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 assert.equal("", strbitop.sor("", ""));
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 assert.equal("", strbitop.sor("", "key"));
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 end);
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 it("returns initial string if key is empty", function ()
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 assert.equal("hello", strbitop.sor("hello", ""));
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 end);
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 end);
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 describe("sxor()", function ()
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 it("works", function ()
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 assert.equal(string.rep("Aa", 100), strbitop.sxor(string.rep("a", 200), " \0"));
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 end);
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 it("returns empty string if first argument is empty", function ()
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 assert.equal("", strbitop.sxor("", ""));
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 assert.equal("", strbitop.sxor("", "key"));
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 end);
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 it("returns initial string if key is empty", function ()
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 assert.equal("hello", strbitop.sxor("hello", ""));
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 end);
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 end);
cde600e2fdf9 util.strbitop: Add tests covering basics
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 end);