Skip to content

Commit

Permalink
Add a spot check for directories that don't contain tests (#1791)
Browse files Browse the repository at this point in the history
Closes #1433
  • Loading branch information
nex3 committed Jun 13, 2022
1 parent de163b0 commit 7e47b81
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 32 deletions.
4 changes: 4 additions & 0 deletions lib-js/spec-directory/spec-directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,8 @@ export default abstract class SpecDirectory {
}
}
}

toString(): string {
return this.path;
}
}
16 changes: 8 additions & 8 deletions spec/core_functions/list/zip.hrx
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<===> README.md
`zip()` is unique among built-in functions in that there's no possible
invocation that produces an error, since it can take any number of arguments and
any argument can be interpreted as a list. Since we don't normally test for
passing invalid named parameters, it has no error tests.

<===>
================================================================================
<===> no_lists/input.scss
@import "core_functions/list/utils";

Expand Down Expand Up @@ -191,11 +199,3 @@ a {b: zip(c, d, e)}
a {
b: c d e;
}

<===>
================================================================================
<===> error/README.md
`zip()` is unique among built-in functions in that there's no possible
invocation that produces an error, since it can take any number of arguments and
any argument can be interpreted as a list. Since we don't normally test for
passing invalid named parameters, it has no error tests.
22 changes: 0 additions & 22 deletions spec/libsass-closed-issues/47_str_slice/output.css

This file was deleted.

5 changes: 3 additions & 2 deletions spec/libsass-closed-issues/issue_2863.hrx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<===> input.scss
<===> input.scss
$squoted: "'dquoted'";
$dquoted: "\"squoted\"";

Expand All @@ -10,7 +10,8 @@ test {
str-insert-single: str-insert( $squoted, "p", 2 );
str-insert-double: str-insert( $dquoted, "p", 2 );
}
<===> output.css

<===> output.css
test {
str-slice-single: "'d";
str-slice-double: '"s';
Expand Down
29 changes: 29 additions & 0 deletions test/spot-check.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as p from 'path';
import * as specDirectory from '../lib-js/spec-directory';

// Spot checks for common spec errors.

it('every directory contains or is contained by a test', async () => {
// Verifies that `dir` either is a test, or that all its children are tests.
async function verifyDirectory(
dir: specDirectory.SpecDirectory
): Promise<void> {
if (dir.isTestDir()) return;

const subdirs = await dir.subdirs();
if (subdirs.length === 0) {
// Empty directories aren't recorded by Git, so we allow them.
if ((await dir.listFiles()).length === 0) return;

const path = p.relative(process.cwd(), dir.path);
throw new Error(
`Directory ${path} is neither a test, the child of a test, nor the ` +
'parent of a test.'
);
} else {
await Promise.all(subdirs.map(verifyDirectory));
}
}

await verifyDirectory(await specDirectory.fromPath('spec'));
});

0 comments on commit 7e47b81

Please sign in to comment.