Skip to content

Commit d05b508

Browse files
authored
Import spec tests for awk, jq and sed (#53)
1 parent e776055 commit d05b508

File tree

342 files changed

+83047
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

342 files changed

+83047
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* Vitest runner for onetrueawk spec tests
3+
*
4+
* This runs the imported spec tests from the onetrueawk project against just-bash's awk.
5+
*/
6+
7+
import * as fs from "node:fs";
8+
import * as path from "node:path";
9+
import { describe, expect, it } from "vitest";
10+
import { parseAwkTestFile } from "./parser.js";
11+
import { formatError, runAwkTestCase } from "./runner.js";
12+
import { getSkipReason, isFileSkipped } from "./skips.js";
13+
14+
const CASES_DIR = path.join(__dirname, "cases");
15+
16+
// Get all T.* test files (the systematic test scripts)
17+
// Filter: starts with T., no file extension (no second dot)
18+
const ALL_TEST_FILES = fs
19+
.readdirSync(CASES_DIR)
20+
.filter((f) => f.startsWith("T.") && f.indexOf(".", 2) === -1)
21+
.sort();
22+
23+
// Filter out completely skipped files
24+
const TEST_FILES = ALL_TEST_FILES.filter((f) => !isFileSkipped(f));
25+
26+
/**
27+
* Truncate program for test name display
28+
*/
29+
function truncateProgram(program: string, maxLen = 50): string {
30+
const normalized = program
31+
.split("\n")
32+
.map((l) => l.trim())
33+
.filter((l) => l)
34+
.join(" ");
35+
36+
if (normalized.length <= maxLen) {
37+
return normalized;
38+
}
39+
return `${normalized.slice(0, maxLen - 3)}...`;
40+
}
41+
42+
describe("OneTrue AWK Spec Tests", () => {
43+
for (const fileName of TEST_FILES) {
44+
const filePath = path.join(CASES_DIR, fileName);
45+
46+
describe(fileName, () => {
47+
// Parse the test file
48+
const content = fs.readFileSync(filePath, "utf-8");
49+
const parsed = parseAwkTestFile(content, filePath);
50+
51+
// Skip files with no parseable tests
52+
if (parsed.testCases.length === 0) {
53+
it.skip("No parseable tests", () => {});
54+
return;
55+
}
56+
57+
for (const testCase of parsed.testCases) {
58+
// Check for individual test skip (pass program for pattern matching)
59+
const skipReason = getSkipReason(
60+
fileName,
61+
testCase.name,
62+
testCase.program,
63+
);
64+
if (skipReason) {
65+
testCase.skip = skipReason;
66+
}
67+
68+
const programPreview = truncateProgram(testCase.program);
69+
const testName = `[L${testCase.lineNumber}] ${testCase.name}: ${programPreview}`;
70+
71+
it(testName, async () => {
72+
const result = await runAwkTestCase(testCase);
73+
74+
if (result.skipped) {
75+
return;
76+
}
77+
78+
if (!result.passed) {
79+
expect.fail(formatError(result));
80+
}
81+
});
82+
}
83+
});
84+
}
85+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
oldawk=${oldawk-awk}
3+
awk=${awk-../a.out}
4+
5+
echo oldawk=$oldawk, awk=$awk
6+
7+
for i in T.*
8+
do
9+
$i
10+
done
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# an arbitrary collection of input data
2+
3+
cat td.1 td.1 >foo.td
4+
sed 's/^........................//' td.1 >>foo.td
5+
pr -m td.1 td.1 td.1 >>foo.td
6+
pr -2 td.1 >>foo.td
7+
wc foo.td
8+
9+
td=foo.td
10+
>footot
11+
12+
for i in $*
13+
do
14+
echo $i >/dev/tty
15+
echo $i '<<<'
16+
cd ..
17+
echo testdir/$i:
18+
ind <testdir/$i
19+
a.out -f testdir/$i >drek.c
20+
cat drek.c
21+
make drek || ( echo $i ' ' bad compile; echo $i ' ' bad compile >/dev/tty; continue )
22+
cd testdir
23+
24+
time /usr/bin/awk -f $i $td >foo2 2>foo2t
25+
cat foo2t
26+
time ../drek $td >foo1 2>foo1t
27+
cat foo1t
28+
cmp foo1 foo2 || ( echo $i ' ' bad; echo $i ' ' bad >/dev/tty; diff foo1 foo2 | sed 20q )
29+
echo '>>>' $i
30+
echo
31+
echo $i: >>footot
32+
cat foo1t foo2t >>footot
33+
done
34+
35+
ctimes footot

src/awk-spec-tests/cases/Compare.p

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
oldawk=${oldawk-awk}
3+
awk=${awk-../a.out}
4+
5+
echo oldawk=$oldawk, awk=$awk
6+
7+
for i
8+
do
9+
echo "$i:"
10+
$oldawk -f $i test.countries test.countries >foo1
11+
$awk -f $i test.countries test.countries >foo2
12+
if cmp -s foo1 foo2
13+
then true
14+
else echo -n "$i: BAD ..."
15+
fi
16+
diff -b foo1 foo2 | sed -e 's/^/ /' -e 10q
17+
done

src/awk-spec-tests/cases/Compare.t

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
oldawk=${oldawk-myawk}
3+
awk=${awk-../a.out}
4+
5+
echo oldawk=$oldawk, awk=$awk
6+
7+
for i
8+
do
9+
echo "$i:"
10+
$oldawk -f $i test.data >foo1
11+
$awk -f $i test.data >foo2
12+
if cmp -s foo1 foo2
13+
then true
14+
else echo -n "$i: BAD ..."
15+
fi
16+
diff -b foo1 foo2 | sed -e 's/^/ /' -e 10q
17+
done
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
3+
oldawk=${oldawk-awk}
4+
awk=${awk-../a.out}
5+
6+
echo compiling time.c
7+
cc time.c -o time
8+
time=./time
9+
10+
echo time command = $time
11+
12+
#case `uname` in
13+
#SunOS)
14+
# time=/usr/bin/time ;;
15+
#Linux)
16+
# time=/usr/bin/time ;;
17+
#*)
18+
# time=time ;;
19+
#esac
20+
21+
echo oldawk = $oldawk, awk = $awk, time command = $time
22+
23+
24+
# an arbitrary collection of input data
25+
26+
cat td.1 td.1 >foo.td
27+
sed 's/^........................//' td.1 >>foo.td
28+
pr -m td.1 td.1 td.1 >>foo.td
29+
pr -2 td.1 >>foo.td
30+
cat bib >>foo.td
31+
wc foo.td
32+
33+
td=foo.td
34+
>footot
35+
36+
for i in $*
37+
do
38+
echo $i "($oldawk vs $awk)":
39+
# ind <$i
40+
$time $oldawk -f $i $td >foo2 2>foo2t
41+
cat foo2t
42+
$time $awk -f $i $td >foo1 2>foo1t
43+
cat foo1t
44+
cmp foo1 foo2
45+
echo $i: >>footot
46+
cat foo1t foo2t >>footot
47+
done
48+
49+
ctimes footot

src/awk-spec-tests/cases/LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/****************************************************************
2+
Copyright (C) Lucent Technologies 1997
3+
All Rights Reserved
4+
5+
Permission to use, copy, modify, and distribute this software and
6+
its documentation for any purpose and without fee is hereby
7+
granted, provided that the above copyright notice appear in all
8+
copies and that both that the copyright notice and this
9+
permission notice and warranty disclaimer appear in supporting
10+
documentation, and that the name Lucent Technologies or any of
11+
its entities not be used in advertising or publicity pertaining
12+
to distribution of the software without specific, written prior
13+
permission.
14+
15+
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16+
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
17+
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
18+
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
20+
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
21+
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
22+
THIS SOFTWARE.
23+
****************************************************************/

src/awk-spec-tests/cases/NOTES

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Need some tests for octal, hex, various string escapes.
2+
3+
Need to complete the sub and gsub tests.
4+
5+
more on printf, especially weird formats
6+
7+
more on operators
8+
9+
10+
never throw away a test
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
The archive of test files contains
2+
3+
- A shell file called REGRESS that controls the testing process.
4+
5+
- Several shell files called Compare* that control sub-parts
6+
of the testing.
7+
8+
- About 160 small tests called t.* that constitute a random
9+
sampling of awk constructions collected over the years.
10+
Not organized, but they touch almost everything.
11+
12+
- About 60 small tests called p.* that come from the first
13+
two chapters of The AWK Programming Language. This is
14+
basic stuff -- they have to work.
15+
16+
These two sets are intended as regression tests, to be sure
17+
that a new version produces the same results as a previous one.
18+
There are a couple of standard data files used with them,
19+
test.data and test.countries, but others would work too.
20+
21+
- About 20 files called T.* that are self-contained and
22+
more systematic tests of specific language features.
23+
For example, T.clv tests command-line variable handling.
24+
These tests are not regressions -- they compute the right
25+
answer by separate means, then compare the awk output.
26+
A specific test for each new bug found shows up in at least
27+
one of these, most often T.misc. There are about 220 tests
28+
total in these files.
29+
30+
- Two of these files, T.re and T.sub, are systematic tests
31+
of the regular expression and substitution code. They express
32+
tests in a small language, then generate awk programs that
33+
verify behavior.
34+
35+
- About 20 files called tt.* that are used as timing tests;
36+
they use the most common awk constructions in straightforward
37+
ways, against a large input file constructed by Compare.tt.
38+
39+
40+
There is undoubtedly more stuff in the archive; it's been
41+
collecting for years and may need pruning. Suggestions for
42+
improvement, additional tests (especially systematic ones),
43+
and the like are all welcome.
44+

src/awk-spec-tests/cases/REGRESS

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
uname -a
4+
cc echo.c -o echo && echo echo compiled
5+
6+
oldawk=${oldawk-awk}
7+
awk=${awk-../a.out}
8+
9+
echo oldawk=$oldawk, awk=$awk
10+
11+
oldawk=$oldawk awk=$awk Compare.t t.*
12+
echo `ls t.* | wc -l` tests; echo
13+
14+
oldawk=$oldawk awk=$awk Compare.p p.? p.??*
15+
echo `ls p.* | wc -l` tests; echo
16+
17+
oldawk=$oldawk awk=$awk Compare.T1
18+
echo `grep '\$awk' T.* | wc -l` tests; echo
19+
20+
oldawk=$oldawk awk=$awk Compare.tt tt.*
21+
echo `ls tt.* | wc -l` tests; echo

0 commit comments

Comments
 (0)