1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the V4VM module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28#include <QJSEngine>
29#include <QCoreApplication>
30#include <QCommandLineParser>
31#include <qdebug.h>
32#include <stdlib.h>
33
34#include "test262runner.h"
35
36int main(int argc, char **argv)
37{
38 QCoreApplication app(argc, argv);
39
40
41 QCommandLineParser parser;
42 parser.addHelpOption();
43 parser.addVersionOption();
44 QCommandLineOption verbose("verbose", "Verbose output");
45 parser.addOption(commandLineOption: verbose);
46 QCommandLineOption commandOption("command", "Javascript command line interpreter", "command");
47 parser.addOption(commandLineOption: commandOption);
48 QCommandLineOption testDir("tests", "path to the tests", "tests", "test262");
49 parser.addOption(commandLineOption: testDir);
50 QCommandLineOption cat("cat", "Print packaged test code that would be run");
51 parser.addOption(commandLineOption: cat);
52 QCommandLineOption parallel("parallel", "Run tests in parallel");
53 parser.addOption(commandLineOption: parallel);
54 QCommandLineOption jit("jit", "JIT all code");
55 parser.addOption(commandLineOption: jit);
56 QCommandLineOption bytecode("interpret", "Run using the bytecode interpreter");
57 parser.addOption(commandLineOption: bytecode);
58 QCommandLineOption withExpectations("with-test-expectations", "Parse TestExpectations to deal with known failures");
59 parser.addOption(commandLineOption: withExpectations);
60 QCommandLineOption updateExpectations("update-expectations", "Update TestExpectations to remove unexepected passes");
61 parser.addOption(commandLineOption: updateExpectations);
62 QCommandLineOption writeExpectations("write-expectations", "Generate a new TestExpectations file based on the results of the run");
63 parser.addOption(commandLineOption: writeExpectations);
64 parser.addPositionalArgument(name: "[filter]", description: "Only run tests that contain filter in their name");
65
66 parser.process(app);
67
68 Test262Runner testRunner(parser.value(option: commandOption), parser.value(option: testDir));
69
70 QStringList otherArgs = parser.positionalArguments();
71 if (otherArgs.size() > 1) {
72 qWarning() << "too many arguments";
73 return 1;
74 } else if (otherArgs.size()) {
75 testRunner.setFilter(otherArgs.at(i: 0));
76 }
77
78 if (parser.isSet(option: cat)) {
79 testRunner.cat();
80 return 0;
81 }
82
83 if (parser.isSet(option: updateExpectations) && parser.isSet(option: writeExpectations)) {
84 qWarning() << "Can only specify one of --update-expectations and --write-expectations.";
85 exit(status: 1);
86 }
87
88 if (parser.isSet(option: jit) && parser.isSet(option: bytecode)) {
89 qWarning() << "Can only specify one of --jit and --interpret.";
90 exit(status: 1);
91 }
92
93 int flags = 0;
94 if (parser.isSet(option: verbose))
95
96 flags |= Test262Runner::Verbose;
97 if (parser.isSet(option: parallel))
98 flags |= Test262Runner::Parallel;
99 if (parser.isSet(option: jit))
100 flags |= Test262Runner::ForceJIT;
101 if (parser.isSet(option: bytecode))
102 flags |= Test262Runner::ForceBytecode;
103 if (parser.isSet(option: withExpectations))
104 flags |= Test262Runner::WithTestExpectations;
105 if (parser.isSet(option: updateExpectations))
106 flags |= Test262Runner::UpdateTestExpectations;
107 if (parser.isSet(option: writeExpectations))
108 flags |= Test262Runner::WriteTestExpectations;
109 testRunner.setFlags(flags);
110
111 if (testRunner.run())
112 return EXIT_SUCCESS;
113 else
114 return EXIT_FAILURE;
115}
116

source code of qtdeclarative/tests/auto/qml/ecmascripttests/qjstest/main.cpp