Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 6f066ec

Browse files
Merge pull request #150 from youpong/fix-getuser
Get user name by getpwuid instead of environment variable USER
2 parents 6078c61 + ff77c96 commit 6f066ec

File tree

7 files changed

+51
-18
lines changed

7 files changed

+51
-18
lines changed

.github/workflows/coverage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Coverage Testing
1+
name: Coverage Testing on public beta of Ubuntu 24.04
22

33
on:
44
push:
@@ -12,9 +12,9 @@ on:
1212

1313
jobs:
1414
coverage-test:
15-
runs-on: ubuntu-latest
15+
runs-on: ubuntu-24.04
1616
steps:
17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
1818
- name: configure
1919
run: ./configure --enable-code-coverage
2020
- name: build

.github/workflows/unit-test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ on:
1212

1313
jobs:
1414
unit-test:
15+
continue-on-error: true
1516
strategy:
1617
matrix:
17-
os: [macos-latest, ubuntu-latest]
18+
os: [ macos-latest, ubuntu-latest, ubuntu-24.04 ]
1819
runs-on: ${{ matrix.os }}
1920
steps:
20-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
2122
- name: Install GNU Getopt on macOS
2223
if: ${{ matrix.os == 'macos-latest' }}
23-
run: |
24-
brew install gnu-getopt
24+
run: brew install gnu-getopt
2525
- name: configure
2626
run: ./configure
2727
- name: build

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,31 @@
3333

3434
## Prerequisites
3535

36+
The following versions or newer are required.
37+
3638
for building
3739

38-
* GNU getopt - 2.37.2 or later
39-
* GNU Make - 4.3 or later
40-
* GCC - 11.3.0 or later
40+
* GNU getopt - 2.37.2
41+
* GNU Make - 4.3
42+
* GCC - 13.2.0 or Clang - 15.0.0
4143

4244
for macOS, You can install gnu-getopt by runnning the following command.
43-
```
45+
```bash
4446
$ brew install gnu-getopt
4547
```
4648

4749
for generating API documents
4850

49-
* Doxygen - 1.9.1 or later
50-
* Graphviz -2.43.0 or later
51+
* Doxygen - 1.9.1
52+
* Graphviz -2.43.0
5153

5254
for contributing
5355

54-
* ClangFormat - 14.0.0 or later
56+
* ClangFormat - 14.0.0
5557

5658
for generating gif
5759

58-
* vhs - 0.2.0 or later
60+
* vhs - 0.2.0
5961

6062
## Documentation
6163

src/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SRCS = fetch.cpp main.cpp util.cpp
33
OBJS = $(SRCS:.cpp=.o)
44

55
CXX = @CXX@
6-
CXXFLAGS = -std=c++2a -Wall -Wextra --pedantic-errors @CXXFLAGS@
6+
CXXFLAGS = -std=c++17 -Wall -Wextra --pedantic-errors @CXXFLAGS@
77
LIBS = @LIBS@
88
LDFLAGS = -pthread
99

src/fetch.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,23 @@ std::vector<std::runtime_error> Command::exceptions;
88
std::mutex Command::mtx;
99
string Context::PACKAGE_DELIM = "; "s;
1010

11+
#include <pwd.h>
12+
#include <string.h>
13+
#include <unistd.h>
1114
/**
1215
* @returns gets the username
16+
* @throws runtime_error failed to get username
1317
*/
1418
string getuser()
1519
{
16-
return getenv("USER");
20+
auto *p = getpwuid(getuid());
21+
if (p == NULL)
22+
{
23+
throw runtime_error(
24+
"Could not get struct passwd: "s + strerror(errno));
25+
}
26+
27+
return p->pw_name;
1728
}
1829

1930
/**
@@ -634,3 +645,13 @@ void print(string color_name, string distro_name)
634645

635646
return;
636647
}
648+
649+
void test_getuser()
650+
{
651+
expect(string(getenv("USER")), getuser(), "getuser"s);
652+
}
653+
654+
void test_fetch()
655+
{
656+
test_getuser();
657+
}

src/fetch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "config.h"
88
#include <algorithm>
99
#include <cctype>
10+
#include <cerrno>
1011
#include <filesystem>
1112
#include <fstream>
1213
#include <functional>
@@ -66,6 +67,8 @@ void printBattery(string path);
6667

6768
void print(string color, string distro_name);
6869

70+
void test_fetch();
71+
6972
// util.cpp
7073

7174
string getColor(string);

src/main.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "fetch.h"
55

66
void DisplayInfo(bool show_battery);
7+
void test_suite();
78

89
/**
910
* @returns
@@ -26,7 +27,7 @@ int main(int argc, char *argv[])
2627
// no-op
2728
break;
2829
case Mode::EXEC_TEST:
29-
test_util();
30+
test_suite();
3031
cout << Crayon{}.green().text("All unit tests passed."s) << endl;
3132
return 0;
3233
case Mode::SHOW_VERSION:
@@ -100,3 +101,9 @@ void DisplayInfo(bool show_battery)
100101

101102
cout << endl;
102103
}
104+
105+
void test_suite()
106+
{
107+
test_fetch();
108+
test_util();
109+
}

0 commit comments

Comments
 (0)