Skip to content

Commit db1f61a

Browse files
authored
added selfcheck / simplecpp: added -e to report errors only (#290)
1 parent 00d1f67 commit db1f61a

File tree

6 files changed

+55
-9
lines changed

6 files changed

+55
-9
lines changed

.github/workflows/CI-unixish.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI Unixish
1+
name: CI-unixish
22

33
on: [push, pull_request]
44

@@ -28,43 +28,48 @@ jobs:
2828
- name: make test
2929
run: make -j$(nproc) test CXX=${{ matrix.compiler }}
3030

31+
- name: selfcheck
32+
run: |
33+
make -j$(nproc) selfcheck CXX=${{ matrix.compiler }}
34+
3135
- name: Run valgrind
3236
if: matrix.os == 'ubuntu-22.04'
3337
run: |
3438
make clean
3539
# this valgrind version doesn't support DWARF 5 yet
3640
make -j$(nproc) CXX=${{ matrix.compiler }} CXXFLAGS="-gdwarf-4"
3741
valgrind --leak-check=full --num-callers=50 --show-reachable=yes --track-origins=yes --gen-suppressions=all --error-exitcode=42 ./testrunner
42+
valgrind --leak-check=full --num-callers=50 --show-reachable=yes --track-origins=yes --gen-suppressions=all --error-exitcode=42 ./simplecpp simplecpp.cpp -e
3843
3944
- name: Run with libstdc++ debug mode
4045
if: matrix.os == 'ubuntu-22.04' && matrix.compiler == 'g++'
4146
run: |
4247
make clean
43-
make -j$(nproc) test CXX=${{ matrix.compiler }} CXXFLAGS="-g3 -D_GLIBCXX_DEBUG"
48+
make -j$(nproc) test selfcheck CXX=${{ matrix.compiler }} CXXFLAGS="-g3 -D_GLIBCXX_DEBUG"
4449
4550
- name: Run with libc++ debug mode
4651
if: matrix.os == 'ubuntu-22.04' && matrix.compiler == 'clang++'
4752
run: |
4853
make clean
49-
make -j$(nproc) test CXX=${{ matrix.compiler }} CXXFLAGS="-stdlib=libc++ -g3 -D_LIBCPP_ENABLE_ASSERTIONS=1" LDFLAGS="-lc++"
54+
make -j$(nproc) test selfcheck CXX=${{ matrix.compiler }} CXXFLAGS="-stdlib=libc++ -g3 -D_LIBCPP_ENABLE_ASSERTIONS=1" LDFLAGS="-lc++"
5055
5156
- name: Run AddressSanitizer
5257
if: matrix.os == 'ubuntu-22.04'
5358
run: |
5459
make clean
55-
make -j$(nproc) test CXX=${{ matrix.compiler }} CXXFLAGS="-O2 -g3 -fsanitize=address" LDFLAGS="-fsanitize=address"
60+
make -j$(nproc) test selfcheck CXX=${{ matrix.compiler }} CXXFLAGS="-O2 -g3 -fsanitize=address" LDFLAGS="-fsanitize=address"
5661
env:
5762
ASAN_OPTIONS: detect_stack_use_after_return=1
5863

5964
- name: Run UndefinedBehaviorSanitizer
6065
if: matrix.os == 'ubuntu-22.04'
6166
run: |
6267
make clean
63-
make -j$(nproc) test CXX=${{ matrix.compiler }} CXXFLAGS="-O2 -g3 -fsanitize=undefined -fno-sanitize=signed-integer-overflow" LDFLAGS="-fsanitize=undefined -fno-sanitize=signed-integer-overflow"
68+
make -j$(nproc) test selfcheck CXX=${{ matrix.compiler }} CXXFLAGS="-O2 -g3 -fsanitize=undefined -fno-sanitize=signed-integer-overflow" LDFLAGS="-fsanitize=undefined -fno-sanitize=signed-integer-overflow"
6469
6570
# TODO: requires instrumented libc++
6671
- name: Run MemorySanitizer
6772
if: false && matrix.os == 'ubuntu-22.04' && matrix.compiler == 'clang++'
6873
run: |
6974
make clean
70-
make -j$(nproc) test CXX=${{ matrix.compiler }} CXXFLAGS="-O2 -g3 -stdlib=libc++ -fsanitize=memory" LDFLAGS="-lc++ -fsanitize=memory"
75+
make -j$(nproc) test selfcheck CXX=${{ matrix.compiler }} CXXFLAGS="-O2 -g3 -stdlib=libc++ -fsanitize=memory" LDFLAGS="-lc++ -fsanitize=memory"

.github/workflows/CI-windows.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@ jobs:
4646
- name: Test
4747
run: |
4848
.\${{ matrix.config }}\testrunner.exe || exit /b !errorlevel!
49+
50+
- name: Selfcheck
51+
run: |
52+
.\${{ matrix.config }}\simplecpp.exe simplecpp.cpp -e || exit /b !errorlevel!
4953

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ test: testrunner simplecpp
1616
./testrunner
1717
python3 run-tests.py
1818

19+
selfcheck: simplecpp
20+
./selfcheck.sh
21+
1922
simplecpp: main.o simplecpp.o
2023
$(CXX) $(LDFLAGS) main.o simplecpp.o -o simplecpp
2124

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ build_script:
1717

1818
test_script:
1919
- debug\testrunner.exe
20+
- debug\simplecpp.exe simplecpp.cpp -e

main.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,34 @@ int main(int argc, char **argv)
3131
// Settings..
3232
simplecpp::DUI dui;
3333
bool quiet = false;
34+
bool error_only = false;
3435
for (int i = 1; i < argc; i++) {
3536
const char * const arg = argv[i];
3637
if (*arg == '-') {
3738
bool found = false;
3839
const char c = arg[1];
39-
const char * const value = arg[2] ? (argv[i] + 2) : argv[++i];
4040
switch (c) {
4141
case 'D': // define symbol
42+
{
43+
const char * const value = arg[2] ? (argv[i] + 2) : argv[++i];
4244
dui.defines.push_back(value);
4345
found = true;
4446
break;
47+
}
4548
case 'U': // undefine symbol
49+
{
50+
const char * const value = arg[2] ? (argv[i] + 2) : argv[++i];
4651
dui.undefined.insert(value);
4752
found = true;
4853
break;
54+
}
4955
case 'I': // include path
56+
{
57+
const char * const value = arg[2] ? (argv[i] + 2) : argv[++i];
5058
dui.includePaths.push_back(value);
5159
found = true;
5260
break;
61+
}
5362
case 'i':
5463
if (std::strncmp(arg, "-include=",9)==0) {
5564
dui.includes.push_back(arg+9);
@@ -70,11 +79,18 @@ int main(int argc, char **argv)
7079
quiet = true;
7180
found = true;
7281
break;
82+
case 'e':
83+
error_only = true;
84+
found = true;
85+
break;
7386
}
7487
if (!found) {
75-
std::cout << "Option '" << arg << "' is unknown." << std::endl;
88+
std::cout << "error: option '" << arg << "' is unknown." << std::endl;
7689
error = true;
7790
}
91+
} else if (filename) {
92+
std::cout << "error: multiple filenames specified" << std::endl;
93+
std::exit(1);
7894
} else {
7995
filename = arg;
8096
}
@@ -83,6 +99,11 @@ int main(int argc, char **argv)
8399
if (error)
84100
std::exit(1);
85101

102+
if (quiet && error_only) {
103+
std::cout << "error: -e cannot be used in conjunction with -q" << std::endl;
104+
std::exit(1);
105+
}
106+
86107
if (!filename) {
87108
std::cout << "Syntax:" << std::endl;
88109
std::cout << "simplecpp [options] filename" << std::endl;
@@ -93,6 +114,7 @@ int main(int argc, char **argv)
93114
std::cout << " -std=STD Specify standard." << std::endl;
94115
std::cout << " -q Quiet mode (no output)." << std::endl;
95116
std::cout << " -is Use std::istream interface." << std::endl;
117+
std::cout << " -e Output errors only." << std::endl;
96118
std::exit(0);
97119
}
98120

@@ -102,6 +124,10 @@ int main(int argc, char **argv)
102124
simplecpp::TokenList *rawtokens;
103125
if (use_istream) {
104126
std::ifstream f(filename);
127+
if (!f.is_open()) {
128+
std::cout << "error: could not open file '" << filename << "'" << std::endl;
129+
std::exit(1);
130+
}
105131
rawtokens = new simplecpp::TokenList(f, files,filename,&outputList);
106132
}
107133
else {
@@ -118,7 +144,8 @@ int main(int argc, char **argv)
118144

119145
// Output
120146
if (!quiet) {
121-
std::cout << outputTokens.stringify() << std::endl;
147+
if (!error_only)
148+
std::cout << outputTokens.stringify() << std::endl;
122149

123150
for (const simplecpp::Output &output : outputList) {
124151
std::cerr << output.location.file() << ':' << output.location.line << ": ";

selfcheck.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
output=$(./simplecpp simplecpp.cpp -e 2>&1)
4+
ec=$?
5+
echo "$output" | grep -v 'Header not found: <'
6+
exit $ec

0 commit comments

Comments
 (0)