superxcgm / xcShell

Your own shell
1 stars 1 forks source link

Stderr redirection #63

Closed superxcgm closed 3 years ago

superxcgm commented 3 years ago

Epic

Process

Description

Shell should able to redirect stderr to other file or same as stdout.

AC

  1. Redirect stderr to other file (override) Given: User type some-command 2> a.out (For example: echo '1 / 0' | bc 2> a.out) When: User hit <Enter> Then: shell should clear content of file a.out redirect stderr to a.out

  2. Redirect stderr to other file (append) Given: User type some-command 2>> a.out (For example: echo '1 / 0' | bc 2>> a.out) When: User hit <Enter> Then: shell should not clear content of file a.out, redirect stderr to end of a.out

  3. Redirect stderr to same as stdout (override) Given: User type some-command > a.out 2>&1 (For example: echo '1 / 0' | bc > a.out 2>&1) When: User hit <Enter> Then: shell should clear content of file a.out, redirect stderr and stdout to a.out

  4. Redirect stderr to same as stdout (append) Given: User type some-command >> a.out 2>&1 (For example: echo '1 / 0' | bc >> a.out 2>&1) When: User hit <Enter> Then: shell should not clear content of file a.out, redirect stderr and stdout to end of a.out

  5. Redirect stderr to different file as stdout Given: User type some-command > a.out 2> b.out When: User hit <Enter> Then: shell should clear content of file a.out redirect stdout to a.out, and clear content of file b.out redirect stderr to b.out.

Demo test c code for case 5.

#include <stdio.h>

int main() {
    printf("hello world\n");
    fprintf(stderr, "fuck the world\n");
    return 0;
}
lq1149622825 commented 3 years ago

tasking:

superxcgm commented 3 years ago

QA

  1. Redirect stderr to other file (override) Given: User type some-command 2> a.out (For example: echo '1 / 0' | bc 2> a.out) When: User hit <Enter> Then: ✅ shell should clear content of file a.out redirect stderr to a.out

  2. Redirect stderr to other file (append) Given: User type some-command 2>> a.out (For example: echo '1 / 0' | bc 2>> a.out) When: User hit <Enter> Then: ✅ shell should not clear content of file a.out, redirect stderr to end of a.out

  3. Redirect stderr to same as stdout (override) Given: User type some-command > a.out 2>&1 (For example: echo '1 / 0' | bc > a.out 2>&1) When: User hit <Enter> Then: ✅ shell should clear content of file a.out, redirect stderr and stdout to a.out

  4. Redirect stderr to same as stdout (append) Given: User type some-command >> a.out 2>&1 (For example: echo '1 / 0' | bc >> a.out 2>&1) When: User hit <Enter> Then: ✅ shell should not clear content of file a.out, redirect stderr and stdout to end of a.out

  5. Redirect stderr to different file as stdout Given: User type some-command > a.out 2> b.out When: User hit <Enter> Then: ✅shell should clear content of file a.out redirect stdout to a.out, and clear content of file b.out redirect stderr to b.out.

Test case already add to functional test. Screenshot from 2021-10-09 21-00-12