diff --git a/test-suite.html b/test-suite.html index 79fed5e6e7..0dbd535016 100644 --- a/test-suite.html +++ b/test-suite.html @@ -50,7 +50,7 @@

Writing tests

Language directories

All tests are sorted into directories in the tests/languages directory. Each directory name encodes, which language you are currently testing.

-

All language names must match the names from the definition in components.js.

+

All language names must match the names from the definition in components.json.

Example 1: testing a language in isolation (default use case)

Just put your test file into the directory of the language you want to test.

@@ -92,8 +92,8 @@

Writing your test

  • Your language snippet. The code you want to tokenize using Prism. (required)
  • The simplified token stream you expect. Needs to be valid JSON. (optional)
    - Instead of manually inserting the expected token stream yourself, prefer using the npm run test:languages -- --insert command. You can read more about this and related commands here.
    - If there no token stream defined, the test case will fail unless the --insert or --update flag is present when running the test command. + The test runner will automatically insert this if not present. Carefully check that the inserted token stream is what you expected.
    + If the test case fails because the JSON is present but incorrect, then you can use the --update flag to overwrite it.
  • A brief comment explaining the test case. (optional)
  • @@ -122,7 +122,7 @@

    The easy way to write tests

  • Create a new test case file tests/languages/{language}/{test-case}.test.
  • Insert the code you want to test (and nothing more).
  • Repeat the first two steps for as many test cases as you want.
  • -
  • Run npm run test:languages -- --insert.
  • +
  • Run npm run test:languages.
  • Done.
  • @@ -135,28 +135,16 @@

    The easy way to write tests

    This works by making the test runner insert the actual token stream of you test code as the expected token stream. Carefully check that the inserted token stream is actually what you expect or else the test is meaningless!

    -

    More details about the command can be found here.

    -

    Insert and update expected token streams

    +

    Updating tests

    -

    When creating and changing languages, their test files have to be updated to properly test the language. The rather tedious task of updating test files can be automated using the following commands:

    +

    When creating and changing languages, their test files have to be updated to properly test the language. The rather tedious task of updating test files can be automated using the following command:

    - +

    Updates (overwrites) the expected token stream of all failing test files. The language tests are guaranteed to pass after running this command.

    -

    Keep in mind: Both commands make it easy to create/update test files but this doesn't mean that the tests will be correct. Always carefully check the inserted/updated token streams!

    +

    Keep in mind: This command makes it easy to create/update test files but this doesn't mean that the tests will be correct. Always carefully check the inserted/updated token streams!

    Explaining the simplified token stream

    @@ -169,7 +157,7 @@

    Explaining the sim
  • All empty structures are removed.
  • -

    Note: The pretty-printed simplified token stream is indented using 4 spaces. You have to convert these to tabs after you copy-pasted the JSON. (Most editors today have an option that handles the conversion for you.)

    +

    The simplified token stream does not contain the aliases of a token.

    For further information: reading the tests of the test runner (tests/testrunner-tests.js) will help you understand the transformation.

    diff --git a/tests/run.js b/tests/run.js index 6c88f8708a..d6a388295e 100644 --- a/tests/run.js +++ b/tests/run.js @@ -12,7 +12,6 @@ const testSuite = // load complete test suite : TestDiscovery.loadAllTests(__dirname + '/languages'); -const insert = !!argv.accept || !!argv.insert; const update = !!argv.update; // define tests for all tests in all languages in the test suite @@ -30,7 +29,7 @@ for (const language in testSuite) { it("– should pass test case '" + fileName + "'", function () { if (path.extname(filePath) === '.test') { - TestCase.runTestCase(language, filePath, update ? 'update' : insert ? 'insert' : 'none'); + TestCase.runTestCase(language, filePath, update ? 'update' : 'insert'); } else { TestCase.runTestsWithHooks(language, require(filePath)); }