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

ArkScript-lang / Ark / 15453345670

04 Jun 2025 09:40PM UTC coverage: 86.735% (+0.1%) from 86.608%
15453345670

push

github

SuperFola
chore: updating fuzzing corpus

2 of 3 new or added lines in 2 files covered. (66.67%)

140 existing lines in 7 files now uncovered.

7258 of 8368 relevant lines covered (86.74%)

120482.26 hits per line

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

88.14
/src/arkreactor/Builtins/IO.cpp
1
#include <Ark/Builtins/Builtins.hpp>
2

3
#include <iostream>
4
#include <filesystem>
5
#include <fmt/core.h>
6

7
#include <Ark/Files.hpp>
8
#include <Ark/VM/VM.hpp>
9
#include <Ark/Exceptions.hpp>
10
#include <Ark/TypeChecker.hpp>
11

12
namespace Ark::internal::Builtins::IO
13
{
14
    /**
15
     * @name print
16
     * @brief Print value(s) in the terminal
17
     * @details No separator is put between the values. Adds a \n at the end
18
     * @param values the values to print
19
     * =begin
20
     * (print "hello")
21
     * =end
22
     * @author https://github.com/SuperFola
23
     */
24
    // cppcheck-suppress constParameterReference
25
    Value print(std::vector<Value>& n, VM* vm)
76✔
26
    {
76✔
27
        for (const auto& value : n)
204✔
28
            fmt::print("{}", value.toString(*vm));
128✔
29
        fmt::println("");
76✔
30

31
        return nil;
76✔
32
    }
×
33

34
    /**
35
     * @name puts
36
     * @brief Print value(s) in the terminal
37
     * @details No separator is put between the values, no \n at the end
38
     * @param values the values to print
39
     * =begin
40
     * (puts "hello")
41
     * =end
42
     * @author https://github.com/SuperFola
43
     */
44
    // cppcheck-suppress constParameterReference
45
    Value puts_(std::vector<Value>& n, VM* vm)
257✔
46
    {
257✔
47
        for (const auto& value : n)
573✔
48
            fmt::print("{}", value.toString(*vm));
316✔
49

50
        return nil;
257✔
51
    }
×
52

53
    /**
54
     * @name input
55
     * @brief Request a value from the user
56
     * @details Return the value as a string
57
     * @param prompt (optional) printed before asking for the user input
58
     * =begin
59
     * (input "put a number> ")
60
     * =end
61
     * @author https://github.com/SuperFola
62
     */
63
    // cppcheck-suppress constParameterReference
64
    Value input(std::vector<Value>& n, VM* vm [[maybe_unused]])
×
65
    {
×
66
        if (types::check(n, ValueType::String))
×
67
            fmt::print("{}", n[0].string());
×
68
        else if (!n.empty())
×
69
            throw types::TypeCheckingError("input", { { types::Contract {}, types::Contract { { types::Typedef("prompt", ValueType::String) } } } }, n);
×
70

71
        std::string line;
×
72
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
UNCOV
73
        std::getline(std::cin, line);
×
74
#else
75
        line = "fuzzer input";
76
#endif
77

78
        return Value(line);
×
79
    }
×
80

81
    Value writeFile(std::vector<Value>& n, VM* vm [[maybe_unused]])
3✔
82
    {
3✔
83
        if (types::check(n, ValueType::String, ValueType::Any))
3✔
84
        {
85
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
86
            std::ofstream f(n[0].string());
2✔
87
            if (f.is_open())
2✔
88
            {
89
                f << n[1].toString(*vm);
2✔
90
                f.close();
2✔
91
            }
2✔
92
            else
UNCOV
93
                throw std::runtime_error(fmt::format("io:writeFile: couldn't write to file \"{}\"", n[0].stringRef()));
×
94
#endif
95
        }
3✔
96
        else
97
            throw types::TypeCheckingError(
2✔
98
                "io:writeFile",
1✔
99
                { { types::Contract { { types::Typedef("filename", ValueType::String), types::Typedef("content", ValueType::Any) } } } },
1✔
100
                n);
1✔
101

102
        return nil;
2✔
103
    }
1✔
104

105
    Value appendToFile(std::vector<Value>& n, VM* vm [[maybe_unused]])
3✔
106
    {
3✔
107
        if (types::check(n, ValueType::String, ValueType::Any))
3✔
108
        {
109
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
110
            std::ofstream f(n[0].string(), std::ios::out | std::ios::app);
2✔
111
            if (f.is_open())
2✔
112
            {
113
                f << n[1].toString(*vm);
2✔
114
                f.close();
2✔
115
            }
2✔
116
            else
UNCOV
117
                throw std::runtime_error(fmt::format("io:appendToFile: couldn't write to file \"{}\"", n[0].stringRef()));
×
118
#endif
119
        }
3✔
120
        else
121
            throw types::TypeCheckingError(
2✔
122
                "io:appendToFile",
1✔
123
                { { types::Contract { { types::Typedef("filename", ValueType::String), types::Typedef("content", ValueType::Any) } } } },
1✔
124
                n);
1✔
125

126
        return nil;
2✔
127
    }
1✔
128

129
    // cppcheck-suppress constParameterReference
130
    Value readFile(std::vector<Value>& n, VM* vm [[maybe_unused]])
7✔
131
    {
7✔
132
        if (!types::check(n, ValueType::String))
7✔
133
            throw types::TypeCheckingError(
3✔
134
                "io:readFile",
1✔
135
                { { types::Contract { { types::Typedef("filename", ValueType::String) } } } },
1✔
136
                n);
1✔
137

138
        std::string filename = n[0].string();
6✔
139
        if (!Utils::fileExists(filename))
6✔
140
            throw std::runtime_error(
1✔
141
                fmt::format("io:readFile: couldn't read file \"{}\" because it doesn't exist", filename));
1✔
142

143
        return Value(Utils::readFile(filename));
5✔
144
    }
8✔
145

146
    // cppcheck-suppress constParameterReference
147
    Value fileExists(std::vector<Value>& n, VM* vm [[maybe_unused]])
9✔
148
    {
9✔
149
        if (!types::check(n, ValueType::String))
9✔
150
            throw types::TypeCheckingError(
2✔
151
                "io:fileExists?",
1✔
152
                { { types::Contract { { types::Typedef("filename", ValueType::String) } } } },
1✔
153
                n);
1✔
154

155
        return Utils::fileExists(n[0].string()) ? trueSym : falseSym;
8✔
156
    }
1✔
157

158
    // cppcheck-suppress constParameterReference
159
    Value listFiles(std::vector<Value>& n, VM* vm [[maybe_unused]])
2✔
160
    {
2✔
161
        if (!types::check(n, ValueType::String))
2✔
162
            throw types::TypeCheckingError(
2✔
163
                "io:listFiles",
1✔
164
                { { types::Contract { { types::Typedef("path", ValueType::String) } } } },
1✔
165
                n);
1✔
166

167
        std::vector<Value> r;
1✔
168
        for (const auto& entry : std::filesystem::directory_iterator(n[0].string()))
33✔
169
            // cppcheck-suppress useStlAlgorithm
170
            // We can't use std::transform with a directory_iterator
171
            r.emplace_back(entry.path().string());
32✔
172

173
        return Value(std::move(r));
1✔
174
    }
2✔
175

176
    // cppcheck-suppress constParameterReference
177
    Value isDirectory(std::vector<Value>& n, VM* vm [[maybe_unused]])
5✔
178
    {
5✔
179
        if (!types::check(n, ValueType::String))
5✔
180
            throw types::TypeCheckingError(
2✔
181
                "io:dir?",
1✔
182
                { { types::Contract { { types::Typedef("path", ValueType::String) } } } },
1✔
183
                n);
1✔
184

185
        return (std::filesystem::is_directory(std::filesystem::path(n[0].string()))) ? trueSym : falseSym;
4✔
186
    }
1✔
187

188
    // cppcheck-suppress constParameterReference
189
    Value makeDir(std::vector<Value>& n, VM* vm [[maybe_unused]])
3✔
190
    {
3✔
191
        if (!types::check(n, ValueType::String))
3✔
192
            throw types::TypeCheckingError(
2✔
193
                "io:makeDir",
1✔
194
                { { types::Contract { { types::Typedef("path", ValueType::String) } } } },
1✔
195
                n);
1✔
196

197
        std::filesystem::create_directories(std::filesystem::path(n[0].string()));
2✔
198
        return nil;
2✔
199
    }
1✔
200

201
    // cppcheck-suppress constParameterReference
202
    Value removeFile(std::vector<Value>& n, VM* vm [[maybe_unused]])
5✔
203
    {
5✔
204
        if (!types::check(n, ValueType::String))
5✔
205
            throw types::TypeCheckingError(
2✔
206
                "io:removeFile",
1✔
207
                { { types::Contract { { types::Typedef("filename", ValueType::String) } } } },
1✔
208
                n);
1✔
209

210
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
211
        std::filesystem::remove_all(std::filesystem::path(n[0].string()));
4✔
212
#endif
213
        return nil;
4✔
214
    }
1✔
215
}
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