Skip to content

Commit 9a0152e

Browse files
committed
0.2.0: the tests are given an implementation, and the example is asserted against wc
Every test in this package failed to link. The package declares against the interface and links against no implementation, which is correct — a consumer chooses one — but its own tests run, and running requires definitions. The implementation is now a development dependency, selected by the platform the tests run upon. The diagnostic was the one clause 4.2 of the specification describes: the package compiled, the link failed, and the linker named sixteen undefined operations. That is later than a compilation failure and it is legible, which is what the clause claims for it. This is the first occasion on which the claim was tested by something other than a deliberate demonstration. The step that ran an example ran a program this repository does not contain and asserted lines it does not print. It is replaced by one that runs the example that is here and compares its output against the system's own counter, so the assertion is that the program produced the right answer rather than that it produced an answer. The assertion that the suites ran is derived from the files present rather than written out, for the same reason it is elsewhere: a hand-written list names the suites that existed when it was written.
1 parent ecb8864 commit 9a0152e

3 files changed

Lines changed: 56 additions & 14 deletions

File tree

.github/workflows/ci.yml

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,44 @@ jobs:
3838
- name: Tests
3939
run: |
4040
mcpp test 2>&1 | tee tests.log
41-
# A suite that discovered nothing reports success, so each case is
42-
# asserted to have run.
43-
grep -q 'paths ... ok' tests.log
44-
grep -q 'files ... ok' tests.log
45-
grep -q 'mutex ... ok' tests.log
4641
42+
# A suite that discovered nothing reports success, so every suite is
43+
# asserted to have run. The list is derived from the files present
44+
# rather than written out here: a hand-written list names the suites
45+
# that existed when it was written, and one added afterwards escapes
46+
# the assertion silently.
47+
missing=0
48+
for f in tests/*.cpp; do
49+
name="$(basename "$f" .cpp)"
50+
if ! grep -q "^$name \.\.\. ok" tests.log; then
51+
echo "suite did not run, or did not pass: $name" >&2
52+
missing=1
53+
fi
54+
done
55+
test "$missing" -eq 0
56+
57+
# The claim this package makes is that a program above it reads a file by
58+
# global path, consults a variable, measures an interval and starts
59+
# another program without containing any of that. The program is compared
60+
# against the system's own counter, so the assertion is that it produced
61+
# the right answer rather than that it produced an answer.
62+
#
63+
# The previous form of this step asserted three lines from a different
64+
# example, in a directory this repository does not contain. It had never
65+
# run: the step before it failed first, and a step that never runs asserts
66+
# nothing while appearing to.
4767
- name: An ordinary program runs above the library
48-
working-directory: examples/hello
68+
working-directory: examples/wordcount
4969
run: |
50-
mcpp run 2>&1 | tee run.log
51-
grep -q 'openkal: hello' run.log
52-
grep -q 'openkal: allocation succeeded' run.log
53-
grep -q 'openkal: vectored writes unavailable' run.log
70+
printf 'alpha beta\ngamma\n' > sample.txt
71+
expected="$(wc < sample.txt | tr -s ' ' | sed 's/^ //')"
72+
WORDCOUNT_VERBOSE=1 mcpp run -- sample.txt 2>&1 | tee run.log
73+
74+
lines="$(sed -n 's/^lines \([0-9]*\) words \([0-9]*\) bytes \([0-9]*\)$/\1 \2 \3/p' run.log)"
75+
test -n "$lines" || { echo "the program printed no count" >&2; exit 1; }
76+
echo "wordcount: $lines"
77+
echo "wc: $expected"
78+
test "$lines" = "$expected"
79+
80+
# The variable was consulted, and the interval was measured.
81+
grep -q 'elapsed .* nanoseconds' run.log

examples/wordcount/mcpp.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ version = "0.1.0"
66
openkal-libc = { path = "../.." }
77

88
[target.'cfg(os = "linux")'.dependencies]
9-
openkal-linux = "0.3.0"
9+
openkal-linux = "0.4.0"
1010

1111
[target.'cfg(os = "macos")'.dependencies]
12-
openkal-macos = "0.1.0"
12+
openkal-macos = "0.2.0"

mcpp.toml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
[package]
22
namespace = "mcpplibs"
33
name = "openkal-libc"
4-
version = "0.1.0"
4+
version = "0.2.0"
55
description = "A C library above openkal rather than above a kernel. Porting it once causes the software above it to run on every openkal implementation, which is the claim the specification makes and this package tests."
66
license = "Apache-2.0"
77
authors = ["mcpplibs"]
88
repo = "https://github.com/mcpplibs/openkal-libc"
99

1010
[dependencies]
11-
openkal = "0.3.0"
11+
openkal = "0.4.0"
12+
13+
# The library declares against the interface and links against no
14+
# implementation: a consumer of it chooses one. Its own tests run, and running
15+
# requires definitions, so an implementation is a development dependency and is
16+
# selected by the platform the tests run upon.
17+
#
18+
# Its absence is why every test in this package failed to link while the package
19+
# itself built: the diagnostic named the undefined operations, which is what
20+
# clause 4.2 of the specification describes.
21+
[target.'cfg(os = "linux")'.dev-dependencies]
22+
openkal-linux = "0.4.0"
23+
24+
[target.'cfg(os = "macos")'.dev-dependencies]
25+
openkal-macos = "0.2.0"

0 commit comments

Comments
 (0)