#!/usr/bin/env qore
# -*- mode: qore; indent-tabs-mode: nil -*-

%new-style
%enable-all-warnings
%require-types
%strict-args

%requires ../../../../qlib/QUnit.qm

%exec-class BackquoteTest

class BackquoteTest inherits QUnit::Test {
    constructor() : QUnit::Test("Backquote test", "1.0") {
        addTestCase("Backquote test", \testBackquote());
        set_return_value(main());
    }

    testBackquote() {
        if (PlatformOS == "Windows")
            testSkip("skipping because the test is being run on Windows");

        assertEq("1", chomp(`/bin/echo 1`), "backquotes 1");
        assertEq("Qore is great!", chomp(`/bin/echo "Qore is great!"`), "backquotes 2");
        assertEq("Qore is great!", chomp(`/bin/echo Qore is great!`), "backquotes 3");
        assertEq("1", chomp(backquote("/bin/echo 1")), "backquote function");
        int rc;
%ifndef Windows
        backquote("cat /abcDefGHm54sdvdsCE54dfhbgzgGH45J5g4bbg4dfwrtEFG5 2>/dev/null", \rc);
%else
        backquote("cat /abcDefGHm54sdvdsCE54dfhbgzgGH45J5g4bbg4dfwrtEFG5 2>nul", \rc);
%endif
        assertEq(1, rc);
    }
}
