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

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

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

%exec-class SystemCallTest

class SystemCallTest inherits QUnit::Test {
    constructor() : Test("SystemCallTest", "1.0") {
        addTestCase("system() test", \testMethod());

        # Return for compatibility with test harness that checks return value
        set_return_value(main());
    }

    testMethod() {
%ifdef Windows
        testSkip("Windows");
%endif
        string file = tmp_location() + "/output";

        testAssertion("system() call", \system(), "/bin/echo OUTPUT > " + file, 0);
        on_exit unlink(file);

        assertEq("OUTPUT", chomp(ReadOnlyFile::readTextFile(file)));
    }
}
