Autogenerated .DS_Store files on macOS are included in detect test suite #3973
Labels
bug
good first issue
Should be easier for first time contributors
help welcome
Could use help from community
parser
Summary
macOS occasionally generates
.DS_Store
files to store metadata about a directory for its builtin Finder application. Unfortunately, this can sometimes happen in atest/detect
directory and generate erroneous detect test cases. Once the file exists, it's pretty hard to permanently remove it, as macOS will almost instantly regenerate the file if it is manually removed byrm -f .DS_Store
or by other means.Reproduction Steps
Unfortunately, I cannot seem to reliably trigger the heuristic that generates the .DS_Store file, so instead one can emulate the behavior by doing the following:
highlight.js
repositoryecho '[hello]' > test/detect/1c/.DS_Store
from the repository rootnode ./tools/build.js -t node
npm run test
AssertionError: .DS_Store should be detected as 1c, but was angelscript
Expected behavior
Since the user has little control over
.DS_Store
files, skip.DS_Store
files when iterating through the directory here:highlight.js/test/detect/index.js
Lines 20 to 22 in e964bec
Additional context
There are several ways to approach the problem:
1. Indiscriminately skip all
.DS_Store
filesconst filenames = await fs.readdir(languagePath); await Promise.all(filenames + .filter(filename => filename !== '.DS_Store') .map(async function(example) {
This is the easiest to implement, effectively hardcoding a blocklist of
.DS_Store
files.If someone decided to make a language that used the
.DS_Store
extension, they can still just name the detect test file something liketestcase.txt
, since the current test runner does not care about file extensions.2. Only skip all
.DS_Store
files on macOSconst filenames = await fs.readdir(languagePath); await Promise.all(filenames + .filter(filename => process.platform !== "darwin" || filename !== '.DS_Store') .map(async function(example) {
This does not skip
.DS_Store
on other platforms.You could also optimize it into a one-time check for other platforms:
The main drawback is that it technically causes inconsistent behavior between platforms (where the test only ignores the file on macOS), so the indiscriminate block suggested in (1) may be preferable.
3. Do nothing
This kinda sucks but since nobody reported this before I guess it's not a very common issue.
The text was updated successfully, but these errors were encountered: