• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ArkScript-lang / Ark / 14823373998

04 May 2025 05:03PM UTC coverage: 86.442% (+0.03%) from 86.409%
14823373998

push

github

SuperFola
fix: change the color of the function name inside runtime typechecking errors from blue to cyan to be easier to read inside dark terminals

0 of 1 new or added line in 1 file covered. (0.0%)

195 existing lines in 22 files now uncovered.

6835 of 7907 relevant lines covered (86.44%)

79668.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.5
/src/arkreactor/Builtins/System.cpp
1
#include <Ark/Builtins/Builtins.hpp>
2

3
#include <stdio.h>
4
#include <memory>
5
#include <cstdlib>
6
#include <thread>
7

8
#ifdef _MSC_VER
9
#    define popen _popen
10
#    define pclose _pclose
11
#endif
12

13
#undef abs
14
#include <chrono>
15

16
#include <Ark/Constants.hpp>
17
#include <Ark/TypeChecker.hpp>
18
#include <Ark/VM/VM.hpp>
19

20
namespace Ark::internal::Builtins::System
21
{
22
    namespace
23
    {
24
        struct close_file_deleter
25
        {
26
            int operator()(FILE* file) const noexcept
×
27
            {
×
28
                return pclose(file);
×
29
            }
30
        };
31
    }
32

33
    /**
34
     * @name sys:exec
35
     * @brief Execute a system specific command
36
     * @details Return the output of the command as a String, or nil if it was disabled in the ArkScript build
37
     * @param command the command to execute, as a String
38
     * =begin
39
     * (sys:exec "echo hello")
40
     * =end
41
     * @author https://github.com/SuperFola
42
     */
43
    // cppcheck-suppress constParameterReference
44
    Value system_(std::vector<Value>& n, VM* vm [[maybe_unused]])
×
45
    {
×
46
        if (!types::check(n, ValueType::String))
×
47
            throw types::TypeCheckingError(
×
48
                "sys:exec",
×
49
                { { types::Contract { { types::Typedef("command", ValueType::String) } } } },
×
UNCOV
50
                n);
×
51

52
#ifdef ARK_ENABLE_SYSTEM
53
        std::array<char, 128> buffer;
×
54
        std::string result;
×
55
        std::unique_ptr<FILE, close_file_deleter> pipe(popen(n[0].string().c_str(), "r"), close_file_deleter());
×
56
        if (!pipe)
×
57
            throw std::runtime_error("sys:exec: couldn't retrieve command output");
×
58
        while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
×
59
            result += buffer.data();
×
UNCOV
60
        return Value(result);
×
61
#else
62
        return nil;
63
#endif  // ARK_ENABLE_SYSTEM
UNCOV
64
    }
×
65

66
    /**
67
     * @name sys:sleep
68
     * @brief Sleep for a given duration (in milliseconds)
69
     * @details Return nil
70
     * @param duration a Number representing a duration
71
     * =begin
72
     * (sys:sleep 1000)  # sleep for 1 second
73
     * =end
74
     * @author https://github.com/SuperFola
75
     */
76
    // cppcheck-suppress constParameterReference
77
    Value sleep(std::vector<Value>& n, VM* vm [[maybe_unused]])
3✔
78
    {
3✔
79
        if (!types::check(n, ValueType::Number))
3✔
80
            throw types::TypeCheckingError(
2✔
81
                "sys:sleep",
1✔
82
                { { types::Contract { { types::Typedef("duration", ValueType::Number) } } } },
1✔
83
                n);
1✔
84

85
        auto duration = std::chrono::duration<double, std::ratio<1, 1000>>(n[0].number());
2✔
86
        std::this_thread::sleep_for(duration);
2✔
87

88
        return nil;
2✔
89
    }
3✔
90

91
    /**
92
     * @name sys:exit
93
     * @brief Reverse a given list and return a new one
94
     * @details Any code after this function call won't be executed
95
     * @param exitCode usually 0 for success and 1 for errors
96
     * =begin
97
     * (sys:exit 0)  # halt the virtual machine with given exit code (success)
98
     * =end
99
     * @author https://github.com/SuperFola
100
     */
101
    // cppcheck-suppress constParameterReference
102
    Value exit_(std::vector<Value>& n, VM* vm)
×
103
    {
×
104
        if (!types::check(n, ValueType::Number))
×
105
            throw types::TypeCheckingError(
×
UNCOV
106
                "sys:exit",
×
107
                { { types::Contract { { types::Typedef("exitCode", ValueType::Number) } } } },
×
108
                n);
×
109

UNCOV
110
        vm->exit(static_cast<int>(n[0].number()));
×
UNCOV
111
        return nil;
×
UNCOV
112
    }
×
113
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc