mirror of https://github.com/vitalif/phantomjs
Implement system.args to get command-line arguments.
This also means that phantom.args is deprecated. Based on the initial work from execjosh: https://github.com/ariya/phantomjs/pull/192 See also http://wiki.commonjs.org/wiki/System#System_Interface. http://code.google.com/p/phantomjs/issues/detail?id=270 http://code.google.com/p/phantomjs/issues/detail?id=2761.5
parent
119e1ba516
commit
545a3f76b4
|
@ -243,9 +243,15 @@ QObject *Phantom::createFilesystem()
|
|||
|
||||
QObject *Phantom::createSystem()
|
||||
{
|
||||
if (!m_system)
|
||||
if (!m_system) {
|
||||
m_system = new System(this);
|
||||
|
||||
QStringList systemArgs;
|
||||
systemArgs += m_config.scriptFile();
|
||||
systemArgs += m_config.scriptArgs();
|
||||
m_system->setArgs(systemArgs);
|
||||
}
|
||||
|
||||
return m_system;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,18 @@ System::System(QObject *parent) :
|
|||
{
|
||||
}
|
||||
|
||||
void System::setArgs(const QStringList &args)
|
||||
{
|
||||
m_args = args;
|
||||
}
|
||||
|
||||
QStringList System::args() const
|
||||
{
|
||||
return m_args;
|
||||
}
|
||||
|
||||
void System::initCompletions()
|
||||
{
|
||||
addCompletion("args");
|
||||
addCompletion("platform");
|
||||
}
|
||||
|
|
|
@ -42,11 +42,16 @@
|
|||
class System : public REPLCompletable
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QStringList args READ args)
|
||||
|
||||
public:
|
||||
explicit System(QObject *parent = 0);
|
||||
|
||||
void setArgs(const QStringList& args);
|
||||
QStringList args() const;
|
||||
|
||||
private:
|
||||
QStringList m_args;
|
||||
virtual void initCompletions();
|
||||
};
|
||||
|
||||
|
|
|
@ -13,4 +13,17 @@ describe("System object", function() {
|
|||
it("should have platform set to 'phantomjs'", function() {
|
||||
expect(system.platform).toEqual('phantomjs');
|
||||
});
|
||||
|
||||
it("should have args as array", function() {
|
||||
expect(system.args instanceof Array).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should have args with at least one item", function() {
|
||||
expect(system.args.length >= 1).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should have args[0] as the this test runner", function() {
|
||||
expect(system.args[0]).toEqual('run-tests.js');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue