Repository navigation
Expand file tree
/
Copy pathutil.h
More file actions
73 lines (54 loc) · 2.21 KB
/
Copy pathutil.h
File metadata and controls
73 lines (54 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
Test utilities
Copyright (C) 2013 AMPL Optimization Inc
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that the copyright notice and this permission notice and warranty
disclaimer appear in supporting documentation.
The author and AMPL Optimization Inc disclaim all warranties with
regard to this software, including all implied warranties of
merchantability and fitness. In no event shall the author be liable
for any special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether in an
action of contract, negligence or other tortious action, arising out
of or in connection with the use or performance of this software.
Author: Victor Zverovich
*/
#ifndef TEST_UTIL_H_
#define TEST_UTIL_H_
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include "mp/format.h"
#include "mp/nl-reader.h"
#include "mp/os.h"
std::string ReadFile(fmt::CStringRef name);
void WriteFile(fmt::CStringRef name, fmt::StringRef data);
// Replaces all occurrences of '/' in the path with sep. If sep is 0
// it is set to the system-specific directory separator.
std::string FixPath(
fmt::CStringRef path, char sep = mp::path::preferred_separator);
// Changes the current working directory. Throws Error on error.
void ChangeDirectory(fmt::CStringRef path);
// Executes a shell command. Throws Error on error.
int ExecuteShellCommand(
fmt::CStringRef command, bool throw_on_nonzero_exit_code = true);
inline std::string GetExecutableDir() {
return mp::GetExecutablePath().remove_filename().string();
}
// Splits the string into an array of substrings.
std::vector<std::string> Split(const std::string &s, char sep);
// Replace line at line_index in s with new_line.
std::string ReplaceLine(std::string s, int line_index, fmt::StringRef new_line);
mp::NLHeader MakeTestHeader();
class TempFile {
private:
std::string name_;
public:
explicit TempFile(fmt::CStringRef name) : name_(name.c_str()) {}
~TempFile();
const std::string &name() const { return name_; }
};
#endif // TEST_UTIL_H_